Camera snap under OS X [closed]

asked 2018-12-28 07:17:39 -0600

archimedium gravatar image

updated 2018-12-28 07:31:10 -0600

berak gravatar image

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&lt;width;f++)" for(p="0;p&lt;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

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by berak
close date 2018-12-28 07:28:02.039815

Comments

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 ...

berak gravatar imageberak ( 2018-12-28 07:27:48 -0600 )edit

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 ?

archimedium gravatar imagearchimedium ( 2018-12-28 07:39:05 -0600 )edit

you may stick to the past, that's your decision. we just cannot help you with it, then.

berak gravatar imageberak ( 2018-12-28 07:52:42 -0600 )edit