Ask Your Question
0

Encode image in JPG with OpenCV avoiding the artifacts effect

asked 2014-04-10 04:52:57 -0600

giordix gravatar image

I have an application (openCV - C++) that grab an image from webcam, encode it in JPG and trasmitt it from a Server to Client. Thwebcam is stereo so actually I have two image, LEFT and RIGHT. In the client, when I recieve the image I decode it and I generate an Anaglyph 3D Effect. For do this I use the OpenCV... Well I encode the image in this way:

   params.push_back(CV_IMWRITE_JPEG_QUALITY);
   params.push_back(60); //image quality
   imshow(image); // here the anagliphic image is good!
   cv::imencode(".jpg", image, buffer, params);

and decode in this way:

   cv::Mat imageRecieved = cv::imdecode( cv::Mat(v), CV_LOAD_IMAGE_COLOR );

What I see is that this kind of encode generate in the Anaglyph image a "ghost effect" (artifact?) so there is a bad effect with the edges of the object. If look a door for example there a ghost effect with the edge of the door. I'm sure that this depends of the encode because if I show the Anaglyph image before encode instruction this work well. I cannot use the PNG because it generate to large image and this is a problem for the connection between the Server and the Client.

I look for the GIF but, if I understood good, is nt supported by the cv::encode function.

So there is another way to encode a cv:Mat obj in JPG withou this bad effect and without increase to much the size of the image?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2014-04-10 05:13:13 -0600

Haris gravatar image

Check below code, It works fine for me. I didn’t felt any distortion between encode and decode.

Mat src=imread("src.jpg",1);
vector<uchar> buf;
imencode(".jpg",src,buf);

Mat dst=imdecode(buf,1);
imshow("src",src);
imshow("dst",dst);
waitKey();
edit flag offensive delete link more

Comments

Yes maybe because you use 100% of quality or maybe because you use a file a not a frame from a webcam. You code is the same of mine, cannot help me.

giordix gravatar imagegiordix ( 2014-04-10 05:19:15 -0600 )edit

I checked for web-cam also and works fine, as a first step you may need to decode your image just before sending to socket and make sure the sender side is fine.

Haris gravatar imageHaris ( 2014-04-10 05:28:16 -0600 )edit

Mmm no... I need to send the image when is encoded and after I recieve it, I can decode and show it..

giordix gravatar imagegiordix ( 2014-04-10 05:33:46 -0600 )edit

Question Tools

Stats

Asked: 2014-04-10 04:52:57 -0600

Seen: 17,463 times

Last updated: Apr 10 '14