Ask Your Question
0

mat.at() not returning correct values after setting labels with rowrange()

asked 2020-08-14 08:21:59 -0600

CitationNotNeeded gravatar image

I have this code:

// Create the labels
cv::Mat labels(100, 1, CV_32SC1);
// first 50 labels of positive samples = 1.0
labels.rowRange(0, 50) = 1.0;
// last 50 labels of negative samples = -1.0
labels.rowRange(50, 100) = -1.0;
    //print labels
for (int i = 0; i < 100; i++)
    std::cout << "Label:" << i << " = " << labels.at<float>(i) << std::endl;

But something is wrong because my output looks like this:

Label:0 = 1.4013e-45

Label:1 = 1.4013e-45

Label:2 = 1.4013e-45

Label:3 = 1.4013e-45

....etc

The only values should be 1.0 or -1.0 yet I keep getting 1.4013e-45.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-08-14 08:51:54 -0600

berak gravatar image

updated 2020-08-14 08:53:20 -0600

this is an INTEGER Mat:

cv::Mat labels(100, 1, CV_32SC1);

but you access it as FLOAT:

labels.at<float>(i)

so, either use float or integer types consistently, and it'll work ;)

(and no, it's not the rowRange, that part is correct)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-08-14 08:21:59 -0600

Seen: 597 times

Last updated: Aug 14 '20