I know this question has been answered, but when I tried the solutions, It did not take me anywhere.
Below is the given code I have written to get the left and the right most boundary of an image, that was thresholded using canny edge detector, OpenCV.
#include<iostream>
#include<vector>
#include<math.h>
#include<string>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;
int main(int argc, char **argv)
{
int thresh = 100,rows = 0,cols = 0;;
Mat src,src_gray,canny_output;
src = imread( argv[1]);
cvtColor( src, src_gray, CV_BGR2GRAY );
blur( src_gray, src_gray, Size(3,3) );
Canny( src_gray, canny_output, thresh, thresh*3, 3 );
Mat boundary_image = Mat::zeros( canny_output.size(), CV_8UC1 );
rows = canny_output.rows;
cols = canny_output.cols;
cout<<rows<<endl<<cols<<endl;
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
cout<<canny_output.at<uchar>(i,j)<<endl;
if(canny_output.at<uchar>(i,j) == 255)
{
boundary_image.at<uchar>(i,j) = 255;
break;
}
}
for(int k = cols;k>0;k--)
{
if(canny_output.at<uchar>(i,k) == 255)
{
boundary_image.at<uchar>(i,k) = 255;
break;
}
}
}
imshow("boundary_image",boundary_image);
waitKey(0);
return 0;
}
Whether the algorithm works or not is secondary, but am not able to view the value of the canny edge detected image. It is showing some symbols or empty values. Can you please tell me where I am going wrong?
Note: The question is with the print statement
cout<<canny_output.at<uchar>(i,j)<<endl;
which is not giving me any reasonable values at the output to view the pixel values. Similar questions where posted and the answer was to use uchar as the data type, but in my case, it is not working. It may sound rudimentary, but your help is greatly appreciated.