I am working on a video processing project that involves some sort of encryption using simple XOR operation of a given frame from camera with a key image and finally store the video file. And for decryption phase the XOR operation with the same image will get the original frames. But the problem is while I decrypt the frame appears to be very noisy and found out that its because of the lossy image compression foramt I used while storing. Is there any other lossless image compression foramts for opencv??
问题:
回答1:
If you are working on windows you can use CV_FOURCC_PROMPT
as the second parameter of VideoWriter
constructor - it will allow you to choose codec from list and set various options. Just for test you can use uncompressed avi (aka full frames [not compressed])
. It will produce huge files, but should work fine.
Otherwise just check all of possibilities from the list http://opencv.willowgarage.com/wiki/documentation/cpp/highgui/VideoWriter
Note that HighGui is meant as a simple tool for experimentation.
(http://opencv.willowgarage.com/wiki/VideoCodecs) so it may not provide the functionality you are looking for. If so you will have to use some other library and give it each frame processed by opencv.
回答2:
According to the old page of OpenCV:
There are several lossless video compressors available. No single one however is supported on all platforms at the same time. Look for HuffYUV, CorePNG, Motion PNG or Motion JPEG2000.
Recent OpenCV docs mentions a couple of alternatives as well, like JPG2000 and LAGS (Lagarith Lossless Codec).
Some time ago someone posted a message explaining how he had used OpenCV and FFmpeg to render videos with lossless compression.
回答3:
Official documentation says http://docs.opencv.org/trunk/dd/d9e/classcv_1_1VideoWriter.html#ad59c61d8881ba2b2da22cff5487465b5
Most codecs are lossy. If you want lossless video file you need to use a lossless codecs (eg. FFMPEG FFV1, Huffman HFYU, Lagarith LAGS, etc...)
If FFMPEG is enabled, using codec=0; fps=0; you can create an uncompressed (raw) video file.
回答4:
On Debian Linux (using ffmpeg):
int width = 640;
int height = 480;
bool isColor = true;
string outFName = "out.avi";
Size frameSize = Size(width, height);
int fourcc = VideoWriter::fourcc('p', 'n', 'g', ' ');
outputVideo.open(outFName, fourcc, cap.get(CAP_PROP_FPS), frameSize, isColor));