Ask Your Question

carobnodrvo's profile - activity

2019-04-01 08:41:32 -0600 asked a question calibrateCamera assertion error

calibrateCamera assertion error I am trying to calculate camera intrinsic parameters with calibrateCamera and findChessb

2016-05-14 06:11:59 -0600 received badge  Supporter (source)
2016-05-13 12:53:08 -0600 commented question Accessing each pixel of a Mat .at vs pointer arithmetic gives differnet result

@berak Thanks for the hint but problem is same... Please check edited question.

2016-05-13 12:43:43 -0600 received badge  Editor (source)
2016-05-13 12:42:57 -0600 asked a question Accessing each pixel of a Mat .at vs pointer arithmetic gives differnet result

Today I stumbled across this (for me) weird thing, namely when I run this code

m.convertTo(tmp_mat, CV_32FC3, 1./255);
cvtColor(tmp_mat, tmp_mat, CV_RGB2XYZ, 3);
split(tmp_mat, xyz_channels);

y_channel = xyz_channels[1].clone();

int i,j;
uint8_t* p = y_channel.data;
for( i = 0; i < y_channel.rows; ++i)
{
    for ( j = 0; j < y_channel.cols; ++j)
    {
       std::cout << y_channel.at<float>(i,j) << std::endl;
       std::cout << saturate_cast<float>(p[i*y_channel.cols + j]) << std::endl;
    }
}

this is the output I get

0.984314
123
0.984314
63
0.984314
254
0.984314
251
0.984314
123
0.984314
63
0.984314
254
0.984314
251
0.984314
123
0.984314
63
...

So now I am confused - shouldn't it be same?

2016-03-19 12:18:52 -0600 commented answer compare/countNonZero return bigger value then expected

Many thanks kind Sir. That's the thing I needed.

2016-03-19 12:10:47 -0600 commented answer compare/countNonZero return bigger value then expected

That works and it's because compare/countNonZero count also where both matrices are 0 whereas nested loop doesn't.

Well pixel s1 or s2 can either be 0 or 255 so if they are both 255 I increase score by one and if they are 0 (or different) I don't count it. That was my logic.

One more question: Can I implement my logic from above with compare/countNonZero (currently I think no but I want to her another opinion)

2016-03-19 12:10:10 -0600 received badge  Scholar (source)
2016-03-19 11:48:53 -0600 asked a question compare/countNonZero return bigger value then expected

If I take 2 binary images (pixel values 0 or 255) and compare them with compare/countNonZero and then with two nested loops I don't get same "score".

So first I use this code:

compare(mat1, mat2, mat_tmp, CMP_EQ);

score = countNonZero(mat_tmp);

and then this:

for (int x = 0; x < mat1.cols; ++x)
{
    for (int y = 0; y < mat2.rows; ++y)
    {
        Scalar s1 = mat1.at<uchar>(y,x);
        Scalar s2 = mat2.at<uchar>(y,x);
        score += (s1.val[0]/255)*(s2.val[0]/255);
    }
}

the score values are significantly different (e.g. compare/countNonZero score=206 814 and for nested loops is 1022).

Shouldn't it be same? Why is it so? Have I misunderstood something?