当前位置: 首页>>代码示例>>Python>>正文


Python CaptureManager.convertFrame方法代码示例

本文整理汇总了Python中managers.CaptureManager.convertFrame方法的典型用法代码示例。如果您正苦于以下问题:Python CaptureManager.convertFrame方法的具体用法?Python CaptureManager.convertFrame怎么用?Python CaptureManager.convertFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在managers.CaptureManager的用法示例。


在下文中一共展示了CaptureManager.convertFrame方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Gui

# 需要导入模块: from managers import CaptureManager [as 别名]
# 或者: from managers.CaptureManager import convertFrame [as 别名]

#.........这里部分代码省略.........
        logger.debug("closing")
        if self.ebb:
            self.ebb.closeSerial()
        if self._cap.isWritingVideo:
            self._cap.stopWritingVideo()
        
        for h in logger.handlers:
            if type(h) == logging.FileHandler:
                h.close()
        
        try:
            cv2.destroyWindow('gaussian')
        except Exception as e:
            pass
            
    def isColor( self, imgIn ):
        s = np.shape(imgIn)
        if s == 3:
            try:
                ncolor = np.shape(imgIn)[2]
                boolt = int(ncolor) > 2
                return boolt
            except IndexError:
                if self.existingVid:
                    logger.warning('Video has ended')
                    self.existingVid = False
                    self.resetAll()
                else:
                    logger.warning('Issue with video input')
                    self.resetAll()
        else:
            return False
   
    def play( self ):
        
        if self.showImage:
            ## Get image from camera
            self._cap.enterFrame()
            self.currentFrame = self._cap.getFrame()
        
            self.color = self.isColor(self.currentFrame)

            t1 = time.time()

            if self.color:
                try:
                    self.currentFrame = cv2.cvtColor(self.currentFrame, cv2.COLOR_BGR2GRAY)
                except TypeError:
                    logger.exception("No Frame")
                finally:
                    self._cap.exitFrame()
            else:
                self._cap.exitFrame()
            
            if not self.runTracking: #no finder
                if self.showImage: #yes capture
                    self.ui.videoFrame.setPixmap(self._cap.convertFrame(self.currentFrame))
                    self.ui.videoFrame.setScaledContents(True)
            else: # yes finder
                ## Stop if too dark!!!
                if time.time() - self.startTrackTime < 5:
                    self.firstAvgPixIntensity = np.mean(self.currentFrame)
                    logger.warning('first avg int: %d' % self.firstAvgPixIntensity)
               ## Tracking procedure
                if time.time() - self._lastCheck >= self._sampleFreq:
                    gaussian = self._wormFinder.processFrame( self.currentFrame )
                    if gaussian is not None:
                        cv2.imshow( 'gaussian', gaussian )
                        
                    if self.motorsOn: #yes motorized
                        ## Stop motors if too dark
                        self.currentAvgPixIntensity = np.mean(self.currentFrame)
                        logger.warning('current avg int: %d' % self.currentAvgPixIntensity)
                        if self.currentAvgPixIntensity < self.firstAvgPixIntensity - 50:
                            logger.warning('Darkening of picture: motors turned off')
                            if self.motorsOn:
                                self.motorized()
                            if self._cap.isWritingVideo:
                                self.record()
                        else:
                          self._wormFinder.decideMove()
                    self._lastCheck = time.time()
                    self._wormFinder.drawDebugCropped( self.currentFrame)
                    
                    self.ui.videoFrame.setPixmap(self._cap.convertFrame(self.currentFrame))
                    self.ui.videoFrame.setScaledContents(True)

            if self._cap._fpsEstimate:
               self.ui.fps.setText( 'FPS: %0.2f' % ( self._cap._fpsEstimate ))

            if self.startRecTime:
                elapsedSec = time.time() - self.startRecTime
                elapsed = time.strftime("%H.%M.%S", time.gmtime(elapsedSec) ) 
                self.ui.lcdNumber.setNumDigits(8)
                self.ui.lcdNumber.display( elapsed )
            else:
                self.ui.lcdNumber.display("") 
        return
        
    '''
开发者ID:vsimonis,项目名称:gui-tracker,代码行数:104,代码来源:main.py

示例2: Gui

# 需要导入模块: from managers import CaptureManager [as 别名]
# 或者: from managers.CaptureManager import convertFrame [as 别名]

#.........这里部分代码省略.........
    def set( self ):
        if self.ui.widthLine.text():
            try:
                float( self.ui.widthLine.text() )
            except ValueError as e:
                QtWidgets.QMessageBox.information( self, "Invalid Width", "Cannot convert that width to a float! Make sure you enter a number (decimals accepted)")
                return
       
        if self.ui.widthLine.text() and self.ui.comboBox.currentText():
            self.resolutionSelect()
            # Instantiate motors    
            try:
                self.ebb = EasyEBB( resolution = self.actualRes, sizeMM = float(self.ui.widthLine.text() ) )
                  

                self.setAble('settings', False)
                self.setAble('motors', True)
                self.setAble('center', True)
            except serial.SerialException as e:
                logger.exception(e)
                QtWidgets.QMessageBox.information( self, "Motors Issue",
                                                "Please connect motors or restart them, having issues connecting now")
        else:
            QtWidgets.QMessageBox.information( self, "Validation",
                                                  "Please enter a measurement for the width and double-check your resolution choice") 

        

    def closeEvent ( self, event):
        logger.debug("closing")
        if self._cap._capture.isOpened():
            self._cap._capture.release()
        #if self._cap:
        #    cv2.destroyWindow("Camera Display")
        #    cv2.destroyAllWindows()
        if self.ebb:
            self.ebb.closeSerial()
    
    def isColor( self, imgIn ):
        s = np.shape(imgIn)
        if  np.size(s) == 3:
            try:
                ncolor = np.shape(imgIn)[2]
                boolt = int(ncolor) > 2
                return boolt
            except IndexError:
                QtWidgets.QMessageBox.information( self, "Camera Issue", "Please Check Camera Source")
                logger.error("Something wrong with camera input")
                self.showImage = False
        else:
            return False
         
        
    def play( self ):
        if self.showImage:
            self._cap.enterFrame()
            self.currentFrame = self._cap.frame
        
            self.color = self.isColor(self.currentFrame)
            t1 = time.time()
            if self.color:
                try:
                    self.currentFrame = cv2.cvtColor(self.currentFrame, cv2.COLOR_BGR2GRAY)
                    if self.currentFrame is not None:
                        self.currentFrame = self.p.draw(self.currentFrame, 'black-1')
                        self.currentFrame = self.c.draw(self.currentFrame, 'black-1')
                   
                        self.ui.videoFrame.setPixmap(self._cap.convertFrame(self.currentFrame))
                        self.ui.videoFrame.setScaledContents(True)
                    else:
                        QtWidgets.QMessageBox.information( self, "Camera Issue", "Please Check Camera Source")
                        logger.error("Something wrong with camera input")
                
                    #cv2.imshow( "Camera Display",self.currentFrame)
                except TypeError:
                    logger.exception("No Frame")
                    QtWidgets.QMessageBox.information( self, "Camera Issue", "Please Check Camera Source")

                finally:
                    self._cap.exitFrame()
            else:
                try:
                    if self.currentFrame is not None:
                        self.currentFrame = self.p.draw(self.currentFrame, 'black-1')
                        self.currentFrame = self.c.draw(self.currentFrame, 'black-1')
                        self.ui.videoFrame.setPixmap(self._cap.convertFrame(self.currentFrame))
                        self.ui.videoFrame.setScaledContents(True)
                    else:
                        QtWidgets.QMessageBox.information( self, "Camera Issue", "Please Check Camera Source")
                        logger.error("Something wrong with camera input")
                        logger.exception("No Frame")
                        self.showImage = False

                        #cv2.imshow( "Camera Display",self.currentFrame)
                except TypeError:
                    logger.exception("No Frame")
                finally:
                    self._cap.exitFrame()

            self._cap.exitFrame()
开发者ID:vsimonis,项目名称:gui-calibration,代码行数:104,代码来源:main.py


注:本文中的managers.CaptureManager.convertFrame方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。