With ffmpeg's example extract_mvs.c, I am getting black and white images from color rtsp camera - libavcodec

I am using the extract_mvs.c from ffmpeg:
https://ffmpeg.org/doxygen/2.5/extract__mvs_8c_source.html
I added opencv to imwrite the image.
cv::Mat img(frame->height,frame->width,CV_8UC1,frame->data[0]);
imwrite( "pic.jpg", img );
That works because the image in the frame is in grayscale. The camera is a color camera however, and I dont know why I am getting grayscale. If I cange the above to CV_8UC3, I get segmentation fault.
I tried to save the image with ppm_save function and I still get a black and white frame when there should be a color frame. Any ideas?
Thanks,
Chris

Just read about graphics file formats and such. JPG requires BGR24 format. The raw frame buffer format YUV420P needs to be converted to BGR24 using swscale. Then the output frames height and width needs to be manually set before calling :
cv::Mat img(out_frame->height,out_frame->width,CV_8UC3,out_frame->data[0]);
imwrite( "pic.jpg", img );
Likewise,PPM file format requires RGB24 and the raw format needs to be converted to this before saving the ppm file.
Thanks,
Chris

Related

How can I export .hdr or .exr image from iPhone HDRI photo (.HEIC format)?

I want to take HDR photos with my iPhone and get images as .hdr or .exr image formats, in order to use them for my cinema rendering purpose.
I took some HDR photos with my iPhone X and sent them to my iMac, and then I tried converting them from .HEIC format to .exr format with sips command like below:
sips -s format exr image.HEIC
However, it turned out that output .exr images seemed not to be adequate OpenEXR images. Actually I tried to import one of the images with OpenCV in Python and checked its max RGB value on numpy ndarray like below, but it was just 1.0, although there was obviously very bright light there.
img = np.array(cv.imread(img_path, cv.IMREAD_ANYCOLOR | cv.IMREAD_ANYDEPTH))
print(img.max())
How can I get HDR images in the right way with my iPhone? If you know any other better ways to do that, can you tell me about it? Thank you.

saveas white border matlab

I want to save a frame as an image in png format with saveas command. Although my image's size is 640X480 (gcf), the saved images size is 1201x901 and spaces white color.(like a bold white border).So I want the image to be saved 640x480.
I tried transparent background but it didn't work. How can I fix this problem?
F(j) = getframe(gcf);
fname='C:\...'
saveas(gcf, fullfile(fname, 'newImage'), 'png');
Try this,
set(gca,'position',[0 0 1 1],'units','normalized')
or you can try the imcropfunction.
If you aren't overlaying any graphics over the image, then save the image data directly using imwrite, rather than exporting a figure containing the image to png.
If you are overlaying graphics then the export_fig function (available for download on the MATLAB File Exchange) will automatically crop the whitespace around the figure. In this case use:
export_fig(fullfile(fname, 'newImage'), '-png', '-a1', '-native');

GLPaint - Save image as vector image

I am using CGColorSpaceCreateDeviceRGB() which returns a png image(pixel format)? Is there a way to save this image as a vector image. Basically I need to save the pictures drawn by the GLPaint application as a vector image.
I don't know anything about this function or about GLPaint, but you can't take a pixellized image and turn it into a vector image. Only humans and highly clever algorithms can do that ( see http://vectormagic.com/ )
If you have access to the input (gestures?) of GLPaint, you should convert them to SVG directly instead of passing through an RGB image.

The color of video is wrong when made from UIImage of the PNG files

I am taking a UIImage from Png file and feed it to the videoWriter.
avAdaptor appendPixelBuffer:pixelBuffer
When the end result video comes out, it seems to lacking the one color, missing the yellow color or something.
I take alook of the function that made the pixelbuffer out of the UIImage
CVPixelBufferCreateWithBytes(NULL,
myWidth,
myHeight,
kCVPixelFormatType_32BGRA,
(void*)CFDataGetBytePtr(image),
CGImageGetBytesPerRow(cgImage),
NULL,
0,
NULL,
&pixelBuffer);
I also try the kCVPixelFormatType_32AGRB and others, it didn't help.
any thoughts?
Please verify if your PNG image is with or without transparency element. If your PNG image doesn't contain transparency then it's 24-bit and not 32-bit per pixel.
Also, have you tried kCVPixelFormatType_32RGBA ?
Maybe the image sizes do not fit together.
Your input image should have the same width and height like the video output. If "myWidth" or "myHeight" is different (i.e. different aspect ratio) to the size of the image, one byte may be lost at the end of the line, which could lead to color shifting. kCVPixelFormatType_32BGRA seems to be the preferred (fastest) pixel format, so this should be okay.
There is no yellow color in RGB colorspace. This means yellow is only the >red< and >green< components. It seems that >blue< is missing.
I assume you are using a CFDataRef (maybe NSData) for the image. If it is an NSData object you can print the bytes to the debug console using
NSLog(#"data: %#", image);
This will print a hex dump to the console. Here you can see if you have alpha and what kind of byte order your png is alike. If your image has alpha, every fourth byte should be the same number.

How to change background color of an eps file while converting it to jpeg or png

I am converting eps (Encapsulated PostScript) files to jpeg files with ghostscript. A sample command I use is:
gswin32.exe -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r600x600 -dGraphicsAlphaBits=4 -dUseCIEColor -dEPSCrop -sOutputFile=”a.jpeg” b.eps
The input eps files come with white backgrounds (I only have their clipping path). What I need to do is change this white background to another color in the output images, or it would be even better if I could make them transparent (output file format would be png). How can I do this?
never tried it myself but you should be able to convert your eps file into png by setting:
-sDEVICE=pngalpha
also the pngalpha device has a -dBackgroundColor option:
-dBackgroundColor=16#RRGGBB (RGB color, default white = 16#ffffff) For
the pngalpha device only, set the
suggested background color in the PNG
bKGD chunk. When a program reading a
PNG file does not support alpha
transparency, the PNG library converts
the image using either a background
color if supplied by the program or
the bKGD chunk. One common web browser
has this problem, so when using on a web page you
would need to use
-dBackgroundColor=16#CCCC00 when creating alpha transparent PNG images
for use on the page.
more details here: Details of Ghostscript output devices see section 3.1. PNG file format
After you've obtained your (white background) images from Ghostscript, you could use ImageMagick's convert or GraphicMagick's gm convert commands to change the white to transparent background:
convert -background transparent my.png my_transp.png