Camera snap under OS X [closed]
Hi,
I've written the following C program, able to take a snap with the camera. It works well under GNU/Linux, but I got OpenCV with Macports, and it compiles and runs, but doesn't produce any image ... What's the problem with OS X ?
/* required standards includes */
include <stdio.h>
include <stdlib.h>
include <string.h>
include <opencv cv.h="">
include <opencv highgui.h="">
/* * Main program / int main(argc,argv) int argc; char *argv; { int f,g,p; /* Indexes / char name[255]; / string for input image / int width,height; / size of the image / FILE *fp1; / pointers to files for reading and writing */
IplImage *ITmp=NULL;
IplImage *framePtr=NULL;
CvCapture *capture=NULL;
CvSize frameSize;
if(argc!=2)
{
printf("¥nusage : %s image(.ppm)¥n",argv[0]);
printf("Acquire an image file from IEEE1394 camera¥n");
exit(1);
}
while(capture==NULL) capture=cvCreateCameraCapture(CV_CAP_ANY);
printf("Camera OK¥n");
while(framePtr==NULL) framePtr=cvQueryFrame(capture);
printf("Capture OK¥n");
frameSize=cvGetSize(framePtr);
width=frameSize.width;
height=frameSize.height;
ITmp=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,3);
if(ITmp!=NULL)
{
cvConvertImage(framePtr,ITmp,0);
/* form the name of the input image / for(f=0;argv[1][f]!='¥0'&&argv[1][f]!='.';f++); argv[1][f]='¥0'; strcpy(name,argv[1]); strcat(name,".ppm"); fp1=fopen(name,"wb"); if(fp1==NULL) { printf("Can't open %s(.pgm|.ppm) for writing¥n",argv[1]); exit(1); } / write the output image / fprintf(fp1,"P6¥n#acquired image¥n#from %d %d¥n%d %d¥n255¥n",0,0,width,height); for(g=0;g<height;g++) for(f="0;f<width;f++)" for(p="0;p<3;p++)" putc(itmp-="">imageData[3(g*width+f)+2-p],fp1); fclose(fp1); } cvReleaseCapture(&capture); if(ITmp!=NULL) cvReleaseImage(&ITmp); exit(0); }
Can someone help me ?
Thanks,
Best regards,
-- François LE COAT
the c-api, you're trying to use, was deprecated in 2010 already, and is no more usable in current opencv.
please discard all of the above code, and use c++ (cv::Mat, cv::VideoCapture, etc)
really noone cares about problems like yours anymore ...
Well ... It's a matter of programmed obsolescence I don't use C++ language, and I've never used. I'm old, and never learned C++. Are you rejecting people like me ?
you may stick to the past, that's your decision. we just cannot help you with it, then.