Page 1 of 1

Webcam Raw image

Posted: 2009-05-19T11:04:42-07:00
by fabiovaz
Dear fellows,

Does anyone know how I convert a headerless image raw file into any format using IM ? I'm working with a "C" program which captured an image from a webcam. The resultant file has 640x480, 24-bits per pixel (size:921600 bytes). Note that this file has no header or pallete associated.

Any help much appreciated.

Thank you in advance,
Fabio Vaz.

Re: Webcam Raw image

Posted: 2009-05-19T13:56:52-07:00
by el_supremo
If you can modify the C program, you can build the conversion into it using the MagickWand API.
Just edit this function into the program.

Code: Select all

#include <wand/MagickWand.h>
void convert_webcam(unsigned char *image,char *fname)
{
	MagickWand *mw;

	MagickWandGenesis();

	mw = NewMagickWand();
	// transfer the raw image to a MagickWand
	MagickConstituteImage(mw,640,480,"RGB",CharPixel,image);

	// and use MagickWand to write it out in any format you like
	MagickWriteImage(mw,fname);
	
	mw = DestroyMagickWand(mw);
	MagickWandTerminus();
}
Once it works you should add some error checking just in case the Constitute or the Write fail.

If you can't change the program, you can use Imagemagick's convert program to do the file format conversion. Prefix your filename with "rgb:" to tell IM the structure of the file.

Code: Select all

convert -size 640x480 -depth 8 rgb:input_file output.png
Pete

Re: Webcam Raw image (SOLVED)

Posted: 2009-05-19T14:33:42-07:00
by fabiovaz
Pete,

It worked fine with imageMagick convert command you sent !!!!!!!! I'll try to work with the MagickWand APi now.

Thank you very very much for your help !