Page 1 of 1

Magick++ and YUYV

Posted: 2016-07-28T09:49:53-07:00
by stephanecharette
Using magick++6.q16-5 on Debian running on ARM7 device. Reading from V4L2 (Video 4 Linux 2) USB camera, the input stream identifies itself as follows:

Code: Select all

Video input : 0 (Camera 1: ok)
Format Video Capture:
	Width/Height  : 640/480
	Pixel Format  : 'YUYV'
	Field         : None
	Bytes per Line: 1280
	Size Image    : 614400
	Colorspace    : SRGB
	Flags         : 
The size of 614400 seems right, since 640x480x2 (2 bytes per pixel) gives 614400. I'd like to take these 614400 bytes of data and convert them to a Magick::Image object. This is what I've tried:

Code: Select all

Magick::Blob blob( buffer, buffer_len );
Magick::Image img;
img.size( Magick::Geometry(640, 480) );
img.magick( "YUYV" );
img.read( blob );
img.write( "test.jpg" );
But this doesn't work. the img.read(blob) line throws a C++ exception:

Code: Select all

terminate called after throwing an instance of 'Magick::ErrorMissingDelegate'
  what():  Magick: no decode delegate for this image format `YUYV' @ error/blob.c/BlobToImage/361
So hunting around, I see that Magick needs the data in UYVY format instead. I swap every byte around in the buffer to be UYVY, change this line:

Code: Select all

img.magick( "UYVY" );
...and while this now runs to completion, the images it produces aren't right. Pointing the camera out the window to a bunch of green shrubs and trees produces this:

Image

Anyone have insight into what I'm doing wrong? In case it is relevant, I also ran into a problem including Magick++.h:

Code: Select all

/usr/include/ImageMagick-6/magick/magick-config.h:29:3: warning: #warning "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default" [-Wcpp]
 # warning "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default"
Not knowing what to do, I've tried to set -DMAGICKCORE_QUANTUM_DEPTH=8 and to 16 when building my code, but this doesn't seem to change my problem.

Re: Magick++ and YUYV

Posted: 2016-07-28T10:33:08-07:00
by snibgo
In case it is relevant, I also ran into a problem including Magick++.h:
That is bad news. It means the build is bad. I suggest you solve this before trying to use IM further.

For decoding video, have you tried ffmpeg? It seems a more obvious choice.

Re: Magick++ and YUYV

Posted: 2016-07-28T10:41:25-07:00
by stephanecharette
I'm not trying to get video. I'm using it as a still camera. I can read the image, now all I need is a way to interpret the bytes.

As for "the build is bad" -- this is exactly how it installed when I ran "sudo apt-get install libmagick++-dev". The Debian repo is like this, I did not build from source.

Re: Magick++ and YUYV

Posted: 2016-07-28T10:49:33-07:00
by fmw42

Code: Select all

convert -list colorspace
does not list a YUYV format. So I am not sure IM understands that. I have never heard of that format. But I know little about such. Is that a special version of YUV?

https://msdn.microsoft.com/en-us/library/ms867704.aspx shows a layout of UYVY. Is that the same but reordered?

Re: Magick++ and YUYV

Posted: 2016-07-28T12:33:49-07:00
by stephanecharette
fmw42 wrote:...does not list a YUYV format. So I am not sure IM understands that. I have never heard of that format. But I know little about such. Is that a special version of YUV?
YUY2 aka YUNV aka V422 aka YUYV: http://www.fourcc.org/yuv.php#YUYV