PERF_TEST_P(DevInfo, StereoConstantSpaceBP, testing::ValuesIn(devices())) { DeviceInfo devInfo = GetParam(); setDevice(devInfo.deviceID()); Mat img_l_host = readImage("gpu/perf/aloe.jpg", CV_LOAD_IMAGE_GRAYSCALE); Mat img_r_host = readImage("gpu/perf/aloeR.jpg", CV_LOAD_IMAGE_GRAYSCALE); ASSERT_FALSE(img_l_host.empty()); ASSERT_FALSE(img_r_host.empty()); GpuMat img_l(img_l_host); GpuMat img_r(img_r_host); GpuMat dst; StereoConstantSpaceBP bp(128); declare.time(10.0); SIMPLE_TEST_CYCLE() { bp(img_l, img_r, dst); } Mat dst_host(dst); SANITY_CHECK(dst_host); }
PERF_TEST_P(DevInfo, StereoBM, testing::ValuesIn(devices())) { DeviceInfo devInfo = GetParam(); setDevice(devInfo.deviceID()); Mat img_l_host = readImage("gpu/perf/aloe.jpg", CV_LOAD_IMAGE_GRAYSCALE); Mat img_r_host = readImage("gpu/perf/aloeR.jpg", CV_LOAD_IMAGE_GRAYSCALE); ASSERT_FALSE(img_l_host.empty()); ASSERT_FALSE(img_r_host.empty()); GpuMat img_l(img_l_host); GpuMat img_r(img_r_host); GpuMat dst; StereoBM_GPU bm(0, 256); declare.time(0.5).iterations(100); SIMPLE_TEST_CYCLE() { bm(img_l, img_r, dst); } Mat dst_host(dst); SANITY_CHECK(dst_host); }
PERF_TEST_P(DevInfo, StereoBeliefPropagation, testing::ValuesIn(devices())) { DeviceInfo devInfo = GetParam(); setDevice(devInfo.deviceID()); Mat img_l_host = readImage("gpu/stereobm/aloe-L.png", CV_LOAD_IMAGE_GRAYSCALE); Mat img_r_host = readImage("gpu/stereobm/aloe-R.png", CV_LOAD_IMAGE_GRAYSCALE); ASSERT_FALSE(img_l_host.empty()); ASSERT_FALSE(img_r_host.empty()); GpuMat img_l(img_l_host); GpuMat img_r(img_r_host); GpuMat dst; StereoBeliefPropagation bp(128); declare.time(10.0); SIMPLE_TEST_CYCLE() { bp(img_l, img_r, dst); } Mat dst_host(dst); SANITY_CHECK(dst_host); }
GPU_PERF_TEST_1(StereoBM, cv::gpu::DeviceInfo) { cv::gpu::DeviceInfo devInfo = GetParam(); cv::gpu::setDevice(devInfo.deviceID()); cv::Mat img_l_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(img_l_host.empty()); cv::Mat img_r_host = readImage("gpu/perf/aloeR.jpg", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(img_r_host.empty()); cv::gpu::StereoBM_GPU bm(0, 256); cv::gpu::GpuMat img_l(img_l_host); cv::gpu::GpuMat img_r(img_r_host); cv::gpu::GpuMat dst; bm(img_l, img_r, dst); declare.time(5.0); TEST_CYCLE() { bm(img_l, img_r, dst); } }
GPU_PERF_TEST_1(StereoConstantSpaceBP, cv::gpu::DeviceInfo) { cv::gpu::DeviceInfo devInfo = GetParam(); cv::gpu::setDevice(devInfo.deviceID()); cv::Mat img_l_host = readImage("gpu/stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(img_l_host.empty()); cv::Mat img_r_host = readImage("gpu/stereobm/aloe-R.png", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(img_r_host.empty()); cv::gpu::StereoConstantSpaceBP csbp(128); cv::gpu::GpuMat img_l(img_l_host); cv::gpu::GpuMat img_r(img_r_host); cv::gpu::GpuMat dst; csbp(img_l, img_r, dst); declare.time(10.0); TEST_CYCLE() { csbp(img_l, img_r, dst); } }
GPU_PERF_TEST_1(StereoBeliefPropagation, cv::gpu::DeviceInfo) { cv::gpu::DeviceInfo devInfo = GetParam(); cv::gpu::setDevice(devInfo.deviceID()); cv::Mat img_l_host = readImage("gpu/stereobp/aloe-L.png"); ASSERT_FALSE(img_l_host.empty()); cv::Mat img_r_host = readImage("gpu/stereobp/aloe-R.png"); ASSERT_FALSE(img_r_host.empty()); cv::gpu::StereoBeliefPropagation bp(64); cv::gpu::GpuMat img_l(img_l_host); cv::gpu::GpuMat img_r(img_r_host); cv::gpu::GpuMat dst; bp(img_l, img_r, dst); declare.time(10.0); TEST_CYCLE() { bp(img_l, img_r, dst); } }
int Vision::assign_color(Mat image, int x, int y) { Rect myROI( x - 3, y - 3, 7, 3); Mat imageIn = image(myROI); //imshow("Rect", imageIn); //waitKey(); // split the BGR image into individual channels Mat img_b(imageIn.rows, imageIn.cols, CV_8UC1); Mat img_g(imageIn.rows, imageIn.cols, CV_8UC1); Mat img_r(imageIn.rows, imageIn.cols, CV_8UC1); Mat channels[] = {img_b, img_g, img_r}; split(imageIn, channels); // compute the overall intensity for each pixel as (b + g + r) Mat intensity(imageIn.rows, imageIn.cols, CV_32F); add(img_b, img_g, intensity); add(intensity, img_r, intensity); intensity = intensity / 3.0; // compute the normalized color values for each channel Mat norm_b = img_b / intensity; Mat norm_g = img_g / intensity; Mat norm_r = img_r / intensity; // compute the average normalized color value of each channel double avg_b = cv::mean(norm_b)[0]; double avg_g = cv::mean(norm_g)[0]; double avg_r = cv::mean(norm_r)[0]; // print the color values to console std::printf("B: %f G: %f R: %f \n", avg_b, avg_g, avg_r); // define the reference color values double RED[] = {0.0, 0.5, 3.0}; double GREEN[] = {.5, 2.5, .0}; double BLUE[] = {2.5, 0.7, 0.0}; double YELLOW[] = {0.0, 2, 1}; double ORANGE[] = {0.0, 1.0, 2.0}; double WHITE[] = {2.0, 2.0, 2.0}; double YELLOW2[] = {0.0, 2.0, 2.0}; double ORANGE2[] = {0.0, 2.0, 3.0}; /* double RED[][3] = {{0.0, 1.0, 2.0},{0.0, 1.0, 2.0},{0.0, 0.3, 3.0},{0.0, 1.0, 2.0}}; double GREEN[][3] = {{.5, 2.5, .0},{.5, 2.5, .0} ,{.5, 2.5, .0},{.5, 2.5, .0}}; double BLUE[][3] = {{2.0, 1.0, 0.0}, {2.0, 1.0, 0.0}, {2.0, 1.0, 0.0}, {2.0, 1.0, 0.0}}; double YELLOW[][3] = {{0.0, 2.0, 1.0}, {0.0, 2.0, 1.0}, {0.0, 3.0, 3.0}, {0.0, 2.0, 1.0}}; double ORANGE[][3] = {{0.0, 2.0, 3.0}, {0.0, 1.0, 2.5}, {0.0, 1.0, 3.0}, {0.0, 1.0, 3.0}}; double WHITE[][3] = {{2.0, 2.0, 2.0}, {1.0, 1.0, 1.0}, {2.0, 2.0, 2.0}, {1.0, 1.0, 1.0}}; */ // compute the squerror relative to the reference color values double minError = 10.0; double errorSqr; char bestFit = 'x'; // int bestFit = 9999; // check RED fitness errorSqr = normSqr(RED[0], RED[1], RED[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_RED; } // check GREEN fitness errorSqr = normSqr(GREEN[0], GREEN[1], GREEN[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_GREEN; } // check BLUE fitness errorSqr = normSqr(BLUE[0], BLUE[1], BLUE[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_BLUE; } // check YELLOW fitness errorSqr = normSqr(YELLOW[0], YELLOW[2], YELLOW[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_YELLOW; } errorSqr = normSqr(YELLOW2[0], YELLOW2[2], YELLOW2[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_YELLOW; } // check ORANGE fitness errorSqr = normSqr(ORANGE[0], ORANGE[1], ORANGE[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_ORANGE; } errorSqr = normSqr(ORANGE2[0], ORANGE2[1], ORANGE2[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_ORANGE; } // check WHITE fitness errorSqr = normSqr(WHITE[0], WHITE[1], WHITE[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_WHITE; } errorSqr = normSqr(1.0, 1.0, 1.0, avg_b, avg_g, avg_r); if(errorSqr < minError && abs(avg_b - avg_r) < .3 && abs(avg_g - avg_r < .3) && abs(avg_g - avg_b < .3)) { minError = errorSqr; bestFit = COLOR_WHITE; } // return the best fit color label return bestFit; }
/*********************************************************************************************************************** * @BRIEF Process a single image frame * @PARAM[in] imageIn the input image region of interest * @RETURN the label char describing the ROI color * @AUTHOR Christopher D. McMurrough **********************************************************************************************************************/ char labelColor(const cv::Mat &imageIn) { // split the BGR image into individual channels cv::Mat img_b(imageIn.rows, imageIn.cols, CV_8UC1); cv::Mat img_g(imageIn.rows, imageIn.cols, CV_8UC1); cv::Mat img_r(imageIn.rows, imageIn.cols, CV_8UC1); cv::Mat channels[] = {img_b, img_g, img_r}; cv::split(imageIn, channels); // compute the overall intensity for each pixel as (b + g + r) cv::Mat intensity(imageIn.rows, imageIn.cols, CV_32F); cv::add(img_b, img_g, intensity); cv::add(intensity, img_r, intensity); intensity = intensity / 3.0; // compute the normalized color values for each channel cv::Mat norm_b = img_b / intensity; cv::Mat norm_g = img_g / intensity; cv::Mat norm_r = img_r / intensity; // compute the average normalized color value of each channel double avg_b = cv::mean(norm_b)[0]; double avg_g = cv::mean(norm_g)[0]; double avg_r = cv::mean(norm_r)[0]; // print the color values to console std::printf("B: %f G: %f R: %f \n", avg_b, avg_g, avg_r); // define the reference color values double RED[] = {0.4, 0.5, 1.8}; double GREEN[] = {1.0, 1.2, 1.0}; double BLUE[] = {1.75, 1.0, 0.5}; double YELLOW[] = {0.82, 1.7, 1.7}; double ORANGE[] = {0.2, 1.0, 2.0}; double WHITE[] = {2.0, 1.7, 1.7}; // compute the squerror relative to the reference color values double minError = 3.0; double errorSqr; char bestFit = 'x'; // check RED fitness errorSqr = normSqr(RED[0], RED[1], RED[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_RED; } // check GREEN fitness errorSqr = normSqr(GREEN[0], GREEN[1], GREEN[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_GREEN; } // check BLUE fitness errorSqr = normSqr(BLUE[0], BLUE[1], BLUE[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_BLUE; } // check YELLOW fitness errorSqr = normSqr(YELLOW[0], YELLOW[1], YELLOW[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_YELLOW; } // check ORANGE fitness errorSqr = normSqr(ORANGE[0], ORANGE[1], ORANGE[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_ORANGE; } // check WHITE fitness errorSqr = normSqr(WHITE[0], WHITE[1], WHITE[2], avg_b, avg_g, avg_r); if(errorSqr < minError) { minError = errorSqr; bestFit = COLOR_WHITE; } // return the best fit color label return bestFit; }