opencv - not correct print with unchar Mat for image 8UC1 c++ -
this question has answer here:
could please ? have image after canny detector, type 8uc1, when want access values, cout gives me ? (test canny�), code following:
mat src; /// load image src = imread( argv[1] ); if( !src.data ) { return -1; } mat src_gray(src.size[1],src.size[2],cv_8u,0);
//some parameters
int edgethresh = 1; //int lowthreshold; int lowthreshold = 100; int const max_lowthreshold = 100; int ratio = 3; int kernel_size = 3; //char* window_name = "edge map"; cvtcolor( src, src_gray, cv_bgr2gray ); mat detected_edges; /// reduce noise kernel 3x3 blur( src_gray, detected_edges, size(3,3) ); ///canny edge detection canny( detected_edges, detected_edges, lowthreshold, lowthreshold*ratio, kernel_size ); (unsigned int i=0;i<detected_edges.size[1];i++){ (unsigned int j=0;j<detected_edges.size[1];j++) { if (detected_edges.at<unsigned char>(i,j)!=0) cout<<"test canny"<<detected_edges.at<unsigned char>(i,j)<<endl; } }
when change in short, i.e. (i,j), gives me value between -256 , 255. not understand why type 8uc1, need use short , correct use short ? (to verify surely type have, used link how find out type of mat object mat::type() in opencv) thanks.
suddenly, found answer, because uchar has problems cout, need write std::cout<<"test canny"<<(int)detected_edges.at(i,j)<
Comments
Post a Comment