Пример #1
0
CameraControl *
camera_control_new(int cameraID)
{
	CameraControl* cc = (CameraControl*) calloc(1, sizeof(CameraControl));
	cc->cameraID = cameraID;

#if defined(CAMERA_CONTROL_USE_CL_DRIVER)
	int w, h;
	int cams = CLEyeGetCameraCount();

	if (cams <= cameraID) {
            free(cc);
            return NULL;
	}

	GUID cguid = CLEyeGetCameraUUID(cameraID);
	cc->camera = CLEyeCreateCamera(cguid,
                CLEYE_COLOR_PROCESSED, CLEYE_VGA, 60);

	CLEyeCameraGetFrameDimensions(cc->camera, &w, &h);

	// Depending on color mode chosen, create the appropriate OpenCV image
	cc->frame4ch = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 4);
	cc->frame3ch = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 3);

	CLEyeCameraStart(cc->camera);
#else
        char *video = psmove_util_get_env_string(PSMOVE_TRACKER_FILENAME_ENV);

        if (video) {
            psmove_DEBUG("Using '%s' as video input.\n", video);
            cc->capture = cvCaptureFromFile(video);
            free(video);
        } else {
            cc->capture = cvCaptureFromCAM(cc->cameraID);

            int width, height;
            get_metrics(&width, &height);

            cvSetCaptureProperty(cc->capture, CV_CAP_PROP_FRAME_WIDTH, width);
            cvSetCaptureProperty(cc->capture, CV_CAP_PROP_FRAME_HEIGHT, height);
        }
#endif

	return cc;
}
Пример #2
0
CameraControl *
camera_control_new_with_settings(int cameraID, int width, int height, int framerate, int cam_type)
{
	CameraControl* cc = (CameraControl*) calloc(1, sizeof(CameraControl));
	cc->cameraID = cameraID;

    if (framerate <= 0) {
        framerate = PSMOVE_TRACKER_DEFAULT_FPS;
    }
    
    if (cam_type == PSMove_Camera_PS3EYE_BLUEDOT)
    {
        cc->focl_x = (float)PS3EYE_FOCAL_LENGTH_BLUE;
        cc->focl_y = (float)PS3EYE_FOCAL_LENGTH_BLUE;
    }
    else if (cam_type == PSMove_Camera_PS3EYE_REDDOT)
    {
        cc->focl_x = (float)PS3EYE_FOCAL_LENGTH_RED;
        cc->focl_y = (float)PS3EYE_FOCAL_LENGTH_RED;
        
    }
    else if (cam_type == PSMove_Camera_Unknown)
    {
        cc->focl_x = (float)PS3EYE_FOCAL_LENGTH_BLUE;
        cc->focl_y = (float)PS3EYE_FOCAL_LENGTH_BLUE;
    }

    // Needed for cbb tracker. Will be overwritten by camera calibration files if they exist.
    

#if defined(CAMERA_CONTROL_USE_CL_DRIVER)
    // Windows 32-bit. Either CL_SDK or Registry_requiring
	int cams = CLEyeGetCameraCount();

	if (cams <= cameraID) {
            free(cc);
            return NULL;
	}

	GUID cguid = CLEyeGetCameraUUID(cameraID);
	cc->camera = CLEyeCreateCamera(cguid,
        CLEYE_COLOR_PROCESSED, CLEYE_VGA, framerate);

    CLEyeCameraGetFrameDimensions(cc->camera, &width, &height);

	// Depending on color mode chosen, create the appropriate OpenCV image
    cc->frame4ch = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 4);
    cc->frame3ch = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);

	CLEyeCameraStart(cc->camera);

#elif defined(CAMERA_CONTROL_USE_PS3EYE_DRIVER)
    // Mac or Windows
    // Initialize PS3EYEDriver
    ps3eye_init();
    int cams = ps3eye_count_connected();
    psmove_DEBUG("Found %i ps3eye(s) with CAMERA_CONTROL_USE_PS3EYE_DRIVER.\n", cams);
    if (cams <= cameraID) {
        free(cc);
        return NULL;
    }

    if (width <= 0 || height <= 0) {
        get_metrics(&width, &height);
    }

    psmove_DEBUG("Attempting to open ps3eye with cameraId, width, height, framerate: %d, %d, %d, %d.\n", cameraID, width, height, framerate);
    cc->eye = ps3eye_open(cameraID, width, height, framerate);

    if (cc->eye == NULL) {
        psmove_WARNING("Failed to open camera ID %d", cameraID);
        free(cc);
        return NULL;
    }

    cc->framebgr = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);

#else
    // Assume webcam accessible from OpenCV.
    char *video = psmove_util_get_env_string(PSMOVE_TRACKER_FILENAME_ENV);
    if (video) {
        psmove_DEBUG("Using '%s' as video input.\n", video);
        cc->capture = cvCaptureFromFile(video);
        free(video);
    } else {
        cc->capture = cvCaptureFromCAM(cc->cameraID);
        if (width <= 0 || height <= 0) {
            get_metrics(&width, &height);
        }
        cvSetCaptureProperty(cc->capture, CV_CAP_PROP_FRAME_WIDTH, width);
        cvSetCaptureProperty(cc->capture, CV_CAP_PROP_FRAME_HEIGHT, height);
    }

#endif
    cc->width = width;
    cc->height = height;
    cc->deinterlace = PSMove_False;

	return cc;
}