copy half image
Hello All.
I have an image:
MAt gray which the size is 480*640 and its 1 channel and I need to copy the half images:
Mat edges1 (480, 640/2, CV_8U); Mat edges2 (480,640/2, CV_8U);
for(int i=0;i<480;i++) { for(int j=0;j<640/2;j++) {
edges1.at<uchar>(i,j)=gray.at<uchar>(i,j);
} }
for(int i=0;i<480;i++) { for(int j=640/2;j<640;j++) {
edges2.at<uchar>(i,j)=gray.at<uchar>(i,j);
} } imwrite("bordes1.png", edges1,compression_params); imwrite("bordes2.png", edges2,compression_params); return 1; }
But I got Segmentation fault. What can it be?
you can find proper code sample here
Oh, thanks a lot. But whats the problem with my code? I'm seeing that work in a low leves with opencv always get problem. I have to use the function defines in opencv headres to make samething.
i did not try your code but try swapping i & j ( this code works slow)
your 2nd case starts counting j at 640/2, which is correct for the src image, but already out of bounds for the dst image.
you are right! thanks