Navigation

    VEYE IMAGING Forum

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Recent
    • Popular
    • Users
    • WIKI
    • veye.cc

    树莓派CM4+CS-MIPI-SC132 x2 运行python opencv报错

    VEYE MIPI camera
    2
    2
    279
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      sjchen last edited by

      由于CS-MIPI-SC132最大支持1280x1080,故修改capture2opencv脚本如下:

      import D_mipicamera as Dcam
      import time
      import cv2 #sudo apt-get install python-opencv
      
      def align_down(size, align):
          return (size & ~((align)-1))
      
      def align_up(size, align):
          return align_down(size + align - 1, align)
      
      if __name__ == "__main__":
          try:
              camera = Dcam.mipi_camera()
              print("Open camera...")
              camera.init_camera()
              while cv2.waitKey(10) != 27:
                  frame = camera.capture(encoding = 'i420')
                  height = int(align_up(1080, 16))
                  width = int(align_up(1280, 32)) #修改了分辨率
                  image = frame.as_array.reshape(int(height * 1.5), width)
                  image = cv2.cvtColor(image, cv2.COLOR_YUV2BGR_I420)
                  cv2.imshow("D-Cam", image)
                  # Release memory
                  camera.release_buffer(frame)
                  del frame
              
              print("Close camera...")
              camera.close_camera()
          except Exception as e:
              print(e)
      

      运行后报错:QQ截图20211217141752.jpg

      veye_xumm 1 Reply Last reply Reply Quote 0
      • veye_xumm
        veye_xumm @sjchen last edited by

        @sjchen
        除了你已经修改的地方之外,
        需要用
        D_init_camera_ex函数代替D_init_camera,这个函数具备分辨率的定义参数。

        1 Reply Last reply Reply Quote 0
        • First post
          Last post