Get depth distance from an object

888 views Asked by At

I am trying to get the world coordinates of an object using Kinect, Openni 2.2.0.33 and OpenCV 2.4.10. I developed a code that runs well and get the values of X, Y and Z coordinates of an object. But there is something strange here....for some places in the room I get coherent values, but for some other places in the room I get values completely inacceptable, for example, instead of 2 meters I obtained 6 meters! I am not sure if there is some problem with my code, or with the device, or even with the drive. My guess is that the problem is in the return of deph (I am not sure if this is in pixels or mm or anything else). Follow my code, please any help will be appreciate!

sVideo.readFrame(&vFrame);
sVideoDepth.readFrame(&vFrameDepth); //Depth

matrizFrame.create(vFrame.getHeight(), vFrame.getWidth(), CV_8UC3); //cria matrizFrame
bufferImage.create(vFrame.getHeight(), vFrame.getWidth(), CV_8UC3); //cria matrizBuffer
IdentifyRed.create(vFrame.getHeight(), vFrame.getWidth(), CV_8UC3);
HSVImage.create(vFrame.getHeight(), vFrame.getWidth(), CV_8UC3); //create HSVImage
depthImage.create(vFrameDepth.getHeight(), vFrameDepth.getWidth(), CV_16UC1); //create DepthImage
bufferImage.data = (uchar*)vFrame.getData(); 

depthImage.data = (uchar*)vFrameDepth.getData(); //Depth
cv::cvtColor(bufferImage, matrizFrame, CV_BGR2RGB); //converte a matriz bufferImage de BGR para RGB e atribui a matrizFrame
cv::cvtColor(matrizFrame, HSVImage, CV_BGR2HSV); //converte a matriz bufferImage de BGR oara HSI e atribui a HSVImage

cv::inRange(HSVImage,cv::Scalar(160,80,80),cv::Scalar(255,255,255), IdentifyRed); //identify a red object
cv::erode(IdentifyRed, IdentifyRed, estruturaElemento);
cv::dilate(IdentifyRed,IdentifyRed, estruturaElemento);

red_2D = getCoordenadas2D(IdentifyRed); //function that get the 2D pixel coordinates of the object

ushort distanceRed = depthImage.at<ushort>(red_2D.x, red_2D.y); //using the 2D coordinate of the object in the color image, get the distance of the correspondent pixel in the DepthImage

openni::DepthPixel depthRed = distanceRed;

red_3D = getCoordenadas3D(red_2D.x, red_2D.y, depthRed); //use the function "openni::CoordinateConverter::convertDepthToWorld" to get the 3D world coordinates.

According with Openni documentation the return should be in mm, but the output of Z is exactly equal the input (distanceRed) value. Also for many places in the room this value is not acceptable!!

By the way this is my first post here, so I am sorry if I did somethimg wrong. Thanks in advance.

0

There are 0 answers