accessing to a Matrix cell

asked 2014-06-22 03:32:09 -0600

ldn gravatar image

updated 2014-06-22 03:38:58 -0600

berak gravatar image


I am implementing some filters on my image, but the point is that when I use abs() and then try to imshow my result image, it's all black. the harris_result is a cv::Mat *harris_result.

cv::MatExpr x = cv::abs(re); harris_results = &x.a;//convert cv::MatExpr to cv::Mat and then when I want to print the content of harris_result

std::cout<<harris_results->at<uchar>(10,100)<<std::endl; harris_result="" is="" a="" cv::mat="" *harris_result<="" p="">

there is no error, but while debugging at this line it stops working.

I appreciate some help


edit retag flag offensive close merge delete


it probably needs a bit more code. where is harris_result coming from ?

also, you could try to format your code nicely (mark it , and press the 10101 button)

berak gravatar imageberak ( 2014-06-22 03:41:28 -0600 )edit

these code are in a function that returns harris_results,harris_features_def and a long value. that's why harris_result is a pointer. and I just need to access each cell . long harris(cv::Mat derivX, cv::Mat derivY,int is_first,cv::Mat *harris_results,cv::Mat *harris_features_def) and I just need to access each cell . as the below code is not working, just for test I tried to cout std::cout<<harris_results->at<uchar>(10,100)<<std::endl; to see is it's reading teh value, but it does not for (i=6 ; i < harris_results->rows; i++) for (j=6 ; j < harris_results->cols; j++) if ((harris_results->at<uchar>(i, j) > Harris_TH) && (i>5) && (i<1020) && (j>5) && (j<1020)) { harris_features[t][1]=harris_results->at<uchar>(i, j); harris_features[t][2]=i;...

ldn gravatar imageldn ( 2014-06-22 05:48:39 -0600 )edit

please, again, that should go into your question (code in comments is a PITA)

also, where does harris_result come from ? e.g. cornerHarris outputs float result Mats. you might access harris_results in a wrong way.

last, but not least, - do not pass cv::Mat as a Pointer, but as a reference. those things are refcounted internally (aka smart pointer) and you'll wreck havoc on that by passing pointers

berak gravatar imageberak ( 2014-06-22 06:01:13 -0600 )edit