inRange Query图像输出



我已经开始学习opencv,并编写了以下代码,以获得hsv中图像(来自输入相机)和inRange图像的输出!hsv输出很好,但inRange o/p只是空白:|plz help am stupped

int main(int argc[], char** argv[])
   {
VideoCapture camera(CV_CAP_ANY);
Mat input;
Mat output(Size(input.size().height,input.size().width),input.type());
Mat img_thresh(Size(640,480),input.type());
namedWindow("input",0);
namedWindow("output",0);
namedWindow("threshold",0);
cv::Scalar hsv_min = cvScalar(0, 30, 80, 0);
    cv::Scalar hsv_max = cvScalar(20, 150, 255, 0);
for(;;)
{
    camera >> input;
    cvtColor(input,output,CV_BGR2HSV,1);
    cv::inRange(input,hsv_min,hsv_max,img_thresh);  
    imshow("input",input);
    imshow("output",output);
    imshow("threshold",img_thresh);
    cv::waitKey(40);    
}
return 0;

}

将inRange函数应用于输入BGR图像。您必须将其应用于HSV图像,在代码中命名输出。所以这条线应该是:

cv::inRange(output,hsv_min,hsv_max,img_thresh);

您的代码正在运行,但您没有使用正确的图像!

如果你想知道你的图像中HSV的值,我建议你使用:

cvSetMouseCallback("input", getObjectColor);

和:

void getObjectColor(int event, int x, int y, int flags, void *param = NULL) {
    // Vars
    CvScalar pixel;
    IplImage *hsv;
    if(event == CV_EVENT_LBUTTONUP) {
        // Get the hsv image
        hsv = cvCloneImage(image);
        cvCvtColor(image, hsv, CV_BGR2HSV);
        // Get the selected pixel
        pixel = cvGet2D(hsv, y, x);
        cvShowImage("getObjColor", hsv);
        // Change the value of the tracked color with the color of the selected pixel
        h = (int)pixel.val[0];
        s = (int)pixel.val[1];
        v = (int)pixel.val[2];
        cout << "Color HSV = h:" << pixel.val[0] << " | s:" << pixel.val[1] << " | v:" << pixel.val[2] << endl;
        // Release the memory of the hsv image
            cvReleaseImage(&hsv);
    } 
}

您需要创建一些变量来实现这一点,代码取自互联网(记不清在哪里了!)

相关内容

  • 没有找到相关文章

最新更新