【问题标题】:opencv resize window for a live camopencv 调整实时摄像头的窗口大小
【发布时间】:2020-01-15 23:01:17
【问题描述】:

我已经关注this tutorial 并设法进行了面部检测,年龄+性别就像this video 一样

现在我面临的问题是应用程序的窗口大小非常小,我不知道也找不到调整大小的方法(in this image 右下角你可以看到窗口)。

申请代码可以是found here

【问题讨论】:

    标签: opencv resize window raspbian face-detection


    【解决方案1】:

    解决方案无论您为实时摄像头设置大小、、、opencv 调整窗口大小

    import cv2
    
    def main():
        windowName = "Main"
        cv2.namedWindow(windowName)
        cap = cv2.VideoCapture(0)
    
        print('Width :' + str(cap.get(3)))
        print('Height :' + str(cap.get(4)))
    
        cap.set(3, 620)
        cap.set(4, 720)
    
    
    
    
        if cap.isOpened():
            ret, frame = cap.read()
        else:
            ret = False
    
        while ret:
            ret, frame = cap.read()
    
            output = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
            cv2.imshow(windowName, frame)
            if cv2.waitKey(1) == 27:
                break
    
        cv2.destroyAllWindow()
    
        cap.release()    
    
    if __name__== "__main__":
        main() 
    

    【讨论】:

      【解决方案2】:
      import cv2
      
      def main():
      
          windowName = "Main"
      
          cv2.namedWindow(windowName)
      
          cap = cv2.VideoCapture(0)
      
          print('Width :' + str(cap.get(3)))
          print('Height :' + str(cap.get(4)))
      
          cap.set(3, 620)
          cap.set(4, 720)
      
      
      
      
          if cap.isOpened():
              ret, frame = cap.read()
          else:
              ret = False
      
          while ret:
              ret, frame = cap.read()
      
              output = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
              cv2.imshow(windowName, frame)
              if cv2.waitKey(1) == 27:
                  break
      
          cv2.destroyAllWindow()
      
          cap.release()   
      if __name__== "__main__":
      
          main() 
      

      【讨论】:

      • 虽然这段代码可以解决问题,但including an explanation 确实有助于提高帖子的质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因
      猜你喜欢
      • 2020-09-12
      • 1970-01-01
      • 2020-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      • 2017-04-29
      • 2021-10-02
      相关资源
      最近更新 更多