Search code examples
pythonopencvkinect

Kinect RGB camera not working but IR camera works in python


I just trying to open the Kinect v2 RGB camera with cv2.VideoCapture(0) and it's not showing the video but if I change the video rotation of Kinect in windows settings it will work with IR camera.

How can I use RGB camera?

Here is the code:

import cv2
vid = cv2.VideoCapture(0)

while vid.isOpened():
    ret, frame = vid.read()
    if not ret:
       break

    cv2.imshow('frame', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

vid.release()
cv2.destroyAllWindows()

Errors:

  1. [ WARN:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (464) `anonymous-namespace'::SourceReaderCB::OnReadSample videoio(MSMF): OnReadSample() is called with error status: -2147024809

  2. [ WARN:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (476) `anonymous-namespace'::SourceReaderCB::OnReadSample videoio(MSMF): async ReadSample() call is failed with error status: -2147024809

  3. [ WARN:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (1752) CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -2147024809

  4. [ WARN:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (539) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback


Solution

  • In my opinion,you can use the

    vid = cv2.VideoCapture(0,cv2.CAP_DSHOW)
    

    instead it seems is the problem of Windows MSMF api you can use the Directorshow api instead I meet this problem before and slove it in this way.I hope that answer will help you.