Webcam Raw image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
fabiovaz

Webcam Raw image

Post 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.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Webcam Raw image

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
fabiovaz

Re: Webcam Raw image (SOLVED)

Post 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 !
Post Reply