Exemplo n.º 1
0
TEST_P(Labeling, ConnectedComponents)
{
    cv::Mat image;
    cvtColor(loat_image(), image, CV_BGR2GRAY);

    ASSERT_TRUE(image.type() == CV_8UC1);

    GreedyLabeling host(image);
    host(host._labels);

    cv::gpu::GpuMat mask;
    mask.create(image.rows, image.cols, CV_8UC1);

    cv::gpu::GpuMat components;
    components.create(image.rows, image.cols, CV_32SC1);

    cv::gpu::connectivityMask(cv::gpu::GpuMat(image), mask, cv::Scalar::all(0), cv::Scalar::all(2));

    ASSERT_NO_THROW(cv::gpu::labelComponents(mask, components));

    // for (int j = 0; j + 32 < components.rows; j += 32)
    //     for (int i = 0; i + 32 < components.cols; i += 32)
    //     {
    //         std::cout << "Tile: " << i << " " << j << std::endl;
    //         std::cout << cv::Mat(host._labels, cv::Rect(i,j,32,32)) << std::endl;
    //         std::cout << cv::Mat(cv::Mat(components), cv::Rect(i,j,32,32)) << std::endl;
    //     }

    // for debug
    // cv::imshow("test", image);
    // cv::waitKey(0);
    // cv::imshow("test", host._labels * 50);
    // cv::waitKey(0);
    // // cv::imshow("test", cv::Mat(mask) * 10);
    // // cv::waitKey(0);
    // cv::imshow("test", cv::Mat(components) * 2);
    // cv::waitKey(0);
}
Exemplo n.º 2
0
GPU_TEST_P(Labeling, ConnectedComponents)
{
    cv::Mat image;
    cvtColor(loat_image(), image, CV_BGR2GRAY);

    cv::threshold(image, image, 150, 255, CV_THRESH_BINARY);

    ASSERT_TRUE(image.type() == CV_8UC1);

    GreedyLabeling host(image);
    host(host._labels);

    cv::gpu::GpuMat mask;
    mask.create(image.rows, image.cols, CV_8UC1);

    cv::gpu::GpuMat components;
    components.create(image.rows, image.cols, CV_32SC1);

    cv::gpu::connectivityMask(cv::gpu::GpuMat(image), mask, cv::Scalar::all(0), cv::Scalar::all(2));

    ASSERT_NO_THROW(cv::gpu::labelComponents(mask, components));

    host.checkCorrectness(cv::Mat(components));
}