示例#1
0
/**
 * CHECKS IF THE STREAM IN * capture IS SEEKABLE.
**/
static void icvCheckSeekAVI_XINE( CvCaptureAVI_XINE * capture )
{
    OPENCV_ASSERT ( capture,                        "icvCheckSeekAVI_XINE( CvCaptureAVI_XINE* )", "illegal capture");
    OPENCV_ASSERT ( capture->stream,
                        "icvCheckSeekAVI_XINE( CvCaptureAVI_XINE* )", "illegal capture->stream");
    OPENCV_ASSERT ( capture->vo_port,
                        "icvCheckSeekAVI_XINE( CvCaptureAVI_XINE* )", "illegal capture->vo_port");

#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvCheckSeekAVI_XINE ... start\n" );
#endif

    // temp. frame for testing.
    xine_video_frame_t tmp;
    // try to seek to a future frame...
    xine_play( capture->stream, 0, 300 ); /* 300msec */
    // try to receive the frame...
    xine_get_next_video_frame( capture->vo_port, &tmp );
    // if the framenumber is still 0, we can't use the xine seek functionality
    capture->seekable = ( tmp.frame_number != 0 );
    // reset stream
    xine_play( capture->stream, 0, 0 );
    // release xine_frame
    xine_free_video_frame( capture->vo_port, &tmp );

#ifndef NDEBUG
    if ( capture->seekable )
        fprintf( stderr, "(DEBUG) icvCheckSeekAVI_XINE: Input is seekable, using XINE seek implementation.\n" );
    else
        fprintf( stderr, "(DEBUG) icvCheckSeekAVI_XINE: Input is NOT seekable, using fallback function.\n" );

    fprintf( stderr, "(DEBUG) icvCheckSeekAVI_XINE ... end\n" );
#endif
}
示例#2
0
void Camera::setDistortionCoeffs(Mat distortCoeffMtx)
{
	OPENCV_ASSERT(distortCoeffMtx.rows==4 || distortCoeffMtx.rows==5 || distortCoeffMtx.rows==8,"Camera.setDistortionCoeffs","Camera distortion coefficient matrix does not have 4,5 or 8 rows.");
	OPENCV_ASSERT(distortCoeffMtx.cols==1,"Camera.setDistortionCoeffs","Camera distortion coefficient matrix does not have 1 column.");
	OPENCV_ASSERT(distortCoeffMtx.type() == CV_64F,"Camera.setDistortionCoeffs","Camera distortion coefficient matrix does not have type CV_64F.");
	
	distortionCoeffs = distortCoeffMtx;
}
示例#3
0
static int icvSeekRatioAVI_XINE( CvCaptureAVI_XINE* capture, double ratio )
{
#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvSeekRatioAVI_XINE ... start\n" );
#endif

    OPENCV_ASSERT ( capture,
                        "icvSeekRatioAVI_XINE( CvCaptureAVI_XINE *, double )", "illegal capture");
    OPENCV_ASSERT ( capture->stream,
                        "icvSeekRatioAVI_XINE( CvCaptureAVI_XINE *, double )", "illegal capture->stream");
    OPENCV_ASSERT ( capture->vo_port,
                        "icvSeekRatioAVI_XINE( CvCaptureAVI_XINE *, double )", "illegal capture->vo_port");

// not needed tnx to asserts...
    // we need a valid capture context and it's stream to seek through
//	if ( !capture || !capture->stream ) return 0;

    /// ratio must be [0..1]
    if ( ratio > 1 || ratio < 0 ) return 0;

    if ( capture->seekable )
    {
    // TODO: FIX IT, DOESN'T WORK PROPERLY, YET...!
        int pos_t, pos_l, length;
        xine_get_pos_length( capture->stream, &pos_l, &pos_t, &length );
        fprintf( stderr, "ratio on GetProperty(): %d\n", pos_l );

        /// use xinelib's seek functionality
        if ( xine_play( capture->stream, (int)(ratio*(float)length), 0 ) )
        {
            capture->frame_number = ( int ) ( ratio*length / capture->frame_duration );
        }
        else
        {
#ifndef NDEBUG
            fprintf( stderr, "(DEBUG) icvSeekRatioAVI_XINE ... failed!\n" );
#endif
            return 0;
        }
    }
    else
    {
        /// TODO: fill it !
        fprintf( stderr, "icvSeekRatioAVI_XINE(): Seek not supported by stream !\n" );
        fprintf( stderr, "icvSeekRatioAVI_XINE(): (seek in stream with NO seek support NOT implemented...yet!)\n" );
#ifndef NDEBUG
        fprintf( stderr, "(DEBUG) icvSeekRatioAVI_XINE ... failed!\n" );
#endif
        return 0;
    }

#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvSeekRatioAVI_XINE ... end!\n" );
#endif
    return 1;
}
示例#4
0
/** Ray: cam -> world */
Ray Camera::rayCam2World(Ray rCam)
{
	OPENCV_ASSERT(rCam.cameraID == cameraID,"Camera.rayCam2World","Ray is given in some other camera's coordinate system. Cannot transform...");
	OPENCV_ASSERT(isTSet,"Camera.rayCam2World","Using unknown camera transformation!");

	// Create ray
	Ray rWorld = rCam;
	rWorld.A = T * rCam.A;
	rWorld.B = T * rCam.B;
	rWorld.cameraID = CAMID_WORLD;
	return rWorld;
}
示例#5
0
static int icvSeekFrameAVI_XINE( CvCaptureAVI_XINE* capture, int f )
{
#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ... start\n" );
#endif

    OPENCV_ASSERT ( capture,
                        "icvSeekFrameAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture");
    OPENCV_ASSERT ( capture->stream,
                        "icvSeekFrameAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->stream");
    OPENCV_ASSERT ( capture->vo_port,
                        "icvSeekFrameAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->vo_port");

// not needed tnx to asserts...
    // we need a valid capture context and it's stream to seek through
//	if ( !capture || !capture->stream ) return 0;

    if ( capture->seekable )
    {

        /// use xinelib's seek functionality
        int new_time = ( int ) ( ( f + 1 ) * ( float ) capture->frame_duration );

#ifndef NDEBUG
        fprintf( stderr, "(DEBUG) calling xine_play()" );
#endif
        if ( xine_play( capture->stream, 0, new_time ) )
        {
#ifndef NDEBUG
            fprintf( stderr, "ok\n" );
            fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ... end\n" );
#endif
            capture->frame_number = f;
            return 1;
        }
        else
        {
#ifndef NDEBUG
            fprintf( stderr, "failed\n" );
            fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ... failed\n" );
#endif
            return 0;
        }
    }
    else
    {
#ifndef NDEBUG
        fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ... end\n" );
#endif
        return icvOldSeekFrameAVI_XINE( capture, f );
    }
}
示例#6
0
// Setters
void Camera::setCameraMatrix(Mat camMtx)
{
	OPENCV_ASSERT(camMtx.rows==3,"Camera.setCameraMatrix","Camera matrix does not have 8 rows.");
	OPENCV_ASSERT(camMtx.cols==3,"Camera.setCameraMatrix","Camera matrix does not have 1 column.");
	OPENCV_ASSERT(camMtx.type() == CV_64F,"Camera.setCameraMatrix","Camera matrix does not have type CV_64F.");

	cameraMatrix = camMtx;
	// Extract camera parameters for faster access
	fx = (float)camMtx.at<double>(0,0);
	fy = (float)camMtx.at<double>(1,1);
	cx = (float)camMtx.at<double>(0,2);
	cy = (float)camMtx.at<double>(1,2);
}
示例#7
0
static int icvSeekTimeAVI_XINE( CvCaptureAVI_XINE* capture, int t )
{
#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvSeekTimeAVI_XINE ... start\n" );
#endif

    OPENCV_ASSERT ( capture,
                        "icvSeekTimeAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture");
    OPENCV_ASSERT ( capture->stream,
                        "icvSeekTimeAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->stream");
    OPENCV_ASSERT ( capture->vo_port,
                        "icvSeekTimeAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->vo_port");

#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvSeekTimeAVI_XINE ... start\n" );
#endif

// not needed tnx to asserts...
    // we need a valid capture context and it's stream to seek through
//	if ( !capture || !capture->stream ) return 0;

    if ( capture->seekable )
    {
        /// use xinelib's seek functionality
        if ( xine_play( capture->stream, 0, t ) )
        {
            capture->frame_number = ( int ) ( ( float ) t * capture->frame_rate / 1000 );
#ifndef NDEBUG
            fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ... end\n" );
#endif
            return 1;
        }
        else
        {
#ifndef NDEBUG
            fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ... failed!\n" );
#endif
            return 0;
        }
    }
    else
    {
        int new_frame = ( int ) ( ( float ) t * capture->frame_rate / 1000 );
#ifndef NDEBUG
        fprintf( stderr, "(DEBUG) icvSeekFrameAVI_XINE ....end\n" );
#endif
        return icvOldSeekFrameAVI_XINE( capture, new_frame );
    }
}
示例#8
0
bool Camera::calculateExtrinsicParams(vector<Point3f> objectPoints, vector<Point2f> imagePoints)
{
	OPENCV_ASSERT(isCalibrated,"Camera.calculateExtrinsicParams","Cannot calculate extrinsic parameters before camera calibration!");
	Mat rvec, tvec;
	Mat rotMtx;
	bool solverResult = solvePnP(
		Mat(objectPoints), Mat(imagePoints),	// Input correspondences
		cameraMatrix, distortionCoeffs,	// Intrinsic camera parameters (have to be already available)
		rvec, tvec);

	if (solverResult)
	{
		// Create this->T from rvec and tvec
		Rodrigues(rvec, rotMtx);
		Matx44f T_inv = Matx44f(
			(float)rotMtx.at<double>(0,0), (float)rotMtx.at<double>(0,1), (float)rotMtx.at<double>(0,2), (float)tvec.at<double>(0,0),
			(float)rotMtx.at<double>(1,0), (float)rotMtx.at<double>(1,1), (float)rotMtx.at<double>(1,2), (float)tvec.at<double>(1,0),
			(float)rotMtx.at<double>(2,0), (float)rotMtx.at<double>(2,1), (float)rotMtx.at<double>(2,2), (float)tvec.at<double>(2,0),
			0.0F, 0.0F, 0.0F, 1.0F
			);
		T = T_inv.inv();
		isTSet=true;
	}

	return solverResult;
}
示例#9
0
int CV_ThreshHistTest::prepare_test_case( int test_case_idx )
{
    int code = CV_BaseHistTest::prepare_test_case( test_case_idx );

    if( code > 0 )
    {
        CvRNG* rng = ts->get_rng();
        threshold = cvTsRandReal(rng)*gen_hist_max_val;

        if( hist_type == CV_HIST_ARRAY )
        {
            orig_nz_count = total_size;
            
            values = cvCreateMat( 1, total_size, CV_32F );
            memcpy( values->data.fl, cvPtr1D( hist[0]->bins, 0 ), total_size*sizeof(float) );
        }
        else
        {
            CvSparseMat* sparse = (CvSparseMat*)hist[0]->bins;
            CvSparseMatIterator iterator;
            CvSparseNode* node;
            int i, k;

            orig_nz_count = sparse->heap->active_count;

            values = cvCreateMat( 1, orig_nz_count+1, CV_32F );
            indices = cvCreateMat( 1, (orig_nz_count+1)*cdims, CV_32S );

            for( node = cvInitSparseMatIterator( sparse, &iterator ), i = 0;
                 node != 0; node = cvGetNextSparseNode( &iterator ), i++ )
            {
                 const int* idx = CV_NODE_IDX(sparse,node);
                     
                 OPENCV_ASSERT( i < orig_nz_count, "CV_ThreshHistTest::prepare_test_case", "Buffer overflow" );

                 values->data.fl[i] = *(float*)CV_NODE_VAL(sparse,node);
                 for( k = 0; k < cdims; k++ )
                     indices->data.i[i*cdims + k] = idx[k];
            }

            OPENCV_ASSERT( i == orig_nz_count, "Unmatched buffer size",
                "CV_ThreshHistTest::prepare_test_case" );
        }
    }

    return code;
}
示例#10
0
/** Ray: cam -> image
	Warning: works only for rays created by the same, stationary camera! */
Point2f Camera::rayOrigCam2Img(Ray rOrigCam)
{
	OPENCV_ASSERT(rOrigCam.originalCameraID == cameraID,"Camera.rayOrigCam2Img","This is not the original camera. Use rayCam2Img() instead!");
	// TODO: should be able to throw error in release mode as well!
	Point2f pImg;
	pImg = rOrigCam.originalImageLocation;
	return pImg;
}
示例#11
0
static int icvSetPropertyAVI_XINE( CvCaptureAVI_XINE* capture,
                                   int property_id, double value )
{
#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvSetPropertyAVI_XINE ... start\n" );
#endif

    OPENCV_ASSERT ( capture,
                        "icvSetPropertyAVI_XINE( CvCaptureAVI_XINE *, int, double )", "illegal capture");
    OPENCV_ASSERT ( capture->stream,
                        "icvGetPropericvSetPropertyAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->stream");
    OPENCV_ASSERT ( capture->vo_port,
                        "icvSetPropertyAVI_XINE( CvCaptureAVI_XINE *, int, double )", "illegal capture->vo_port");

// not needed tnx to asserts...
    // we need a valid capture context and it's stream to seek through
//	if ( !capture || !capture->stream || !capture->bgr_frame || !capture->xine || !capture->vo_port ) return 0

#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvSetPropertyAVI_XINE: seeking to value %f ... ", value );
#endif

    switch ( property_id )
    {
            /// set (seek to) position in msec
            case CV_CAP_PROP_POS_MSEC:
            return icvSeekTimeAVI_XINE( capture, ( int ) value );

            /// set (seek to) frame number
            case CV_CAP_PROP_POS_FRAMES:
            return icvSeekFrameAVI_XINE( capture, ( int ) value );

            /// set (seek to) position ratio in the range [0..1] depending on
            /// the total length of the stream and the actual position
            case CV_CAP_PROP_POS_AVI_RATIO:
            return icvSeekRatioAVI_XINE( capture, value );

            default:
#ifndef NDEBUG
            fprintf( stderr, "(DEBUG) icvSetPropertyAVI_XINE ... failed!\n" );
#endif

            return 0;
    }
}
示例#12
0
/** Ray: world -> cam */
Ray Camera::rayWorld2Cam(Ray rWorld)
{
	OPENCV_ASSERT(isTSet,"Camera.rayWorld2Cam","Using unknown camera transformation!");
	// Create ray
	Ray rCam = rWorld;
	rCam.A = T.inv() * rWorld.A;
	rCam.B = T.inv() * rWorld.B;
	rCam.cameraID = cameraID;
	return rCam;
}
示例#13
0
/** Ray: cam -> image */
Ray2D Camera::rayCam2Img(Ray rCam)
{
	OPENCV_ASSERT(rCam.originalCameraID != cameraID,"Camera.rayCam2Img","Reprojection of ray into original camera is not supported. Use rayOrigCam2Img() instead!");

	Ray2D rImg;
	rImg.cameraID = cameraID;
	rImg.A = pointCam2Img(rCam.A);
	rImg.B = pointCam2Img(rCam.B);

	return rImg;
}
示例#14
0
static int icvGrabFrameAVI_XINE( CvCaptureAVI_XINE* capture )
{
#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvGrabFrameAVI_XINE ... start\n" );
#endif

    OPENCV_ASSERT ( capture,
                        "icvGrabFrameAVI_XINE( CvCaptureAVI_XINE * )", "illegal capture");
    OPENCV_ASSERT ( capture->vo_port,
                        "icvGrabFrameAVI_XINE( CvCaptureAVI_XINE * )", "illegal capture->vo_port");

    int res = xine_get_next_video_frame( capture->vo_port, &capture->xine_frame );

    /* always keep internal framenumber updated !!! */
    if ( res ) capture->frame_number++;

#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvGrabFrameAVI_XINE ... end\n" );
#endif
    return res;
}
示例#15
0
/** Point: cam -> image */
Point2f Camera::pointCam2Img(Matx41f pCam)
{
	// Get 3D coordinates (from homogeneous coordinates)
	float x = pCam.val[0] / pCam.val[3];
	float y = pCam.val[1] / pCam.val[3];
	float z = pCam.val[2] / pCam.val[3];

	OPENCV_ASSERT(z != 0,"Camera.pointCam2Img","z==0, unable to perform perspectivic projection");

	// Camera transformation
	Point2f pImg;
	pImg.x = fx * ( x / z ) + cx;
	pImg.y = fy * ( y / z ) + cy;

	return pImg;
}
示例#16
0
static CvCaptureAVI_XINE* icvCaptureFromFile_XINE( const char* filename )
{
    // construct capture struct
    CvCaptureAVI_XINE * capture = ( CvCaptureAVI_XINE* ) cvAlloc ( sizeof ( CvCaptureAVI_XINE ) );
    memset( capture, 0, sizeof ( CvCaptureAVI_XINE ) );

    // initialize XINE
    if ( !icvOpenAVI_XINE( capture, filename ) )
        return 0;

    OPENCV_ASSERT ( capture,
                        "cvCaptureFromFile_XINE( const char * )", "couldn't create capture");

    return capture;

}
示例#17
0
bool Camera::loadCalibrationData(const char *filename)
{
	FileStorage fs(filename, FileStorage::READ);
    if (!fs.isOpened())
    {
		OPENCV_ASSERT(false,"Camera.loadCalibrationData","Cannot load calibration data!");
        return false;
    }
    Mat camMat = Mat::eye(3, 3, CV_64F);
    Mat dCoeffs = Mat::zeros(8, 1, CV_64F);
    fs["Camera_Matrix"] >> camMat;
	fs["Distortion_Coefficients"] >> dCoeffs;
	setCameraMatrix(camMat);
	setDistortionCoeffs(dCoeffs);
	fs.release(); 
	isCalibrated=true;
	return true;
}
示例#18
0
static CvCapture_GStreamer * icvCreateCapture_GStreamer(int type, const char *filename)
{
	CvCapture_GStreamer *capture = 0;
	CV_FUNCNAME("cvCaptureFromCAM_GStreamer");

	__BEGIN__;

//	teststreamer(filename);

//	return 0;

	if(!isInited) {
		printf("gst_init\n");
		gst_init (NULL, NULL);

// according to the documentation this is the way to register a plugin now
// unfortunately, it has not propagated into my distribution yet...
// 		gst_plugin_register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR,
// 			"opencv-appsink", "Element application sink",
// 			"0.1", appsink_plugin_init, "LGPL", "highgui", "opencv",
// 			"http://opencvlibrary.sourceforge.net/");

		isInited = true;
	}

	const char *sourcetypes[] = {"dv1394src", "v4lsrc", "v4l2src", "filesrc"};
//	printf("entered capturecreator %s\n", sourcetypes[type]);

	GstElement *source = gst_element_factory_make(sourcetypes[type], NULL);
	if(!source)
		return 0;

	if(type == CV_CAP_GSTREAMER_FILE)
		g_object_set(G_OBJECT(source), "location", filename, NULL);

	GstElement *colour = gst_element_factory_make("ffmpegcolorspace", NULL);

	GstElement *sink = gst_element_factory_make("opencv-appsink", NULL);
	GstCaps *caps = gst_caps_new_simple("video/x-raw-rgb", NULL);
	gst_app_sink_set_caps(GST_APP_SINK(sink), caps);
//	gst_caps_unref(caps);
	gst_base_sink_set_sync(GST_BASE_SINK(sink), false);
//	g_signal_connect(sink, "new-buffer", G_CALLBACK(newbuffer), NULL);

	GstElement *decodebin = gst_element_factory_make("decodebin", NULL);
	g_signal_connect(decodebin, "new-decoded-pad", G_CALLBACK(icvNewPad), colour);

	GstElement *pipeline = gst_pipeline_new (NULL);

	gst_bin_add_many(GST_BIN(pipeline), source, decodebin, colour, sink, NULL);

//	printf("added many\n");

	switch(type) {
	case CV_CAP_GSTREAMER_V4L2: // default to 640x480, 30 fps
		caps = gst_caps_new_simple("video/x-raw-rgb",
					   "width", G_TYPE_INT, 640,
					   "height", G_TYPE_INT, 480,
					   "framerate", GST_TYPE_FRACTION, 30, 1,
					   NULL);
		if(!gst_element_link_filtered(source, decodebin, caps)) {
			CV_ERROR(CV_StsError, "GStreamer: cannot link v4l2src -> decodebin\n");
			gst_object_unref(pipeline);
			return 0;
		}
		gst_caps_unref(caps);
		break;
	case CV_CAP_GSTREAMER_V4L:
	case CV_CAP_GSTREAMER_1394:
	case CV_CAP_GSTREAMER_FILE:
		if(!gst_element_link(source, decodebin)) {
			CV_ERROR(CV_StsError, "GStreamer: cannot link filesrc -> decodebin\n");
			gst_object_unref(pipeline);
			return 0;
		}
		break;
	}

	if(!gst_element_link(colour, sink)) {
		CV_ERROR(CV_StsError, "GStreamer: cannot link colour -> sink\n");
		gst_object_unref(pipeline);
		return 0;
	}

//	printf("linked, pausing\n");

	if(gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PAUSED) ==
	   GST_STATE_CHANGE_FAILURE) {
		CV_WARN("GStreamer: unable to set pipeline to paused\n");
//		icvHandleMessage(capture);
//		cvReleaseCapture((CvCapture **)(void *)&capture);
		gst_object_unref(pipeline);
		return 0;
	}

//	printf("state now paused\n");

	// construct capture struct
	capture = (CvCapture_GStreamer *)cvAlloc(sizeof(CvCapture_GStreamer));
	memset(capture, 0, sizeof(CvCapture_GStreamer));
	capture->type = type;
	capture->pipeline = pipeline;
	capture->source = source;
	capture->decodebin = decodebin;
	capture->colour = colour;
	capture->appsink = sink;

	icvHandleMessage(capture);

	OPENCV_ASSERT(capture,
                      "cvCaptureFromFile_GStreamer( const char * )", "couldn't create capture");

//	GstClock *clock = gst_pipeline_get_clock(GST_PIPELINE(pipeline));
//	printf("clock %s\n", gst_object_get_name(GST_OBJECT(clock)));

	__END__;

	return capture;
}
示例#19
0
/** Point: world -> cam */
Matx41f Camera::pointWorld2Cam(Matx41f pWorld)
{
	OPENCV_ASSERT(isTSet,"Camera.pointWorld2Cam","Using unknown camera transformation!");
	Matx41f pCam = T.inv() * pWorld;
	return pCam;
}
示例#20
0
/** Point: cam -> world */
Matx41f Camera::pointCam2World(Matx41f pCam)
{
	OPENCV_ASSERT(isTSet,"Camera.pointCam2World","Using unknown camera transformation!");
	Matx41f pWorld = T * pCam;
	return pWorld;
}
示例#21
0
static int icvOpenAVI_XINE( CvCaptureAVI_XINE* capture, const char* filename )
{
#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvOpenAVI_XINE ... start\n" );
#endif

    char configfile[ 2048 ];

    capture->xine = xine_new();
    sprintf( configfile, "%s%s", xine_get_homedir(), "/.xine/config" );

    xine_config_load( capture->xine, configfile );
    xine_init( capture->xine );

    xine_engine_set_param( capture->xine, 0, 0 );
    capture->vo_port = xine_new_framegrab_video_port( capture->xine );
    if ( capture->vo_port == NULL )
    {
        printf( "(ERROR)icvOpenAVI_XINE(): Unable to initialize video driver.\n" );
        return 0;
    }

    capture->stream = xine_stream_new( capture->xine, NULL, capture->vo_port );

    if ( !xine_open( capture->stream, filename ) )
    {
        printf( "(ERROR)icvOpenAVI_XINE(): Unable to open source '%s'\n", filename );
        return 0;
    }
    // reset stream...
    xine_play( capture->stream, 0, 0 );


    // initialize some internals...
    capture->frame_number = 0;

    if ( !xine_get_next_video_frame( capture->vo_port, &capture->xine_frame ) )
    {
#ifndef NDEBUG
        fprintf( stderr, "(DEBUG) icvOpenAVI_XINE ... failed!\n" );
#endif
        return 0;
    }

    capture->size = cvSize( capture->xine_frame.width, capture->xine_frame.height );
    capture->yuv_frame = cvCreateImage( capture->size, IPL_DEPTH_8U, 3 );
    capture->bgr_frame = cvCreateImage( capture->size, IPL_DEPTH_8U, 3 );

    xine_free_video_frame( capture->vo_port, &capture->xine_frame );
    capture->xine_frame.data[ 0 ] = 0;

    icvCheckSeekAVI_XINE( capture );

    capture->frame_duration = xine_get_stream_info( capture->stream, XINE_STREAM_INFO_FRAME_DURATION ) / 90.;
    capture->frame_rate = 1000 / capture->frame_duration;

#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) frame_duration = %f, framerate = %f\n", capture->frame_duration, capture->frame_rate );
#endif

    OPENCV_ASSERT ( capture->yuv_frame,
                        "icvOpenAVI_XINE( CvCaptureAVI_XINE *, const char *)", "couldn't create yuv frame");

    OPENCV_ASSERT ( capture->bgr_frame,
                        "icvOpenAVI_XINE( CvCaptureAVI_XINE *, const char *)", "couldn't create bgr frame");

#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvOpenAVI_XINE ... end\n" );
#endif
    return 1;
}
示例#22
0
void Camera::undistortImage(Mat& src, Mat& dst)
{
	OPENCV_ASSERT(isCalibrated,"Camera.undistortImage","Cannot undistort before camera calibration!");
	undistort(src, dst, cameraMatrix, distortionCoeffs);
}
示例#23
0
static const IplImage* icvRetrieveFrameAVI_XINE( CvCaptureAVI_XINE* capture, int )
{
#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvRetrieveFrameAVI_XINE ... start\n" );
#endif

    OPENCV_ASSERT ( capture,
                        "icvRetrieveFrameAVI_XINE( CvCaptureAVI_XINE * )", "illegal capture");
    OPENCV_ASSERT ( capture->stream,
                        "icvRetrieveFrameAVI_XINE( CvCaptureAVI_XINE * )", "illegal capture->stream");
    OPENCV_ASSERT ( capture->vo_port,
                        "icvRetrieveFrameAVI_XINE( CvCaptureAVI_XINE * )", "illegal capture->vo_port");

    /* no frame grabbed yet? so let's do it now! */
    int res = 0;
    if ( capture->xine_frame.data == 0 )
    {
        res = icvGrabFrameAVI_XINE( capture );
    }
    else
    {
        res = 1;
    }

    if ( res )
    {
        switch ( capture->xine_frame.colorspace )
        {
                case XINE_IMGFMT_YV12: icvYV12toBGR( capture );
#ifndef NDEBUG
                printf( "(DEBUG)icvRetrieveFrameAVI_XINE: converted YV12 to BGR.\n" );
#endif
                break;

                case XINE_IMGFMT_YUY2: icvYUY2toBGR( capture );
#ifndef NDEBUG
                printf( "(DEBUG)icvRetrieveFrameAVI_XINE: converted YUY2 to BGR.\n" );
#endif
                break;
                case XINE_IMGFMT_XVMC: printf( "(ERROR)icvRetrieveFrameAVI_XINE: XVMC format not supported!\n" );
                break;

                case XINE_IMGFMT_XXMC: printf( "(ERROR)icvRetrieveFrameAVI_XINE: XXMC format not supported!\n" );
                break;

                default: printf( "(ERROR)icvRetrieveFrameAVI_XINE: unknown color/pixel format!\n" );
        }

        /* always release last xine_frame, not needed anymore, but store its frame_number in *capture ! */
        xine_free_video_frame( capture->vo_port, &capture->xine_frame );
        capture->xine_frame.data = 0;

#ifndef NDEBUG
        fprintf( stderr, "(DEBUG) icvRetrieveFrameAVI_XINE ... end\n" );
#endif
        return capture->bgr_frame;
    }

#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvRetrieveFrameAVI_XINE ... failed!\n" );
#endif
    return 0;
}
示例#24
0
/**
 * THIS FUNCTION IS A FALLBACK FUNCTION FOR THE CASE THAT THE XINE SEEK IMPLEMENTATION
 * DOESN'T WORK WITH THE ACTUAL INPUT. THIS FUNCTION IS ONLY USED IN THE CASE OF AN EMERGENCY,
 * BECAUSE IT IS VERY SLOW !
**/
static int icvOldSeekFrameAVI_XINE( CvCaptureAVI_XINE* capture, int f )
{
#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvOldSeekFrameAVI_XINE ... start\n" );
#endif

    OPENCV_ASSERT ( capture,
                        "icvRetricvOldSeekFrameAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture");
    OPENCV_ASSERT ( capture->stream,
                        "icvOldSeekFrameAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->stream");
    OPENCV_ASSERT ( capture->vo_port,
                        "icvOldSeekFrameAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->vo_port");

// not needed tnx to asserts...
    // we need a valid capture context and it's stream to seek through
//	if ( !capture || !capture->stream ) return 0;

    // no need to seek if we are already there...
    if ( f == capture->frame_number )
    {
#ifndef NDEBUG
        fprintf( stderr, "(DEBUG) icvOldSeekFrameAVI_XINE ... end\n" );
#endif
        return 1;
    }
    // if the requested position is behind out actual position,
    // we just need to read the remaining amount of frames until we are there.
    else if ( f > capture->frame_number )
    {
        for ( ;capture->frame_number < f;capture->frame_number++ )
            /// un-increment framenumber grabbing failed
            if ( !xine_get_next_video_frame( capture->vo_port, &capture->xine_frame ) )
            {
                capture->frame_number--;
                break;
            }
            else
            {
                xine_free_video_frame( capture->vo_port, &capture->xine_frame );
            }
    }
    // otherwise we need to reset the stream and
    // start reading frames from the beginning.
    else // f < capture->frame_number
    {
        /// reset stream, should also work with non-seekable input
        xine_play( capture->stream, 0, 0 );
        /// read frames until we are at the requested frame
        for ( capture->frame_number = 0; capture->frame_number < f; capture->frame_number++ )
            /// un-increment last framenumber if grabbing failed
            if ( !xine_get_next_video_frame( capture->vo_port, &capture->xine_frame ) )
            {
                capture->frame_number--;
                break;
            }
            else
            {
                xine_free_video_frame( capture->vo_port, &capture->xine_frame );
            }
    }


#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvOldSeekFrameAVI_XINE ... end\n" );
#endif
    return ( f == capture->frame_number ) ? 1 : 0;
}
示例#25
0
static double icvGetPropertyAVI_XINE( CvCaptureAVI_XINE* capture, int property_id )
{
#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvGetPropertyAVI_XINE ... start\n" );
#endif

    OPENCV_ASSERT ( capture,
                        "icvGetPropertyAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture");
    OPENCV_ASSERT ( capture->stream,
                        "icvGetPropertyAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->stream");
    OPENCV_ASSERT ( capture->vo_port,
                        "icvGetPropertyAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->vo_port");
    OPENCV_ASSERT ( capture->xine,
                        "icvGetPropertyAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->xine");
    OPENCV_ASSERT ( capture->bgr_frame,
                        "icvGetPropertyAVI_XINE( CvCaptureAVI_XINE *, int )", "illegal capture->bgr_frame");

// not needed tnx to asserts...
    // we need a valid capture context and it's stream to seek through
//	if ( !capture || !capture->stream || !capture->bgr_frame || !capture->xine || !capture->vo_port ) return 0

    int pos_t, pos_l, length;
    xine_get_pos_length( capture->stream, &pos_l, &pos_t, &length );
    fprintf( stderr, "ratio on GetProperty(): %i\n", pos_l );

    switch ( property_id )
    {
            /// return actual position in msec
            case CV_CAP_PROP_POS_MSEC:
            if ( !capture->seekable )
            {
                fprintf( stderr, "(ERROR) GetPropertyAVI_XINE(CV_CAP_PROP_POS_MSEC:\n" );
                fprintf( stderr, "	Stream is NOT seekable, so position info may NOT be valid !!\n" );
            }
            return pos_t;

            /// return actual frame number
            case CV_CAP_PROP_POS_FRAMES:
            /// we insist the capture->frame_number to be remain updated !!!!
            return capture->frame_number;

            /// return actual position ratio in the range [0..1] depending on
            /// the total length of the stream and the actual position
            case CV_CAP_PROP_POS_AVI_RATIO:
            if ( !capture->seekable )
            {
                fprintf( stderr, "(ERROR) GetPropertyAVI_XINE(CV_CAP_PROP_POS_AVI_RATIO:\n" );
                fprintf( stderr, "	Stream is NOT seekable, so ratio info may NOT be valid !!\n" );
            }
            if ( length == 0 ) break;
            else return pos_l / 65535;


            /// return width of image source
            case CV_CAP_PROP_FRAME_WIDTH:
            return capture->size.width;

            /// return height of image source
            case CV_CAP_PROP_FRAME_HEIGHT:
            return capture->size.height;

            /// return framerate of stream
            case CV_CAP_PROP_FPS:
            if ( !capture->seekable )
            {
                fprintf( stderr, "(ERROR) GetPropertyAVI_XINE(CV_CAP_PROP_FPS:\n" );
                fprintf( stderr, "	Stream is NOT seekable, so FPS info may NOT be valid !!\n" );
            }
            return capture->frame_rate;

            /// return four-character-code (FOURCC) of source's codec
            case CV_CAP_PROP_FOURCC:
            return ( double ) xine_get_stream_info( capture->stream, XINE_STREAM_INFO_VIDEO_FOURCC );
    }

#ifndef NDEBUG
    fprintf( stderr, "(DEBUG) icvGetPropertyAVI_XINE ... failed!\n" );
#endif

    return 0;
}