Use an OpenCV Threshold with a Kinect Image

I am trying to use the OpenCV threshold with the depth obtained by the OpenCV VideoCapture module, but I get the following error:

OpenCV error: invalid argument in unknown function, file PATHTOOPENCV \ opencv \ modules \ core \ src \ matrix.cpp line 646

My code is as follows:

#include "opencv2/opencv.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/gpu/gpu.hpp" cv::VideoCapture kinect; cv::Mat rgbMap; cv::Mat dispMap; bool newFrame; void setup() { kinect.open(CV_CAP_OPENNI); newFrame = false; } void update() { if(kinect.grab()) { kinect.retrieve( rgbMap, CV_CAP_OPENNI_BGR_IMAGE); kinect.retrieve( dispMap, CV_CAP_OPENNI_DISPARITY_MAP ); newFrame = true; } } void draw() { if(newFrame) { cv::Mat * _thresSrc = new cv::Mat(dispMap); cv::Mat * _thresDst = new cv::Mat(dispMap); cvThreshold(_thresSrc, _thresDst, 24, 255, CV_THRESH_BINARY); // Draw _thresDst; delete _thresSrc; delete _thresDst; newFrame = false; } } 

Many thanks for your help.

+2
source share
1 answer

To get started, you mix the C interface with the C ++ interface , and you can't mix them!

cv::Mat belongs to the C ++ interface, and cvThreshold() belongs to C. You should use cv::threshold() :

 double cv::threshold(const Mat& src, Mat& dst, double thresh, double maxVal, int thresholdType) 

Options:

 src โ€“ Source array (single-channel, 8-bit of 32-bit floating point) dst โ€“ Destination array; will have the same size and the same type as src thresh โ€“ Threshold value maxVal โ€“ Maximum value to use with THRESH_BINARY and THRESH_BINARY_INV thresholding types thresholdType โ€“ Thresholding type (see the discussion) 
+3
source

Source: https://habr.com/ru/post/976501/


All Articles