123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- import os
- import sys
- import time
- from ssat_sdk.utils import LoggingUtil
- from ssat_sdk import sat_environment
- from ssat_sdk.utils import string_util
- from ssat_sdk.service.service_manager import ServiceManager
- from ssat_sdk.device_manage.ub530_manager import UB530Manager
- import CD750SSDK
- import UB530SDK
- UB530 = 'TC-UB530'
- UB530EX = 'TC-UB530EX'
- CD750 = 'CD750'
- class CCardManager():
- status = False
- exe_path = sys.prefix + r"/Tools/CD750/AVerCapSDKDemo.exe"
- sManager = ServiceManager()
- DEVICE_NAME = sat_environment.getCCard_Selected()
- print u"视频采集卡名称:", DEVICE_NAME
- def __init__(self):
- if string_util.strcmp(UB530, self.DEVICE_NAME):
- self.ccard = UB530Manager()
- elif string_util.strcmp(UB530EX, self.DEVICE_NAME):
- CCardManager.exe_path = sys.prefix + r"/Tools/SATHelper/SATHelper.exe"
- else:
- CCardManager.exe_path = sys.prefix + r"/Tools/CD750/AVerCapSDKDemo.exe"
- def start(self):
- print "CCardManager ssdk"
- if string_util.strcmp(self.DEVICE_NAME, CD750):
- self.status = CD750SSDK.StartApp(CCardManager.exe_path)
- time.sleep(3)
- if self.status == True:
- LoggingUtil.printLog("打开CD750 AVerCapSDKDemo成功")
-
- CD750SSDK.ConnectDevice(0)
- CCardManager.status = True
-
- time.sleep(1)
- CD750SSDK.StreamOption(True)
- else:
- LoggingUtil.printLog("打开CD750 AVerCapSDKDemo失败")
- return self.status
- elif string_util.strcmp(self.DEVICE_NAME, UB530):
- self.sManager.startServiceThread("ub530")
- time.sleep(2)
- return self.sManager.getServiceStatus("ub530")
- elif string_util.strcmp(self.DEVICE_NAME, UB530EX):
- self.status = UB530SDK.StartApp(CCardManager.exe_path)
- time.sleep(3)
- if self.status == True:
- LoggingUtil.printLog("打开UB530 VideoCapture成功")
-
- UB530SDK.ConnectDevice()
- CCardManager.status = True
- else:
- LoggingUtil.printLog("打开UB530 VideoCapture失败")
- return self.status
- def isExeRunning(self):
- if string_util.strcmp(self.DEVICE_NAME, CD750):
- return CD750SSDK.IsAppRunning(CCardManager.exe_path)
- elif string_util.strcmp(self.DEVICE_NAME, UB530EX):
- return UB530SDK.IsAppRunning(CCardManager.exe_path)
- elif string_util.strcmp(self.DEVICE_NAME, UB530):
- return self.sManager.getServiceStatus("ub530")
-
- def startApp(self):
- self.status = CD750SSDK.StartApp(CCardManager.exe_path)
- return self.status
-
- def stopApp(self):
- self.status = not CD750SSDK.StopApp(CCardManager.exe_path)
- return self.status
-
- def connect(self, index=0):
- return CD750SSDK.ConnectDevice(index)
-
- def disconnect(self, index=0):
- return CD750SSDK.DisconnectDevice(index)
-
- def showApp(self):
- CD750SSDK.ShowApp()
-
- def hideApp(self):
- CD750SSDK.HideApp()
-
- def streamOption(self, enable=True):
- return CD750SSDK.StreamOption(enable)
-
- def captureSingleImage(self, picpath):
- return CD750SSDK.CaptureSingleImage(picpath, 3, True, 0, 0, 0, 0)
-
- def captureImageByCount(self, count, picpath, prefix="CD750"):
- return CD750SSDK.CaptureImageByCount(count, picpath, prefix, 3, True, 0, 0, 0, 0)
-
- def captureImageByTime(self, times, perCount, picpath, prefix="CD750"):
- if string_util.strcmp(CD750, self.DEVICE_NAME):
- return CD750SSDK.CaptureImageByTime(times, perCount, picpath, prefix, 3, True, 0, 0, 0, 0)
- elif string_util.strcmp(UB530EX, self.DEVICE_NAME):
- return UB530SDK.CaptureImageByTime(times, 0, picpath, prefix, 2)
- elif string_util.strcmp(UB530, self.DEVICE_NAME):
- count = 0
- runTime = time.time()
- endWork = False
- lastIndex = 1
- times = times/1000
- while True:
- lastCount = lastIndex + perCount
- for i in range(lastIndex, lastCount):
- path = "%s%s_%d.jpg" % (picpath, prefix, i)
- if self.ccard.takePicture(path) == 0:
- count += 1
- time.sleep(0.2)
- if (time.time() - runTime >= times):
- endWork = True
- break
- lastIndex += perCount
- if endWork:
- break
-
- return True if count == perCount*times else False
-
- def takePicture(self, picpath):
- status = -1
- if string_util.strcmp(CD750, self.DEVICE_NAME):
- status = CD750SSDK.CaptureSingleImage(picpath, 3, True, 0, 0, 0, 0)
- time.sleep(0.5)
- elif string_util.strcmp(UB530EX, self.DEVICE_NAME):
- status = UB530SDK.CaptureSingleImage(picpath, 2)
- count = 0
- while os.path.exists(picpath) is False:
- time.sleep(0.1)
- if count == 5:
- break
- count = count + 1
-
- status = True if count < 5 else False
- elif string_util.strcmp(UB530, self.DEVICE_NAME):
- status = self.ccard.takePicture(picpath)
- if status == 0:
- status = 1
- else:
- status = 0
- time.sleep(1)
- return status
-
- def getCaptureImageList(self, picpath):
- list = []
- if string_util.strcmp(CD750, self.DEVICE_NAME):
- list = CD750SSDK.GetCaptureImageList(picpath)
- elif string_util.strcmp(UB530EX, self.DEVICE_NAME):
- list = UB530SDK.GetCaptureImageList(picpath)
- elif string_util.strcmp(UB530, self.DEVICE_NAME):
- list = []
-
- newpath = ''
- for i in range(0, picpath.__len__(), 2):
- char1 = picpath[i]
- if i < picpath.__len__()-1:
- char2 = picpath[i+1]
- newpath += char1
- if char1 == char2 and char1 == '/':
- continue
- newpath += char2
- else:
- newpath += char1
- picpath = newpath.replace('/', '\\')
- index = picpath.rfind('\\')
-
- dir = picpath[:index]
-
- name = picpath[index+1:]
-
- preFix = name[:name.rfind("_")]
- for dirpath, dirname, filenames in os.walk(dir):
- for filepath in filenames:
- list.append(os.path.join(dirpath, filepath))
-
- list.sort()
- return list
-
- def stopCaptureImage(self):
- CD750SSDK.StopCaptureImage()
-
- def startCaptureAudio(self, audiopath):
- CD750SSDK.StartCaptureAudio(audiopath)
-
- def stopCaptureAudio(self):
- CD750SSDK.StopCaptureAudio()
-
- def asyStartCaptureAudio(self, keeptime, audiopath):
- CD750SSDK.AsyCaptureAudio(keeptime, audiopath)
- if __name__ == "__main__":
- cardManager = CCardManager()
- print cardManager.start()
-
-
- time_start = time.time()
- cardManager.takePicture("D:\\SAT\\test1.png")
- time_end = time.time()
- print('totally cost', time_end-time_start)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|