我想结合多个阈值来检测不同类型的红色。我尝试制作4种类型的阈值,然后我将4幅图像的结果合并为1.但结果总是漆黑。还有其他办法吗?我猜我使用addWeighted
将2图像合并为1的方式不正确Mat img = imread (nameImg);
cvtColor(img , hsv, CV_BGR2HSV);
Mat bw,bw2,bw3,bw4;
inRange(hsv, Scalar(0,28,192), Scalar(4,67,219),bw); // detecting acne 1
inRange(hsv, Scalar(0,40,152), Scalar(8,85,243),bw2); // acne 2
inRange(hsv, Scalar(0,85,202), Scalar(6,146,247),bw3); // acne 3
inRange(hsv, Scalar(156,93,176), Scalar(82,130,255),bw4); // acne 4
vector<vector<Point> > contours;
vector<vector<Point> > contours2;
vector<vector<Point> > contours3;
vector<vector<Point> > contours4;
findContours(bw.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
findContours(bw2.clone(), contours2, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
findContours(bw3.clone(), contours3, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
findContours(bw4.clone(), contours4, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
Mat dst = Mat::zeros(img.size(), img.type());
drawContours(dst, contours, -1, Scalar::all(255), CV_FILLED);
Mat dst2 = Mat::zeros(img.size(), img.type());
drawContours(dst2, contours2, -1, Scalar::all(255), CV_FILLED);
Mat dst3 = Mat::zeros(img.size(), img.type());
drawContours(dst3, contours4, -1, Scalar::all(255), CV_FILLED);
Mat dst4 = Mat::zeros(img.size(), img.type());
drawContours(dst4, contours4, -1, Scalar::all(255), CV_FILLED);
Mat dst5, dst6;
imshow("dst",dst);
imshow("dst2",dst2);
imshow("dst3",dst3);
imshow("dst4",dst4);
addWeighted(dst, 0.5, dst2, 0.5, 0,dst5);//combine acne 1 with 2
addWeighted(dst4, 0.5, dst3, 0.5, 0,dst6); //combine acne 3 with 4
addWeighted(dst5, 0.5, dst6, 0.5, 0,out);
imshow("result",out); //the result always black