c++ - 将 OpenCV 阈值与 Kinect 图像结合使用

标签 c++ c opencv image-processing kinect

我尝试将 OpenCV 阈值与 OpenCV VideoCapture 模块检索的深度图像结合使用,但出现以下错误:

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

我的代码如下:

#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;
    }
}

非常感谢您的帮助

最佳答案

首先,您正在将 C 接口(interface)与 C++ 接口(interface)混合在一起,并且它们不应该混合在一起!

cv::Mat 属于 C++ 接口(interface),cvThreshold() 属于 C。您应该使用 cv::threshold()相反:

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

Parameters:

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)

关于c++ - 将 OpenCV 阈值与 Kinect 图像结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9470375/

相关文章:

c++ - 按引用调用和按值调用之间的区别

opencv - 使用 OpenCV 进行高效的背景去除

c++ - 终止已由另一个服务启动的服务(内核级)

c++ - 如何在 C++ 中使用继承序列化类

c++ - 在 boost 中禁用中断会禁用上下文切换吗?

python - C.dll 如何向 Python 公开变量?

c++ - 在 C++ 中, "static initialization fiasco"是否仅影响引用另一个模块中定义的对象的数据成员?

c - 如何在结构 C 的数组中搜索

python - OpenCV 中的 Tensorflow 自定义模型

java - Android:将 calcOpticalFlowPyrLK 与 MatOfPoint2f 结合使用