Reputation: 496
I need to flip (mirror) a frame received from webcam and I followed a code like this:
cv::flip(gray,gray,1);
imshow("flipped",gray);
gray is cv::Mat format and flipped is a cvNamedWindow. I get segmentation fault in qt creator IDE. I doubt about the dimension of the gray which might be the reason for the segmentation fault. gray is the gray scale image converted from the actual image received from the cam. How can I clear the error? does anybody has better ideas??
Upvotes: 2
Views: 17645
Reputation: 496
I thk MingW is the verdict. The version I use is reported to have some bugs like this one. So for gettting the mirror image I flipped the src image using flip code 0 and then rotated it by 180 degree to flip it along y axis.
cv::Mat dst;
cv::flip(src,dst,0);
Point2f src_center(dst.cols/2.0F, dst.rows/2.0F);
cv::Mat rot_matrix = getRotationMatrix2D(src_center, 180.0, 1.0);
cv::Mat rotated_img(Size(dst.size().height, dst.size().width), dst.type());
warpAffine(dst, rotated_img, rot_matrix, dst.size());
imshow("flipped",rotated_img);
Upvotes: 2
Reputation: 17005
one of the reasons for the segmentation fault is that you may not have implemented a check for a "bad" frame that is being passed by the webcam to OpenCV. You need to put a check for frame not being NULL and then use the flip/other operations on the stream.
Upvotes: 2