简体   繁体   中英

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:0@1.522] 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:0@1.527] 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:1@1.532] 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:1@1.543] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (539) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

You should test a different opencv backend , per default it's on CAP_ANY (auto detect) and it looks like it's trying to use MSMF in your windows OS.

Google says for Kintect on windows CAP_OPENNI2 should be working.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM