关于识别不同颜色的错误

时间:2013-07-08 01:07:19

标签: c++ opencv

#include "stdafx.h"

#include <cv.h>
#include <highgui.h>


/*IplImage* GetThresholdedImage(IplImage* imgHSV){        
       IplImage* imgThresh=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1);
       cvInRangeS(imgHSV, cvScalar(170,160,60), cvScalar(180,256,256), imgThresh); 
       return imgThresh;
} */
IplImage* GetThresholdedImage(IplImage* imgHSV, CvScalar lower, CvScalar upper)
{       
    IplImage* imgThresh=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1);
    cvInRangeS(imgHSV, lower, upper, imgThresh); 
    return imgThresh;
}

IplImage* hsv;


CvScalar blue_upper = cvScalar(120,256,256);
CvScalar green_lower = cvScalar(40,60,10);
CvScalar green_upper = cvScalar(71,256,256);

IplImage* blue_mask = GetThresholdedImage(hsv, blue_lower, blue_upper);
IplImage* green_mask = GetThresholdedImage(hsv, green_lower, green_upper);

int main(){
      CvCapture* capture =0;       

      capture = cvCaptureFromCAM(0);
      if(!capture){
            printf("Capture failure\n");
            return -1;
      }

      IplImage* frame=0;
      cvNamedWindow("Video");      
      cvNamedWindow("Ball");


      while(true){

            frame = cvQueryFrame(capture);            
            if(!frame) break;

            frame=cvCloneImage(frame); 
            cvSmooth(frame, frame, CV_GAUSSIAN,3,3); 

            IplImage* imgHSV = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3); 
            cvCvtColor(frame, imgHSV, CV_BGR2HSV); 
            IplImage* imgThresh = GetThresholdedImage(imgHSV);

            cvSmooth(imgThresh, imgThresh, CV_GAUSSIAN,3,3);

            cvShowImage("Ball", imgThresh);            
            cvShowImage("Video", frame);


            cvReleaseImage(&imgHSV);
            cvReleaseImage(&imgThresh);            
            cvReleaseImage(&frame);


            int c = cvWaitKey(10);
            if((char)c==27 ) break;      
      }

      cvDestroyAllWindows() ;
      cvReleaseCapture(&capture);     

      return 0;
}

上面是我的代码,告诉不同的颜色,但事实证明主要功能有问题。基本上主要功能就是激活凸轮。错误是:“GetThresholdedImage不接受1个参数”。有人可以给我一些提示吗?

1 个答案:

答案 0 :(得分:1)

该行

IplImage* imgThresh = GetThresholdedImage(imgHSV);

是导致错误的原因。功能界面

GetThresholdedImage

有三个参数,如

中所用
IplImage* blue_mask = GetThresholdedImage(hsv, blue_lower, blue_upper);
IplImage* green_mask = GetThresholdedImage(hsv, green_lower, green_upper);

您必须添加其他两个参数,例如:

IplImage* imgThresh = GetThresholdedImage(imgHSV, blue_lower, blue_upper);

取决于您对图像的处理方式。