Here is a quick function that returns an anaglyph image from two sources.
For the 3D goggles, I use Filter #25 for red and #58 for green.
Depending on which side you load the source images, you need to check for which side is red or green.
// Return an anaglyph image of a right and left channel
// Author : Nicolas Bourré 20100927
IplImage * toAnaglyph(IplImage * imgLeft, IplImage *imgRight)
{
IplImage *iplReturn;IplImage *l_R, * l_G, *l_B;
IplImage *r_R, * r_G, *r_B;iplReturn = cvCreateImage( cvGetSize (imgLeft), 8, 3);l_R = cvCreateImage( cvGetSize (imgLeft), 8, 1);
l_G = cvCreateImage( cvGetSize (imgLeft), 8, 1);
l_B = cvCreateImage( cvGetSize (imgLeft), 8, 1);
r_R = cvCreateImage( cvGetSize (imgLeft), 8, 1);
r_G = cvCreateImage( cvGetSize (imgLeft), 8, 1);
r_B = cvCreateImage( cvGetSize (imgLeft), 8, 1);cvSplit(imgLeft, l_R, l_G, l_B, NULL);
cvSplit(imgRight, r_R, r_G, r_B, NULL);cvMerge(r_R, r_G, l_B, NULL, iplReturn);
cvReleaseImage(&l_R);
cvReleaseImage(&l_G);
cvReleaseImage(&l_B);
cvReleaseImage(&r_R);
cvReleaseImage(&r_G);
cvReleaseImage(&r_B);
return iplReturn;
}
In my case, I needed a quick solution so I didn’t calibrate the cameras for spatial correction.
Enjoy this little snippet!
Laisser un commentaire