Re: [libdc] convert libdc1394video_frame_t to IplImage or SDL_image
Capture and control API for IIDC compliant cameras
Brought to you by:
ddouxchamps,
gordp
From: Jean F. <jea...@go...> - 2008-10-05 09:21:14
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> -------- Original Message --------<br> Subject: Re:[libdc] convert libdc1394video_frame_t to IplImage or SDL_image<br> From: Jeremy Leibs <a class="moz-txt-link-rfc2396E" href="mailto:le...@wi..."><le...@wi...></a><br> To: libdc1394-devel <a class="moz-txt-link-rfc2396E" href="mailto:lib...@li..."><lib...@li...></a><br> Date: 5.10.2008 2:13 Uhr<br> <blockquote cite="mid:48E...@wi..." type="cite"> <pre wrap="">Paulo Freitas wrote: </pre> <blockquote type="cite"> <pre wrap="">So my plan is to convert the dc1394video_frame_t structure to the IplImage structure of the OpenCV or maybe to a SDL_image structure, if is possible. Anyone know how to do this? With this conversion should be easy to show the images by the OpenCV or SDL. </pre> </blockquote> <pre wrap=""><!----> Paulo, I have been using libdc1394 with opencv with a fair amount of success recently. The following is a code snippet I have used to take a dc1394video_frame_t* and pass it into an opencv algorithm. IplImage* cv_img = cvCreateImageHeader( cvSize(dc_frame->size[0], dc_frame>size[1]), IPL_DEPTH_8U, 1); cv_img->imageData = (char*)(dc_frame->image); cv_img->imageSize = dc_frame->image_bytes; I am certain that this will not work in all circumstances, in particular if strange things happen with padding bytes, etc. However, for the images I have been dealing with it was certainly sufficient to get the job done. Just be careful in your assumptions about how portable the code will be. Hope this helps, --Jeremy Leibs ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world <a class="moz-txt-link-freetext" href="http://moblin-contest.org/redirect.php?banner_id=100&url=/">http://moblin-contest.org/redirect.php?banner_id=100&url=/</a> _______________________________________________ Mailing list for libdc1394-devel <a class="moz-txt-link-abbreviated" href="mailto:lib...@li...">lib...@li...</a> <a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/libdc1394-devel">https://lists.sourceforge.net/lists/listinfo/libdc1394-devel</a> </pre> </blockquote> Hi Paulo,<br> <br> Else you could try this snipplet - for b/w and color images.<br> <br> Regards,<br> Jean First<br> <br> <br> <tt>dc1394camera_t *cameras[2];<br> dc1394video_frame_t *frames[2];<br> IplImage *original_eye_image=NULL;<br> IplImage *scene_image=NULL;<br> <br> #ifndef YUV2RGB<br> #define YUV2RGB(y, u, v, r, g, b)\<br> r = y + ((v*1436) >> 10);\<br> g = y - ((u*352 + v*731) >> 10);\<br> b = y + ((u*1814) >> 10);\<br> r = r < 0 ? 0 : r;\<br> g = g < 0 ? 0 : g;\<br> b = b < 0 ? 0 : b;\<br> r = r > 255 ? 255 : r;\<br> g = g > 255 ? 255 : g;\<br> b = b > 255 ? 255 : b<br> #endif<br> <br> void uyyvyy2rgb (unsigned char *src, unsigned char *dest, unsigned long long int NumPixels)<br> {<br> register int i = NumPixels + ( NumPixels >> 1 )-1;<br> register int j = NumPixels + ( NumPixels << 1 )-1;<br> register int y0, y1, y2, y3, u, v;<br> register int r, g, b;<br> <br> while (i > 0) {<br> y3 = (unsigned char) src[i--];<br> y2 = (unsigned char) src[i--];<br> v = (unsigned char) src[i--] - 128;<br> y1 = (unsigned char) src[i--];<br> y0 = (unsigned char) src[i--];<br> u = (unsigned char) src[i--] - 128;<br> YUV2RGB (y3, u, v, r, g, b);<br> dest[j--] = r;<br> dest[j--] = g;<br> dest[j--] = b;<br> YUV2RGB (y2, u, v, r, g, b);<br> dest[j--] = r;<br> dest[j--] = g;<br> dest[j--] = b;<br> YUV2RGB (y1, u, v, r, g, b);<br> dest[j--] = r;<br> dest[j--] = g;<br> dest[j--] = b;<br> YUV2RGB (y0, u, v, r, g, b);<br> dest[j--] = r;<br> dest[j--] = g;<br> dest[j--] = b;<br> }<br> }<br> <br> # capture from a b/w and a color camera<br> for (i=0; i<2; i++) {<br> if (dc1394_capture_dequeue(cameras[i], DC1394_CAPTURE_POLICY_POLL, &frames[i])!=DC1394_SUCCESS){<br> dc1394_log_error("Failed to capture from camera %d", i);<br> }<br> }<br> <br> # copy b/w image to IplImage<br> memcpy(eye_image->imageData, (char *)frames[0]->image, 640*480);<br> # copy color image to IplImage<br> uyyvyy2rgb((unsigned char *)frames[1]->image, (unsigned char *)scene_image->imageData, 640*480);</tt><br> <br> </body> </html> |