Exemplo n.º 1
0
VideoCapture_IntelPerC::VideoCapture_IntelPerC()
    : m_contextOpened(false)
{
    pxcStatus sts = PXCSession_Create(&m_session);
    if (PXC_STATUS_NO_ERROR > sts)
        return;
    m_contextOpened = m_imageStream.initStream(m_session);
    m_contextOpened &= m_depthStream.initStream(m_session);
}
Exemplo n.º 2
0
int main() {

	std::cout << "Wave Effect Sample" << std::endl;

	//Initialize PerC Device
	PXCSmartPtr<PXCSession> session;
	pxcStatus sts = PXCSession_Create(&session);
	if(sts < PXC_STATUS_NO_ERROR) {
		std::cout << "Failed to PXCSession_Create: " << sts << std::endl;
		system("pause");
		return 1;
	}
	UtilCapture capture(session);

	PXCCapture::VideoStream::DataDesc req;
	memset(&req, 0, sizeof(req));
	req.streams[0].format = PXCImage::COLOR_FORMAT_RGB24;
	req.streams[1].format = PXCImage::COLOR_FORMAT_DEPTH;

	sts = capture.LocateStreams(&req);
	if(sts < PXC_STATUS_NO_ERROR) {
		std::cout << "Failed to LocateStreams: " << sts << std::endl;
		std::cout << "Make sure the device is connected." << std::endl;
		system("pause");
		return 2;
	}

	PXCCapture::VideoStream::ProfileInfo camera_info, depth_info;
	capture.QueryVideoStream(0)->QueryProfile(&camera_info);
	const cv::Size camera_size(camera_info.imageInfo.width, camera_info.imageInfo.height);
	capture.QueryVideoStream(1)->QueryProfile(&depth_info);
	const cv::Size depth_size(depth_info.imageInfo.width, depth_info.imageInfo.height);

	std::cout << "Camera info: " << camera_info.imageInfo.width << "x" << camera_info.imageInfo.height
		<< " (" << camera_info.frameRateMin.numerator / camera_info.frameRateMin.denominator << ")" << std::endl;
	std::cout << "Depth info: " << depth_info.imageInfo.width << "x" << depth_info.imageInfo.height
		<< " (" << depth_info.frameRateMin.numerator / depth_info.frameRateMin.denominator << ")" << std::endl;

	cv::Mat3b camera_image(camera_size);
	cv::Mat1b binary_image(depth_size);
	cv::Mat1b binary_show_image;
	cv::Mat1b resized_binary_image;
	cv::Mat1b dilated_binary_image;
	cv::Mat1f wave_image;
	cv::Mat1f wave_show_image;
	cv::Mat3b refract_image;

	Wave wave_object(depth_size);
	Refract refract_object;

	int distance_threshold_10cm = 5;
	int dilate_interation = 5;

	cv::namedWindow("binary");
	cv::namedWindow("wave");
	cv::namedWindow("refract");
	cv::createTrackbar("distance", "binary", &distance_threshold_10cm, 10);
	cv::createTrackbar("dilate", "binary", &dilate_interation, 10);
	cv::createTrackbar("C/100", "wave", NULL, 70, OnWaveCChanged, &wave_object);
	cv::setTrackbarPos("C/100", "wave", (int)(wave_object.get_c() * 100));
	cv::createTrackbar("D/100", "wave", NULL, 100, OnWaveDChanged, &wave_object);
	cv::setTrackbarPos("D/100", "wave", (int)(wave_object.get_D() * 100));
	cv::createTrackbar("K/100", "wave", NULL, 100, OnWaveKChanged, &wave_object);
	cv::setTrackbarPos("K/100", "wave", (int)(wave_object.get_K() * 100));
	cv::createTrackbar("iteration", "wave", NULL, 10, OnWaveIteratorChanged, &wave_object);
	cv::setTrackbarPos("iteration", "wave", wave_object.get_num_iteration());
	cv::createTrackbar("fixed", "wave", NULL, 1, OnWaveFixedBoundaryChanged, &wave_object);
	cv::setTrackbarPos("fixed", "wave", wave_object.get_fixed_boundary());
	cv::createTrackbar("alpha", "refract", NULL, 100, OnRefractAlphaChanged, &refract_object);
	cv::setTrackbarPos("alpha", "refract", (int)refract_object.get_alpha());

	std::cout << "Press ESC key to exit." << std::endl;

	while(true) {

		PXCSmartArray<PXCImage> images;
		PXCSmartSP sp;
		sts = capture.ReadStreamAsync(images, &sp);
		if(sts < PXC_STATUS_NO_ERROR) {
			std::cout << "Failed to ReadStreamAsync: " << sts << std::endl;
			system("pause");
			break;
		}
		sts = sp->Synchronize();
		if(sts < PXC_STATUS_NO_ERROR) {
			std::cout << "Failed to Synchronize: " << sts << std::endl;
			system("pause");
			break;
		}

		//Get camera image
		PXCImage::ImageData camera_data;
		sts = images[0]->AcquireAccess(PXCImage::ACCESS_READ, PXCImage::COLOR_FORMAT_RGB24, &camera_data);
		if(sts == PXC_STATUS_NO_ERROR) {
			const cv::Mat wrap_camera(camera_size, CV_8UC3, camera_data.planes[0], camera_data.pitches[0]);
			cv::flip(wrap_camera, camera_image, 1);//Flip around y-axis
			images[0]->ReleaseAccess(&camera_data);
		} else {
			std::cout << "Failed to AcquireAccess to camera: " << sts << std::endl;
		}

		//Get depth image
		PXCImage::ImageData depth_data;
		sts = images[1]->AcquireAccess(PXCImage::ACCESS_READ, PXCImage::COLOR_FORMAT_DEPTH, &depth_data);
		if(sts == PXC_STATUS_NO_ERROR) {
			const cv::Mat wrap_depth(depth_size, CV_16SC1, depth_data.planes[0], depth_data.pitches[0]);
			const cv::Mat wrap_uv(depth_size, CV_32FC2, depth_data.planes[2], depth_data.pitches[2]);

			Binalize(wrap_depth, wrap_uv, binary_image, distance_threshold_10cm * 100);
			cv::flip(binary_image, binary_image, 1);//Flip around y-axis

			images[1]->ReleaseAccess(&depth_data);
		} else {
			std::cout << "Failed to AcquireAccess to depth: " << sts << std::endl;
		}

		//Dilate
		cv::dilate(binary_image, dilated_binary_image, cv::Mat(), cv::Point(-1, -1), dilate_interation, cv::BORDER_REPLICATE);
		//Resize to display
		cv::resize(dilated_binary_image, binary_show_image, cv::Size(400, 300));

		//Apply wave propagation
		wave_object(dilated_binary_image, wave_image);
		//Convert to display
		cv::resize(wave_image, wave_show_image, cv::Size(400, 300));
		wave_show_image.convertTo(wave_show_image, wave_show_image.type(), 0.5, 0.5);

		//Apply refraction
		refract_object(camera_image, wave_image, refract_image);

		//Blend screen
		cv::resize(dilated_binary_image, resized_binary_image, camera_size);
		BlendScreen(refract_image, resized_binary_image, cv::Vec3b(40, 30, 0));

		//Display binary image
		cv::imshow("binary", binary_show_image);
		cv::imshow("wave", wave_show_image);
		cv::imshow("refract", refract_image);

		//Exit if ESC key is pressed
		if(cv::waitKey(1) == 0x1b) {
			break;
		}
	}

	cv::destroyAllWindows();

	return 0;
}
Exemplo n.º 3
0
////////////////////////////////////////////////////////////////////////////////
// protected member functions
////////////////////////////////////////////////////////////////////////////////
int IntelCamera::InitCamera(int device_num)
{
	// create a session
	pxcStatus sts = PXCSession_Create(&session);
	if (sts<PXC_STATUS_NO_ERROR) {
		fprintf(stderr,"Failed to create a session\n");
		return -1;
	}

	// create a video capture
	PXCSession::ImplDesc desc;
	memset(&desc, 0, sizeof(desc));
	desc.subgroup = PXCSession::IMPL_SUBGROUP_VIDEO_CAPTURE;

	PXCSmartPtr<PXCCapture> capture;
	sts = session->CreateImpl(&desc, PXCCapture::CUID, (void**)&capture);
	if (sts<PXC_STATUS_NO_ERROR) {
		fprintf(stderr,"Failed to create a capture\n");
		return -1;
	}

	// create a device
	PXCSmartPtr<PXCCapture::Device> device;
	sts = capture->CreateDevice(device_num, &device);
	if (sts<PXC_STATUS_NO_ERROR) {
		fprintf(stderr,"Failed to create a device\n");
		return -1;
	}

	// create color stream: 640x480
	sts = device->CreateStream(0, PXCCapture::VideoStream::CUID, (void**)&pColorStream);
	if(sts<PXC_STATUS_NO_ERROR){
		fprintf(stderr,"failed to create color stream\n");
		return -1;
	}
	PXCCapture::VideoStream::ProfileInfo pinfoColor;
	sts = pColorStream->QueryProfile(0, &pinfoColor);
	if(sts<PXC_STATUS_NO_ERROR){
		fprintf(stderr,"failed to get color stream profile\n");
		return -1;
	}

	// set for less error on depth image : because of sync color/depth
	pinfoColor.frameRateMax.denominator =  0;
	pinfoColor.frameRateMax.numerator   = 60;
	pinfoColor.frameRateMin.denominator =  0;
	pinfoColor.frameRateMin.numerator   = 60;

	sts = pColorStream->SetProfile(&pinfoColor);
	if(sts<PXC_STATUS_NO_ERROR){
		fprintf(stderr,"failed to get color stream profile\n");
		return -1;
	}

	// create depth streams: 320x240
	sts = device->CreateStream(1, PXCCapture::VideoStream::CUID, (void**)&pDepthStream);
	if(sts<PXC_STATUS_NO_ERROR){
		fprintf(stderr,"failed to create depth stream\n");
		return -1;
	}
	PXCCapture::VideoStream::ProfileInfo pinfoDepth;
	sts = pDepthStream->QueryProfile(0, &pinfoDepth);
	if(sts<PXC_STATUS_NO_ERROR){
		fprintf(stderr,"failed to get depth stream profile\n");
		return -1;
	}

	// set for less error on depth image
	pinfoDepth.frameRateMax.denominator =  1;
	pinfoDepth.frameRateMax.numerator   = 60;
	pinfoDepth.frameRateMin.denominator =  1;
	pinfoDepth.frameRateMin.numerator   = 60;

	sts = pDepthStream->SetProfile(&pinfoDepth);
	if(sts<PXC_STATUS_NO_ERROR){
		fprintf(stderr,"failed to get depth stream profile\n");
		return -1;
	}

	// read streams
	pColorStream->ReadStreamAsync(&images[0], &sps[0]);
	pDepthStream->ReadStreamAsync(&images[1], &sps[1]);

	// get constant values
	pxcUID prj_value;
	device->SetProperty(PXCCapture::Device::PROPERTY_DEPTH_SMOOTHING, 1); // depth smoothing
	device->QueryPropertyAsUID(PXCCapture::Device::PROPERTY_PROJECTION_SERIALIZABLE, &prj_value);
	device->QueryProperty(PXCCapture::Device::PROPERTY_DEPTH_LOW_CONFIDENCE_VALUE, &no_confidence);
	device->QueryProperty(PXCCapture::Device::PROPERTY_DEPTH_SATURATION_VALUE    , &depth_saturation);

	// get projection instance
	sts = session->DynamicCast<PXCMetadata>()->CreateSerializable<PXCProjection>(prj_value, &projection);
	if (sts<PXC_STATUS_NO_ERROR) {
		fprintf(stderr,"Failed to create a projection\n");
		return -1;
	}

	return 1;
}