How does cv::mask should look like for opencv minMaxLoc?
Asked Answered
E

2

6

easy question but can't figure it out.

normaly its void minMaxLoc(InputArray src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0, InputArray mask=noArray()) But how does the mask looks like?

This is what i want: Its an one-dimensional Mat (only one row) and i want the minMax location of an interval(lower till upperBorder) of the Mat (maxRowGChnnl).

int lowerBorder,upperBorder;
lowerBorder = 30;
upperBorder = 100;
cv::minMaxLoc(maxRowGChnnl.row(0),&minValue,&maxValue,&minLoc,&maxLoc,(lowerBorder,upperBorder));

This is the maxRowGChnnl size:

maxRowGChnnl    {flags=1124024325 dims=2 rows=1 ...}    cv::Mat
flags   1124024325  int
dims    2   int
rows    1   int
cols    293 int

The code above abborts with:

OpenCV Error: Assertion failed ((cn == 1 && (mask.empty() || mask.type() == CV_8
U)) || (cn >= 1 && mask.empty() && !minIdx && !maxIdx)) in unknown function, fil
e ..\..\..\src\opencv\modules\core\src\stat.cpp, line 787

Thanks for your help.

Eyeopening answered 25/11, 2013 at 14:35 Comment(0)
F
5

You don't really need mask, but sub-matrix of maxRowGChnnl. You can do this by:

cv::minMaxLoc(maxRowGChnnl(Rect(lower,0,upper-lower,0)),&minValue,&maxValue,&minLoc,&maxLoc);
Fiedler answered 25/11, 2013 at 15:14 Comment(4)
this is the answer i was thinking off (the way it is solved). But actualy it did not work. When printing maxLoc I reseave [-1,-1]. When printing maxRowGChnnl(cv::Rect(lower,0,upper-lower,0)) the output is [] - empty. But the Mat maxRowGChnnl has values in it! What am I doing wrong?Eyeopening
Oups. My bad. Height should be 1 of course. Not 0. Use maxRowGChnnl(cv::Rect(lower,0,upper-lower,1))Fiedler
Perfect. Thats it! okay i see the construction of rect now.Eyeopening
explanation pleaseReniti
Z
8

mask should be cv::Mat the same size as axRowGChnnl.row(0) and type CV_8UC1. Enabled elements should have values equal 1 disabled 0.

Zeidman answered 25/11, 2013 at 14:51 Comment(0)
F
5

You don't really need mask, but sub-matrix of maxRowGChnnl. You can do this by:

cv::minMaxLoc(maxRowGChnnl(Rect(lower,0,upper-lower,0)),&minValue,&maxValue,&minLoc,&maxLoc);
Fiedler answered 25/11, 2013 at 15:14 Comment(4)
this is the answer i was thinking off (the way it is solved). But actualy it did not work. When printing maxLoc I reseave [-1,-1]. When printing maxRowGChnnl(cv::Rect(lower,0,upper-lower,0)) the output is [] - empty. But the Mat maxRowGChnnl has values in it! What am I doing wrong?Eyeopening
Oups. My bad. Height should be 1 of course. Not 0. Use maxRowGChnnl(cv::Rect(lower,0,upper-lower,1))Fiedler
Perfect. Thats it! okay i see the construction of rect now.Eyeopening
explanation pleaseReniti

© 2022 - 2024 — McMap. All rights reserved.