简体   繁体   English

来自网络摄像头的阈值图像

[英]Thresholding Images from a Webcam

I am teaching myself OpenCV for a work project that will eventually involve object tracking and such, and I'm just trying to familiarize myself with the basics right now. 我正在教自己OpenCV的工作项目,最终将涉及对象跟踪等,而我现在只是想熟悉基础知识。 I have a chunk of code that's meant to simply grab images from my webcam, convert them to grayscale and threshold them, and print them out to a window. 我有一大堆代码,意在简单地从我的网络摄像头抓取图像,将它们转换为灰度和阈值,然后将它们打印到窗口。 I keep getting this error: 我一直收到这个错误:

"cannot convert parameter 1 from 'cv::Mat' to 'const CvArr *'" “无法将参数1从'cv :: Mat'转换为'const CvArr *'”

with this code: 使用此代码:

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main()
{
    Mat img;
    VideoCapture cap(0);

    while (true)
    {
        cap >> img;

        Mat tHold;
        cvtColor(img, tHold, CV_BGR2GRAY);
    cvThreshold(tHold, tHold, 50, 255, CV_THRESH_BINARY);

        imshow("Thresholded Image", tHold);
        waitKey(1);
    }

    return 0;
}

The thing is that other functions seem to work, like Canny(), etc...I just can't get thresholding to work. 事情是其他功能似乎工作,如Canny()等...我只是不能让阈值工作。 Thoughts? 思考? Thanks! 谢谢!

You are using the function cvThreshold from the C interface of OpenCV. 您正在使用OpenCV的C接口中的函数cvThreshold Whereas the input images are of type cv::Mat which are from the C++ interface. 而输入图像的类型为cv::Mat ,它来自C ++接口。

The corresponding C++ function of cvThreshold is cv::threshold . cvThreshold的相应C ++函数是cv::threshold Just replace cvThreshold with cv::threshold . 只需用cv::threshold替换cvThreshold

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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