opencv提取图像中红色范围,结果一直出错
intmain(intargc,char**argv){IplImage*image=cvLoadImage("C:\\Users\\Public\\Pictures\\...
int main(int argc,char **argv)
{
IplImage* image = cvLoadImage("C:\\Users\\Public\\Pictures\\Sample Pictures\\***.jpg");
cvNamedWindow("output",CV_WINDOW_AUTOSIZE);
IplImage* imageHSV =cvCreateImage(cvGetSize(image),image->depth,3);
IplImage* image_11 =cvCreateImage(cvGetSize(image),image->depth,3);
cvCvtColor( image, image_11, CV_RGB2BGR );//BRG 转换到 HSV
cvCvtColor( image_11, imageHSV, CV_BGR2HSV );
IplImage* h_space =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
IplImage* s_space =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
IplImage* v_space =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
cvSplit(imageHSV,h_space,s_space,v_space,NULL);//提取HSV各通道
IplImage* h_s1 =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);//H通道域值化
IplImage* h_s2 =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
IplImage* h_s3 =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
IplImage* h_s4 =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
IplImage* h_s5 =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
cvThreshold(h_space,h_s1,180,255,CV_THRESH_BINARY_INV);
cvThreshold(h_space,h_s2,160,255,CV_THRESH_BINARY);
cvAnd(h_s1,h_s2,h_s3);
cvAnd(h_s3,h_space,h_s5);
IplImage* hsv =cvCreateImage(cvGetSize(image),image->depth,3);
IplImage* image_1 =cvCreateImage(cvGetSize(image),image->depth,3);
cvMerge(h_s5,h_s5,h_s5,NULL,hsv);
cvCvtColor( hsv,image_1, CV_HSV2BGR );
cvShowImage("output",image_1);
cvWaitKey(0);
cvReleaseImage(&image_1);
cvDestroyWindow("output");
} 展开
{
IplImage* image = cvLoadImage("C:\\Users\\Public\\Pictures\\Sample Pictures\\***.jpg");
cvNamedWindow("output",CV_WINDOW_AUTOSIZE);
IplImage* imageHSV =cvCreateImage(cvGetSize(image),image->depth,3);
IplImage* image_11 =cvCreateImage(cvGetSize(image),image->depth,3);
cvCvtColor( image, image_11, CV_RGB2BGR );//BRG 转换到 HSV
cvCvtColor( image_11, imageHSV, CV_BGR2HSV );
IplImage* h_space =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
IplImage* s_space =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
IplImage* v_space =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
cvSplit(imageHSV,h_space,s_space,v_space,NULL);//提取HSV各通道
IplImage* h_s1 =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);//H通道域值化
IplImage* h_s2 =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
IplImage* h_s3 =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
IplImage* h_s4 =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
IplImage* h_s5 =cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
cvThreshold(h_space,h_s1,180,255,CV_THRESH_BINARY_INV);
cvThreshold(h_space,h_s2,160,255,CV_THRESH_BINARY);
cvAnd(h_s1,h_s2,h_s3);
cvAnd(h_s3,h_space,h_s5);
IplImage* hsv =cvCreateImage(cvGetSize(image),image->depth,3);
IplImage* image_1 =cvCreateImage(cvGetSize(image),image->depth,3);
cvMerge(h_s5,h_s5,h_s5,NULL,hsv);
cvCvtColor( hsv,image_1, CV_HSV2BGR );
cvShowImage("output",image_1);
cvWaitKey(0);
cvReleaseImage(&image_1);
cvDestroyWindow("output");
} 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏100(财富值+成长值)
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询