Commit 9e675d61 authored by liyuanhong's avatar liyuanhong

增加了帧实时预览功能

parent 49a92319
...@@ -7,6 +7,7 @@ import time ...@@ -7,6 +7,7 @@ import time
import traceback import traceback
import platform import platform
import cv2 import cv2
import subprocess
import requests import requests
import wx import wx
...@@ -118,9 +119,11 @@ class CameraArea(): ...@@ -118,9 +119,11 @@ class CameraArea():
self.frame.Bind(wx.EVT_BUTTON, lambda evt: self.disConnect(evt), self.frame.Bind(wx.EVT_BUTTON, lambda evt: self.disConnect(evt),
disConnectButton) disConnectButton)
playStreamVideoButton = wx.Button(ctrView, label="播放流地址", pos=(5, 95)) playStreamVideoButton = wx.Button(ctrView, label="播放流地址", pos=(5, 95))
self.frame.Bind(wx.EVT_BUTTON, lambda evt: self.playFrame(evt),
playStreamVideoButton)
showFrameButton = wx.Button(ctrView, label="实时显示帧画面", pos=(120, 95)) showFrameButton = wx.Button(ctrView, label="实时显示帧画面", pos=(120, 95))
self.frame.Bind(wx.EVT_BUTTON, lambda evt: self.showFrame(evt), showFrameButton) self.frame.Bind(wx.EVT_BUTTON, lambda evt: self.showFrame(evt), showFrameButton)
StopPlayStreamVideoButton = wx.Button(ctrView, label="停止播放", pos=(5, 125)) # StopPlayStreamVideoButton = wx.Button(ctrView, label="停止播放", pos=(5, 125))
stopShowFrameButton = wx.Button(ctrView, label="停止显示帧画面", pos=(120, 125)) stopShowFrameButton = wx.Button(ctrView, label="停止显示帧画面", pos=(120, 125))
self.frame.Bind(wx.EVT_BUTTON, lambda evt: self.stopShowFrame(evt), stopShowFrameButton) self.frame.Bind(wx.EVT_BUTTON, lambda evt: self.stopShowFrame(evt), stopShowFrameButton)
...@@ -157,11 +160,9 @@ class CameraArea(): ...@@ -157,11 +160,9 @@ class CameraArea():
boxSizer_ctrArea.Add(ctrPanel,100, flag=wx.EXPAND | wx.ALL) boxSizer_ctrArea.Add(ctrPanel,100, flag=wx.EXPAND | wx.ALL)
ctrArea.SetSizer(boxSizer_ctrArea) ctrArea.SetSizer(boxSizer_ctrArea)
boxSizer_bottom.Add(logArea,60,flag=wx.EXPAND | wx.ALL) boxSizer_bottom.Add(logArea,60,flag=wx.EXPAND | wx.ALL)
boxSizer_bottom.Add(ctrArea, 40, flag=wx.EXPAND | wx.LEFT,border=10) boxSizer_bottom.Add(ctrArea, 40, flag=wx.EXPAND | wx.LEFT,border=10)
bottomPanel.SetSizer(boxSizer_bottom) bottomPanel.SetSizer(boxSizer_bottom)
return bottomPanel return bottomPanel
################################################# #################################################
...@@ -223,7 +224,6 @@ class CameraArea(): ...@@ -223,7 +224,6 @@ class CameraArea():
else: else:
timeCur = self.getCurTime() timeCur = self.getCurTime()
self.logTextCtr.WriteText(timeCur + "已连网!\n") self.logTextCtr.WriteText(timeCur + "已连网!\n")
def doConnect(self): def doConnect(self):
host = self.pushHostText.GetValue() host = self.pushHostText.GetValue()
port = self.pushPortText.GetValue() port = self.pushPortText.GetValue()
...@@ -364,7 +364,7 @@ class CameraArea(): ...@@ -364,7 +364,7 @@ class CameraArea():
def showFrame(self,evt): def showFrame(self,evt):
sys.stdout = self.logTextCtr sys.stdout = self.logTextCtr
sys.stderr = self.logTextCtr sys.stderr = self.logTextCtr
threadObj = threading.Thread(target=self.doShowFrame()) threadObj = threading.Thread(target=self.doShowFrame)
threadObj.start() threadObj.start()
def doShowFrame(self): def doShowFrame(self):
self.isShowFrame = 1 self.isShowFrame = 1
...@@ -373,8 +373,8 @@ class CameraArea(): ...@@ -373,8 +373,8 @@ class CameraArea():
res = requests.post(self.getGetPlayUrl, data=json.dumps({'devId': devId, 'chan': str(channel)})).text res = requests.post(self.getGetPlayUrl, data=json.dumps({'devId': devId, 'chan': str(channel)})).text
res = json.loads(res) res = json.loads(res)
pullUrl = res["data"]["url"] pullUrl = res["data"]["url"]
cap = cv2.VideoCapture(pullUrl)
try: try:
cap = cv2.VideoCapture(pullUrl)
timeCur = self.getCurTime() timeCur = self.getCurTime()
self.logTextCtr.WriteText(timeCur + "帧预览开始!\n") self.logTextCtr.WriteText(timeCur + "帧预览开始!\n")
while (cap.isOpened()): while (cap.isOpened()):
...@@ -399,7 +399,7 @@ class CameraArea(): ...@@ -399,7 +399,7 @@ class CameraArea():
def stopShowFrame(self,evt): def stopShowFrame(self,evt):
sys.stdout = self.logTextCtr sys.stdout = self.logTextCtr
sys.stderr = self.logTextCtr sys.stderr = self.logTextCtr
threadObj = threading.Thread(target=self.stopDoShowFrame()) threadObj = threading.Thread(target=self.stopDoShowFrame)
threadObj.start() threadObj.start()
def stopDoShowFrame(self): def stopDoShowFrame(self):
self.isShowFrame = 0 self.isShowFrame = 0
...@@ -407,6 +407,19 @@ class CameraArea(): ...@@ -407,6 +407,19 @@ class CameraArea():
#################################################### ####################################################
# 播放视频地址 # 播放视频地址
################################################### ###################################################
def playFrame(self): def playFrame(self,evt):
pass sys.stdout = self.logTextCtr
sys.stderr = self.logTextCtr
threadObj = threading.Thread(target=self.doPlayFrame)
threadObj.start()
timeCur = self.getCurTime()
self.logTextCtr.WriteText(timeCur + "开始播放视频!\n")
def doPlayFrame(self):
devId = self.devIdText.GetValue()
channel = self.channelText.GetValue()
res = requests.post(self.getGetPlayUrl, data=json.dumps({'devId': devId, 'chan': str(channel)})).text
res = json.loads(res)
url = res["data"]["url"]
m_command = ["ffplay.exe", url]
subprocess.run(m_command)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment