Ask Your Question
0

Opencv row assignmement different values

asked 2016-12-20 15:58:48 -0600

lovaj gravatar image

I have this code in OpenCV:

cv::Mat1f codes(x,y);
...
for(int i=0; i<codes.rows ; i++){ //you don't care about n
  cv::Mat code(1,codes.cols, codes.type());
  encode_(..., code); //fill code with values
  codes.row(i) = code;
  std::cout<<"code= "<<code<<std::endl;
  std::cout<<"codes.row= "<<codes.row<<std::endl;
}

However the printed values are differents:

code= [-0.0018070865, -0.0088188984, -0.001866244, 0.0071420735, -0.00046708167, -0.0011722896, ...
codes.row= [0.091074832, 0.10463701, 0.060412209, 0.075102232, 0.036429934, 0.018214967, ...

Why this happens?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-12-21 00:10:56 -0600

berak gravatar image

instead of:

codes.row(i) = code;

which creates a temporary Mat header, you want:

code.copyTo(codes.row(i));

think of it like this: a cv::Mat holds continuous data, you can't simply insert an arbitrary pointer anywhere you like, but need to memcpy the specific region.

then, my compiler chokes on this:

 std::cout<<"codes.row= "<<codes.row<<std::endl;

codes.row is a function, you probably meant

 std::cout<<"codes.row= "<<codes.row(i) <<std::endl;
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-12-20 15:58:48 -0600

Seen: 89 times

Last updated: Dec 21 '16