Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I found a code written by others, which can open the kinect videostream and show in the windows by OpenCV, however there are sth. wrong #63

Open
yxp1003 opened this issue Nov 30, 2018 · 3 comments

Comments

@yxp1003
Copy link

yxp1003 commented Nov 30, 2018

the code:
from pykinect2 import PyKinectV2
from pykinect2.PyKinectV2 import *
from pykinect2 import PyKinectRuntime
import numpy as np
import cv2

kinect = PyKinectRuntime.PyKinectRuntime(PyKinectV2.FrameSourceTypes_Color)

while True:
# --- Getting frames and drawing
if kinect.has_new_color_frame():
frame = kinect.get_last_color_frame()
frame = frame.astype(np.uint8)
frame = np.reshape(frame, (2880, 2880))
img = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)
output = cv2.bilateralFilter(img, 9, 150, 75)
cv2.imshow('KINECT Video Stream', output)
frame = None

key = cv2.waitKey(1)
if key == 27: break

the result:
image

I dont know how to fix it, anybody can help me, plz...

@Franzisdrak
Copy link

Hey there,

Did you read all of that code? Try to understand what each line does. You learn way more then if sb just tells you.

Hint:
Check what resolution the kinect uses for the rgb image.

@yxp1003
Copy link
Author

yxp1003 commented Nov 30, 2018

Hey there,

Did you read all of that code? Try to understand what each line does. You learn way more then if sb just tells you.

Hint:
Check what resolution the kinect uses for the rgb image.

I checked the resolution of kinect , and change the 'frame = np.reshape(frame, (2880, 2880))' to '(1920, 1080)', but there has a Exception: 'ValueError: cannot reshape array of size 8294400 into shape (1920,1080)'
yeah, I read the sourcecode just now, and successed show it by pygame.
Nevertheless when I wanna to preccess it with OpenCV, there are sth trouble:

frame = self._kinect.get_last_color_frame()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

Error:
Traceback (most recent call last):
File "E:/PycharmProjects/PyKinect2/venv/real.py", line 97, in
game.run();
File "E:/PycharmProjects/PyKinect2/venv/real.py", line 72, in run
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(3.4.4) c:\projects\opencv-python\opencv\modules\imgproc\src\color.hpp:255: error: (-2:Unspecified error) in function '__cdecl cv::CvtHelper<struct cv::Set<3,4,-1>,struct cv::Set<1,-1,-1>,struct cv::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)'

Invalid number of channels in input image:
'VScn::contains(scn)'
where
'scn' is 1

I have fixed it for a long time.....
anyway, thanks a lot for your help

@yxp1003
Copy link
Author

yxp1003 commented Dec 1, 2018

嘿,

你读过所有代码了吗?试着了解每一行的作用。如果某人告诉你,你会学到更多的东西。

提示:
检查kinect用于rgb图像的分辨率。

Hi,

嘿,

你读过所有代码了吗?试着了解每一行的作用。如果某人告诉你,你会学到更多的东西。

提示:
检查kinect用于rgb图像的分辨率。

Hi,
Can you leave me a E-mail address? I really have some questions that have been bothering me for several days. plz
thank you so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants