void FacenetClassifier::create_input_tensor (long start_index, long end_index) { cout << "Using " << input_images.size() << " images" << endl; cout << "Start Index:" << start_index << " End Index:" << end_index << endl; Tensor input_tensor(DT_FLOAT, TensorShape({(int) (end_index - start_index), 160, 160, 3})); // get pointer to memory for that Tensor float *p = input_tensor.flat<float>().data(); int i; for (i = 0; i < (end_index - start_index) ; i++) { // create a "fake" cv::Mat from it Mat camera_image(160, 160, CV_32FC3, p + i*160*160*3); input_images[i + start_index].convertTo(camera_image, CV_32FC3); } cout << input_tensor.DebugString() << endl; this->input_tensor = Tensor (input_tensor); }
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; }