mardi 31 mars 2015

Drawing a boundary around some dots in an image

I have recently started working on opencv. I have an image having several dots in a line. I want to make a rectangular border around these dots. I have applied some basic C algorithm but it didn't work for me. This is my code.



int main()

{

cv::Mat image = imread("C:/Users/Ravi Sharma/Desktop/img.bmp");

for(int i =0; i < image.rows; i++){
for(int k = 0; k <image.cols; k ++){
if((image.at<cv::Vec3b>(k,i)[0] == 0)&&(image.at<cv::Vec3b>(k,i)[1] == 135)&&(image.at<cv::Vec3b>(k,i)[2] == 255))
{
(image.at<cv::Vec3b>(k,i)[0] = 0)&&(image.at<cv::Vec3b>(k,i)[1] = 0)&&(image.at<cv::Vec3b>(k,i)[2] = 255);
}
}

}
imwrite("C:/Users/Ravi Sharma/Desktop/img1.bmp",image);
cv::namedWindow("Window1");
cv::imshow("Window1",image);
cv::waitKey(50000);
return 1;
}


This code is not updating the pixel value. Please help me correcting the code to get the desired result. How I can use cvminmaxloc function to do the same. Thanx in advance.


Aucun commentaire:

Enregistrer un commentaire