Пример #1
0
void App::run()
{
    // Load images
    left_src = imread(p.left);
    right_src = imread(p.right);
    if (left_src.empty()) throw runtime_error("can't open file \"" + p.left + "\"");
    if (right_src.empty()) throw runtime_error("can't open file \"" + p.right + "\"");
    cvtColor(left_src, left, COLOR_BGR2GRAY);
    cvtColor(right_src, right, COLOR_BGR2GRAY);
    d_left.upload(left);
    d_right.upload(right);

    imshow("left", left);
    imshow("right", right);

    // Set common parameters
    bm.ndisp = p.ndisp;
    bp.ndisp = p.ndisp;
    csbp.ndisp = p.ndisp;

    // Prepare disparity map of specified type
    Mat disp(left.size(), CV_8U);
    gpu::GpuMat d_disp(left.size(), CV_8U);

    cout << endl;
    printParams();

    running = true;
    while (running)
    {
        workBegin();
        switch (p.method)
        {
        case Params::BM:
            if (d_left.channels() > 1 || d_right.channels() > 1)
            {
                cout << "BM doesn't support color images\n";
                cvtColor(left_src, left, COLOR_BGR2GRAY);
                cvtColor(right_src, right, COLOR_BGR2GRAY);
                cout << "image_channels: " << left.channels() << endl;
                d_left.upload(left);
                d_right.upload(right);
                imshow("left", left);
                imshow("right", right);
            }
            bm(d_left, d_right, d_disp);
            break;
        case Params::BP: bp(d_left, d_right, d_disp); break;
        case Params::CSBP: csbp(d_left, d_right, d_disp); break;
        }
        workEnd();

        // Show results
        d_disp.download(disp);
        putText(disp, text(), Point(5, 25), FONT_HERSHEY_SIMPLEX, 1.0, Scalar::all(255));
        imshow("disparity", disp);

        handleKey((char)waitKey(3));
    }
}
Пример #2
0
void xyVision::GetTarget::binarizeTarget_gpu(const gpu::GpuMat img, gpu::GpuMat & bi)
{
	CV_Assert(img.channels() == 3);
	gpu::GpuMat img2 = img.clone();
	std::vector<gpu::GpuMat> chs;
	gpu::split(img2, chs);

	Mat tmp;

	//gpu::GpuMat img_t = chs[2] - chs[0] - chs[1];
	gpu::GpuMat img_t, img_tmp;
	gpu::subtract(chs[2], chs[0], img_tmp);
	gpu::subtract(img_tmp, chs[1], img_t);

	gpu::threshold(img_t, bi, 40, 255, THRESH_BINARY);

	bi.convertTo(bi, CV_8UC1);
}
Пример #3
0
void xyVision::GetTarget::adjustImg_gpu(gpu::GpuMat& img)
{
	CV_Assert(img.channels() == 3);

	Size sz = img.size();
	float scaleFactor = this->proInfo.scale;
	gpu::GpuMat img2;
	gpu::resize(img, img2, Size(int(sz.width*scaleFactor), int(sz.height*scaleFactor)));
	img = img2.clone();

	gpu::getCudaEnabledDeviceCount();
	gpu::setDevice(0);
	vector<gpu::GpuMat> chs;
	gpu::split(img, chs);
	gpu::GpuMat out;
	// b g r
	//imadjust(chs[2], out);
	gpu::equalizeHist(chs[2], out);
	chs[2] = out;
	gpu::merge(chs, img);
}