Magick++ and YUYV

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
stephanecharette
Posts: 4
Joined: 2016-07-28T09:19:24-07:00
Authentication code: 1151

Magick++ and YUYV

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Magick++ and YUYV

Post 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.
snibgo's IM pages: im.snibgo.com
stephanecharette
Posts: 4
Joined: 2016-07-28T09:19:24-07:00
Authentication code: 1151

Re: Magick++ and YUYV

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Magick++ and YUYV

Post 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?
stephanecharette
Posts: 4
Joined: 2016-07-28T09:19:24-07:00
Authentication code: 1151

Re: Magick++ and YUYV

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