Lines Matching full:capture
90 static int icvOpenFile_QT_Movie (CvCapture_QT_Movie * capture, const char * filename);
91 static int icvClose_QT_Movie (CvCapture_QT_Movie * capture);
92 static double icvGetProperty_QT_Movie (CvCapture_QT_Movie * capture, int property_id);
93 static int icvSetProperty_QT_Movie (CvCapture_QT_Movie * capture, int property_id, double value);
94 static int icvGrabFrame_QT_Movie (CvCapture_QT_Movie * capture);
95 static const void * icvRetrieveFrame_QT_Movie (CvCapture_QT_Movie * capture, int);
107 CvCapture_QT_Movie * capture = 0;
111 capture = (CvCapture_QT_Movie *) cvAlloc (sizeof (*capture));
112 memset (capture, 0, sizeof(*capture));
114 if (!icvOpenFile_QT_Movie (capture, filename))
115 cvFree( &capture );
118 return capture;
132 static int icvOpenFile_QT_Movie (CvCapture_QT_Movie * capture, const char * filename)
145 capture->myMovie = 0;
146 capture->myGWorld = nil;
149 capture->next_frame_time = -1;
150 capture->next_frame_number = -1;
151 capture->number_of_frames = -1;
152 capture->movie_start_time = -1;
153 capture->size = cvSize (-1,-1);
169 myErr = NewMovieFromDataRef(& capture->myMovie, newMovieActive | newMovieAsyncOK /* | newMovieIdleImportOK */,
190 GetMovieNextInterestingTime (capture->myMovie, short (nextTimeMediaSample + nextTimeEdgeOK),
197 capture->movie_start_time = theTime;
198 capture->next_frame_time = theTime;
199 capture->next_frame_number = 0;
202 capture->number_of_frames = 0;
205 GetMovieNextInterestingTime (capture->myMovie, short (nextTimeMediaSample),
207 capture->number_of_frames++;
213 GetMovieBox (capture->myMovie, & myRect);
214 capture->size = cvSize (myRect.right - myRect.left, myRect.bottom - myRect.top);
217 myErr = QTNewGWorld (& capture->myGWorld, k32ARGBPixelFormat /* k24BGRPixelFormat geht leider nicht */,
220 SetMovieGWorld (capture->myMovie, capture->myGWorld, nil);
223 capture->image_rgb = cvCreateImageHeader (capture->size, IPL_DEPTH_8U, 4);
226 capture->image_bgr = cvCreateImage (capture->size, IPL_DEPTH_8U, 3);
238 static int icvClose_QT_Movie (CvCapture_QT_Movie * capture)
240 OPENCV_ASSERT (capture, "icvClose_QT_Movie", "'capture' is a NULL-pointer");
243 if (capture->myMovie)
245 cvReleaseImage (& capture->image_bgr);
246 cvReleaseImageHeader (& capture->image_rgb);
247 DisposeGWorld (capture->myGWorld);
248 DisposeMovie (capture->myMovie);
256 * get a capture property
261 static double icvGetProperty_QT_Movie (CvCapture_QT_Movie * capture, int property_id)
263 OPENCV_ASSERT (capture, "icvGetProperty_QT_Movie", "'capture' is a NULL-pointer");
264 OPENCV_ASSERT (capture->myMovie, "icvGetProperty_QT_Movie", "invalid Movie handle");
265 OPENCV_ASSERT (capture->number_of_frames > 0, "icvGetProperty_QT_Movie", "movie has invalid number of frames");
266 OPENCV_ASSERT (capture->movie_start_time >= 0, "icvGetProperty_QT_Movie", "movie has invalid start time");
272 return (capture->next_frame_number);
277 TimeValue position = capture->next_frame_time - capture->movie_start_time;
281 TimeScale timescale = GetMovieTimeScale (capture->myMovie);
286 TimeValue duration = GetMovieDuration (capture->myMovie);
293 return static_cast<double> (capture->size.width);
296 return static_cast<double> (capture->size.height);
300 TimeValue duration = GetMovieDuration (capture->myMovie);
301 TimeScale timescale = GetMovieTimeScale (capture->myMovie);
303 return (capture->number_of_frames / (static_cast<double> (duration) / timescale));
307 return static_cast<double> (capture->number_of_frames);
313 // unhandled or unknown capture property
322 * set a capture property. With movie files, it is only possible to set the
328 static int icvSetProperty_QT_Movie (CvCapture_QT_Movie * capture, int property_id, double value)
330 OPENCV_ASSERT (capture, "icvSetProperty_QT_Movie", "'capture' is a NULL-pointer");
331 OPENCV_ASSERT (capture->myMovie, "icvSetProperty_QT_Movie", "invalid Movie handle");
332 OPENCV_ASSERT (capture->number_of_frames > 0, "icvSetProperty_QT_Movie", "movie has invalid number of frames");
333 OPENCV_ASSERT (capture->movie_start_time >= 0, "icvSetProperty_QT_Movie", "movie has invalid start time");
351 TimeScale timescale = GetMovieTimeScale (capture->myMovie);
352 destination = static_cast<TimeValue> (value / 1000.0 * timescale + capture->movie_start_time);
356 TimeValue duration = GetMovieDuration (capture->myMovie);
357 destination = static_cast<TimeValue> (value * duration + capture->movie_start_time);
361 if (capture->next_frame_time == destination)
365 if (capture->next_frame_time < destination)
367 while (capture->next_frame_time < destination)
369 capture->next_frame_number++;
370 GetMovieNextInterestingTime (capture->myMovie, nextTimeStep, 1, & myType, capture->next_frame_time,
371 1, & capture->next_frame_time, NULL);
382 while (capture->next_frame_time > destination)
384 capture->next_frame_number--;
385 GetMovieNextInterestingTime (capture->myMovie, nextTimeStep, 1, & myType, capture->next_frame_time,
386 -1, & capture->next_frame_time, NULL);
401 short direction = (destination > capture->next_frame_number) ? 1 : -1;
405 while (destination != capture->next_frame_number)
407 capture->next_frame_number += direction;
408 GetMovieNextInterestingTime (capturecapture->next_frame_time,
409 direction, & capture->next_frame_time, NULL);
421 // unhandled or unknown capture property
438 static int icvGrabFrame_QT_Movie (CvCapture_QT_Movie * capture)
440 OPENCV_ASSERT (capture, "icvGrabFrame_QT_Movie", "'capture' is a NULL-pointer");
441 OPENCV_ASSERT (capture->myMovie, "icvGrabFrame_QT_Movie", "invalid Movie handle");
449 SetMovieTimeValue (capture->myMovie, capture->next_frame_time);
458 myCurrTime = GetMovieTime (capture->myMovie, NULL);
461 capture->next_frame_number++;
462 GetMovieNextInterestingTime (capture->myMovie, nextTimeStep, 1, & myType, myCurrTime, 1, & capture->next_frame_time, NULL);
481 static const void * icvRetrieveFrame_QT_Movie (CvCapture_QT_Movie * capture, int)
483 OPENCV_ASSERT (capture, "icvRetrieveFrame_QT_Movie", "'capture' is a NULL-pointer");
484 OPENCV_ASSERT (capture->myMovie, "icvRetrieveFrame_QT_Movie", "invalid Movie handle");
485 OPENCV_ASSERT (capture->image_rgb, "icvRetrieveFrame_QT_Movie", "invalid source image");
486 OPENCV_ASSERT (capture->image_bgr, "icvRetrieveFrame_QT_Movie", "invalid destination image");
494 UpdateMovie (capture->myMovie);
503 MoviesTask (capture->myMovie, 0L);
515 myPixMapHandle = GetGWorldPixMap (capture->myGWorld);
517 cvSetData (capture->image_rgb, GetPixBaseAddr (myPixMapHandle) + 1, GetPixRowBytes (myPixMapHandle));
520 cvCvtColor (capture->image_rgb, capture->image_bgr, CV_RGBA2BGR);
526 return capture->image_bgr;
572 static int icvOpenCamera_QT (CvCapture_QT_Cam * capture, const int index);
573 static int icvClose_QT_Cam (CvCapture_QT_Cam * capture);
574 static double icvGetProperty_QT_Cam (CvCapture_QT_Cam * capture, int property_id);
575 static int icvSetProperty_QT_Cam (CvCapture_QT_Cam * capture, int property_id, double value);
576 static int icvGrabFrame_QT_Cam (CvCapture_QT_Cam * capture);
577 static const void * icvRetrieveFrame_QT_Cam (CvCapture_QT_Cam * capture, int);
594 CvCapture_QT_Cam * capture = 0;
598 capture = (CvCapture_QT_Cam *) cvAlloc (sizeof (*capture));
599 memset (capture, 0, sizeof(*capture));
601 if (!icvOpenCamera_QT (capture, index))
602 cvFree (&capture);
605 return capture;
608 /// capture properties currently unimplemented for QuickTime camera interface
609 static double icvGetProperty_QT_Cam (CvCapture_QT_Cam * capture, int property_id)
615 /// capture properties currently unimplemented for QuickTime camera interface
616 static int icvSetProperty_QT_Cam (CvCapture_QT_Cam * capture, int property_id, double value)
632 static int icvOpenCamera_QT (CvCapture_QT_Cam * capture, const int index)
634 OPENCV_ASSERT (capture, "icvOpenCamera_QT", "'capture' is a NULL-pointer");
673 capture->grabber = OpenComponent (component);
674 if (capture->grabber)
676 result = VDGetNumberOfInputs (capture->grabber, & capture->channel);
682 printf (" Number of inputs: %d\n", (int) capture->channel + 1);
686 number_of_inputs += capture->channel + 1;
693 capture->channel = index - number_of_inputs + capture->channel + 1;
694 OPENCV_ASSERT (capture->channel >= 0, "icvOpenCamera_QT", "negative channel number");
701 result = VDGetInputName (capture->grabber, capture->channel, nameBuffer);
704 printf (" Choosing input %d - %s\n", (int) capture->channel, name);
713 CloseComponent (capture->grabber);
731 result = VDSetInput (capture->grabber, capture->channel);
735 result = VDGetActiveSrcRect (capture->grabber, capture->channel, & myRect);
738 capture->size = cvSize (myRect.right - myRect.left, myRect.bottom - myRect.top);
742 result = QTNewGWorld (& capture->myGWorld, k32ARGBPixelFormat, & myRect, nil, nil, 0);
746 capture->pixmap = GetGWorldPixMap (capture->myGWorld);
751 result = VDSetDigitizerRect (capture->grabber, & myRect);
755 result = VDSetPlayThruDestination (capture->grabber, capture->pixmap, & myRect, nil, nil);
760 result = VDGetPlayThruDestination (capture->grabber, & capture->pixmap, nil, nil, nil);
763 OPENCV_ASSERT (capture->pixmap != nil, "icvOpenCamera_QT", "empty set video destination");
766 GetPixBounds (capture->pixmap, & myRect);
767 capture->size = cvSize (myRect.right - myRect.left, myRect.bottom - myRect.top);
770 capture->image_rgb = cvCreateImageHeader (capture->size, IPL_DEPTH_8U, 4);
771 OPENCV_ASSERT (capture->image_rgb, "icvOpenCamera_QT", "couldnt create image header");
774 capture->image_bgr = cvCreateImage (capture->size, IPL_DEPTH_8U, 3);
775 OPENCV_ASSERT (capture->image_bgr, "icvOpenCamera_QT", "couldnt create image");
778 result = VDCaptureStateChanging (capture->grabber, vdFlagCaptureIsForRecord | vdFlagCaptureStarting | vdFlagCaptureLowLatency);
779 OPENCV_ASSERT (result == noErr, "icvOpenCamera_QT", "couldnt set capture state");
786 static int icvClose_QT_Cam (CvCapture_QT_Cam * capture)
788 OPENCV_ASSERT (capture, "icvClose_QT_Cam", "'capture' is a NULL-pointer");
793 result = VDCaptureStateChanging (capture->grabber, vdFlagCaptureStopping);
794 OPENCV_ASSERT (result == noErr, "icvOpenCamera_QT", "couldnt set capture state");
797 cvReleaseImage (& capture->image_bgr);
798 cvReleaseImageHeader (& capture->image_rgb);
799 DisposeGWorld (capture->myGWorld);
800 CloseComponent (capture->grabber);
806 static int icvGrabFrame_QT_Cam (CvCapture_QT_Cam * capture)
808 OPENCV_ASSERT (capture, "icvGrabFrame_QT_Cam", "'capture' is a NULL-pointer");
809 OPENCV_ASSERT (capture->grabber, "icvGrabFrame_QT_Cam", "'grabber' is a NULL-pointer");
814 result = VDGrabOneFrame (capture->grabber);
825 static const void * icvRetrieveFrame_QT_Cam (CvCapture_QT_Cam * capture, int)
827 OPENCV_ASSERT (capture, "icvRetrieveFrame_QT_Cam", "'capture' is a NULL-pointer");
835 //myPixMapHandle = GetGWorldPixMap (capture->myGWorld);
836 myPixMapHandle = capture->pixmap;
838 cvSetData (capture->image_rgb, GetPixBaseAddr (myPixMapHandle) + 1, GetPixRowBytes (myPixMapHandle));
841 cvCvtColor (capture->image_rgb, capture->image_bgr, CV_RGBA2BGR);
847 return capture->image_bgr;
855 CvCapture_QT_Cam * capture = (CvCapture_QT_Cam *) refCon;
861 OPENCV_ASSERT (capture, "icvDataProc_QT_Cam", "'capture' is a NULL-pointer");
862 OPENCV_ASSERT (capture->gworld, "icvDataProc_QT_Cam", "'gworld' is a NULL-pointer");
866 if (capture->sequence == 0)
883 RectMatrix(&scaleMatrix,&sourceRect,&capture->bounds);
885 err = DecompressSequenceBegin (&capture->sequence, description, capture->gworld, 0,&capture->bounds,&scaleMatrix, srcCopy, NULL, 0, codecNormalQuality, bestSpeedCodec);
893 err = DecompressSequenceFrameS (capture->sequence, raw_data, len, 0, &ignore, nil);
902 if (capture->got_frame)
907 capture->got_frame = true;
912 static int icvOpenCamera_QT (CvCapture_QT_Cam * capture, const int index)
914 OPENCV_ASSERT (capture, "icvOpenCamera_QT", "'capture' is a NULL-pointer");
921 capture->grabber = OpenDefaultComponent (SeqGrabComponentType, 0);
922 OPENCV_ASSERT (capture->grabber, "icvOpenCamera_QT", "couldnt create image");
925 result = SGInitialize (capture->grabber);
927 result = SGSetDataRef (capture->grabber, 0, 0, seqGrabDontMakeMovie);
931 result = SGNewChannel (capture->grabber, VideoMediaType, & (capture->channel));
936 result = SGGetChannelDeviceList (capture->channel, 0, & device_list);
945 result = SGSetChannelDevice (capture->channel, device.name);
952 result = SGDisposeDeviceList (capture->grabber, device_list);
958 result = SGGetSrcVideoBounds (capture->channel, & (capture->bounds));
962 result = QTNewGWorld (& (capture->gworld), k32ARGBPixelFormat, & (capture->bounds), 0, 0, 0);
963 result = SGSetGWorld (capture->grabber, capture->gworld, 0);
965 result = SGSetChannelBounds (capture->channel, & (capture->bounds));
967 result = SGSetChannelUsage (capture->channel, seqGrabRecord);
971 result = SGStartRecord (capture->grabber);
976 result = SGGetChannelSampleDescription(capture->channel, (Handle)imageDesc);
978 capture->bounds.right = (**imageDesc).width;
979 capture->bounds.bottom = (**imageDesc).height;
983 result = SGStop (capture->grabber);
988 result = QTNewGWorld( &tmpgworld, k32ARGBPixelFormat, &(capture->bounds), 0, 0, 0);
990 result = SGSetGWorld( capture->grabber, tmpgworld, 0);
992 DisposeGWorld( capture->gworld );
993 capture->gworld = tmpgworld;
995 result = SGSetChannelBounds (capture->channel, & (capture->bounds));
999 capture->size = cvSize (capture->bounds.right - capture->bounds.left, capture->bounds.bottom - capture->bounds.top);
1005 capture->image_rgb = cvCreateImageHeader (capture->size, IPL_DEPTH_8U, 4);
1006 OPENCV_ASSERT (capture->image_rgb, "icvOpenCamera_QT", "couldnt create image header");
1007 pixmap = GetGWorldPixMap (capture->gworld);
1010 cvSetData (capture->image_rgb, GetPixBaseAddr (pixmap) + 1, GetPixRowBytes (pixmap));
1013 capture->image_bgr = cvCreateImage (capture->size, IPL_DEPTH_8U, 3);
1014 OPENCV_ASSERT (capture->image_bgr, "icvOpenCamera_QT", "couldnt create image");
1018 result = SGSetDataProc (capture->grabber, NewSGDataUPP (icvDataProc_QT_Cam), (long) capture);
1022 result = SGStartRecord (capture->grabber);
1029 static int icvClose_QT_Cam (CvCapture_QT_Cam * capture)
1031 OPENCV_ASSERT (capture, "icvClose_QT_Cam", "'capture' is a NULL-pointer");
1037 result = SGStop (capture->grabber);
1041 result = CloseComponent (capture->grabber);
1045 CDSequenceEnd (capture->sequence);
1048 cvReleaseImage (& capture->image_bgr);
1049 cvReleaseImageHeader (& capture->image_rgb);
1050 DisposeGWorld (capture->gworld);
1056 static int icvGrabFrame_QT_Cam (CvCapture_QT_Cam * capture)
1058 OPENCV_ASSERT (capture, "icvGrabFrame_QT_Cam", "'capture' is a NULL-pointer");
1059 OPENCV_ASSERT (capture->grabber, "icvGrabFrame_QT_Cam", "'grabber' is a NULL-pointer");
1065 result = SGIdle (capture->grabber);
1076 static const void * icvRetrieveFrame_QT_Cam (CvCapture_QT_Cam * capture, int)
1078 OPENCV_ASSERT (capture, "icvRetrieveFrame_QT_Cam", "'capture' is a NULL-pointer");
1079 OPENCV_ASSERT (capture->image_rgb, "icvRetrieveFrame_QT_Cam", "invalid source image");
1080 OPENCV_ASSERT (capture->image_bgr, "icvRetrieveFrame_QT_Cam", "invalid destination image");
1086 while (! capture->got_frame)
1088 myErr = SGIdle (capture->grabber);
1097 cvCvtColor (capture->image_rgb, capture->image_bgr, CV_RGBA2BGR);
1100 capture->got_frame = false;
1103 return capture->image_bgr;
1448 virtual int getCaptureDomain() { return CV_CAP_QT; } // Return the type of the capture object: CV_CAP_VFW, etc...
1492 CvCapture_QT_Movie_CPP* capture = new CvCapture_QT_Movie_CPP;
1494 if( capture->open( filename ))
1495 return capture;
1497 delete capture;
1517 virtual int getCaptureDomain() { return CV_CAP_QT; } // Return the type of the capture object: CV_CAP_VFW, etc...
1561 CvCapture_QT_Cam_CPP* capture = new CvCapture_QT_Cam_CPP;
1563 if( capture->open( index ))
1564 return capture;
1566 delete capture;