Find the minimum value and it's location from the depth images

asked 2017-09-13 03:59:20 -0500

complex gravatar image

updated 2017-09-13 04:01:22 -0500

I am working depth data which is in the format of 16UC1. I want to find out the min value (greater than 0) with location from the image. I am using the minMaxLoc function but I am getting the error. It may be because of short values. It will be great , if you suggest the way. (previously I asked similar question but that question was general http://answers.opencv.org/question/17...)

int main() { Mat abc = imread("depth272.tiff"); cout << abc.size() << endl;

  imshow("depth_image",abc);
  Mat xyz = abc > 0;
  cout << "abc type: " << abc.type() << "xyz type " << xyz.type() << endl;

  double rmin, rmax;
  Point rMinPoint, pMaxPoint;
  minMaxLoc(abc, &rmin, &rmax, &rMinPoint, &pMaxPoint, xyz);
  int row = rMinPoint.x;
  int col = rMinPoint.y;

waitKey(0); return 0; }

edit retag flag offensive close merge delete

Comments

imread("depth272.tiff") // will read a 3 channel, 8bit image. you probably missed the -1 flag

and the error is ?

berak gravatar imageberak ( 2017-09-13 04:08:20 -0500 )edit

@berak, I have changed Mat abc = imread("depth272.tiff"); to Mat abc = imread("depth272.tiff", IMREAD_UNCHANGED); The error is gone but I am getting the type of the matrix xyz as 0. It may be because of comparison with 0. I need the type of xyz as same as abc i.e.2.

complex gravatar imagecomplex ( 2017-09-13 04:13:18 -0500 )edit
1

"I am getting the type of the matrix xyz as 0." -- yes, that's expected. a binary mask is uchar.

why do you need something else ?

berak gravatar imageberak ( 2017-09-13 04:16:39 -0500 )edit

Thank you @berak , now I understand :)

complex gravatar imagecomplex ( 2017-09-13 04:20:41 -0500 )edit