mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
refactored StereoBM
This commit is contained in:
@@ -85,7 +85,7 @@ void inline contextOff()
|
||||
// GPUs data
|
||||
GpuMat d_left[2];
|
||||
GpuMat d_right[2];
|
||||
StereoBM_GPU* bm[2];
|
||||
Ptr<gpu::StereoBM> bm[2];
|
||||
GpuMat d_result[2];
|
||||
|
||||
static void printHelp()
|
||||
@@ -162,14 +162,14 @@ int main(int argc, char** argv)
|
||||
contextOn(0);
|
||||
d_left[0].upload(left.rowRange(0, left.rows / 2));
|
||||
d_right[0].upload(right.rowRange(0, right.rows / 2));
|
||||
bm[0] = new StereoBM_GPU();
|
||||
bm[0] = gpu::createStereoBM();
|
||||
contextOff();
|
||||
|
||||
// Split source images for processing on the GPU #1
|
||||
contextOn(1);
|
||||
d_left[1].upload(left.rowRange(left.rows / 2, left.rows));
|
||||
d_right[1].upload(right.rowRange(right.rows / 2, right.rows));
|
||||
bm[1] = new StereoBM_GPU();
|
||||
bm[1] = gpu::createStereoBM();
|
||||
contextOff();
|
||||
|
||||
// Execute calculation in two threads using two GPUs
|
||||
@@ -182,7 +182,7 @@ int main(int argc, char** argv)
|
||||
d_left[0].release();
|
||||
d_right[0].release();
|
||||
d_result[0].release();
|
||||
delete bm[0];
|
||||
bm[0].release();
|
||||
contextOff();
|
||||
|
||||
// Release the second GPU resources
|
||||
@@ -191,7 +191,7 @@ int main(int argc, char** argv)
|
||||
d_left[1].release();
|
||||
d_right[1].release();
|
||||
d_result[1].release();
|
||||
delete bm[1];
|
||||
bm[1].release();
|
||||
contextOff();
|
||||
|
||||
waitKey();
|
||||
@@ -204,8 +204,7 @@ void Worker::operator()(int device_id) const
|
||||
{
|
||||
contextOn(device_id);
|
||||
|
||||
bm[device_id]->operator()(d_left[device_id], d_right[device_id],
|
||||
d_result[device_id]);
|
||||
bm[device_id]->compute(d_left[device_id], d_right[device_id], d_result[device_id]);
|
||||
|
||||
std::cout << "GPU #" << device_id << " (" << DeviceInfo().name()
|
||||
<< "): finished\n";
|
||||
|
||||
@@ -65,7 +65,7 @@ private:
|
||||
Mat left, right;
|
||||
gpu::GpuMat d_left, d_right;
|
||||
|
||||
gpu::StereoBM_GPU bm;
|
||||
Ptr<gpu::StereoBM> bm;
|
||||
gpu::StereoBeliefPropagation bp;
|
||||
gpu::StereoConstantSpaceBP csbp;
|
||||
|
||||
@@ -172,7 +172,7 @@ void App::run()
|
||||
imshow("right", right);
|
||||
|
||||
// Set common parameters
|
||||
bm.ndisp = p.ndisp;
|
||||
bm = gpu::createStereoBM(p.ndisp);
|
||||
bp.ndisp = p.ndisp;
|
||||
csbp.ndisp = p.ndisp;
|
||||
|
||||
@@ -201,7 +201,7 @@ void App::run()
|
||||
imshow("left", left);
|
||||
imshow("right", right);
|
||||
}
|
||||
bm(d_left, d_right, d_disp);
|
||||
bm->compute(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;
|
||||
@@ -228,8 +228,8 @@ void App::printParams() const
|
||||
switch (p.method)
|
||||
{
|
||||
case Params::BM:
|
||||
cout << "win_size: " << bm.winSize << endl;
|
||||
cout << "prefilter_sobel: " << bm.preset << endl;
|
||||
cout << "win_size: " << bm->getBlockSize() << endl;
|
||||
cout << "prefilter_sobel: " << bm->getPreFilterType() << endl;
|
||||
break;
|
||||
case Params::BP:
|
||||
cout << "iter_count: " << bp.iters << endl;
|
||||
@@ -289,44 +289,44 @@ void App::handleKey(char key)
|
||||
case 's': case 'S':
|
||||
if (p.method == Params::BM)
|
||||
{
|
||||
switch (bm.preset)
|
||||
switch (bm->getPreFilterType())
|
||||
{
|
||||
case gpu::StereoBM_GPU::BASIC_PRESET:
|
||||
bm.preset = gpu::StereoBM_GPU::PREFILTER_XSOBEL;
|
||||
case 0:
|
||||
bm->setPreFilterType(cv::StereoBM::PREFILTER_XSOBEL);
|
||||
break;
|
||||
case gpu::StereoBM_GPU::PREFILTER_XSOBEL:
|
||||
bm.preset = gpu::StereoBM_GPU::BASIC_PRESET;
|
||||
case cv::StereoBM::PREFILTER_XSOBEL:
|
||||
bm->setPreFilterType(0);
|
||||
break;
|
||||
}
|
||||
cout << "prefilter_sobel: " << bm.preset << endl;
|
||||
cout << "prefilter_sobel: " << bm->getPreFilterType() << endl;
|
||||
}
|
||||
break;
|
||||
case '1':
|
||||
p.ndisp = p.ndisp == 1 ? 8 : p.ndisp + 8;
|
||||
cout << "ndisp: " << p.ndisp << endl;
|
||||
bm.ndisp = p.ndisp;
|
||||
bm->setNumDisparities(p.ndisp);
|
||||
bp.ndisp = p.ndisp;
|
||||
csbp.ndisp = p.ndisp;
|
||||
break;
|
||||
case 'q': case 'Q':
|
||||
p.ndisp = max(p.ndisp - 8, 1);
|
||||
cout << "ndisp: " << p.ndisp << endl;
|
||||
bm.ndisp = p.ndisp;
|
||||
bm->setNumDisparities(p.ndisp);
|
||||
bp.ndisp = p.ndisp;
|
||||
csbp.ndisp = p.ndisp;
|
||||
break;
|
||||
case '2':
|
||||
if (p.method == Params::BM)
|
||||
{
|
||||
bm.winSize = min(bm.winSize + 1, 51);
|
||||
cout << "win_size: " << bm.winSize << endl;
|
||||
bm->setBlockSize(min(bm->getBlockSize() + 1, 51));
|
||||
cout << "win_size: " << bm->getBlockSize() << endl;
|
||||
}
|
||||
break;
|
||||
case 'w': case 'W':
|
||||
if (p.method == Params::BM)
|
||||
{
|
||||
bm.winSize = max(bm.winSize - 1, 2);
|
||||
cout << "win_size: " << bm.winSize << endl;
|
||||
bm->setBlockSize(max(bm->getBlockSize() - 1, 2));
|
||||
cout << "win_size: " << bm->getBlockSize() << endl;
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
|
||||
@@ -51,7 +51,7 @@ struct Worker { void operator()(int device_id) const; };
|
||||
// GPUs data
|
||||
GpuMat d_left[2];
|
||||
GpuMat d_right[2];
|
||||
StereoBM_GPU* bm[2];
|
||||
Ptr<gpu::StereoBM> bm[2];
|
||||
GpuMat d_result[2];
|
||||
|
||||
static void printHelp()
|
||||
@@ -112,13 +112,13 @@ int main(int argc, char** argv)
|
||||
setDevice(0);
|
||||
d_left[0].upload(left.rowRange(0, left.rows / 2));
|
||||
d_right[0].upload(right.rowRange(0, right.rows / 2));
|
||||
bm[0] = new StereoBM_GPU();
|
||||
bm[0] = gpu::createStereoBM();
|
||||
|
||||
// Split source images for processing on the GPU #1
|
||||
setDevice(1);
|
||||
d_left[1].upload(left.rowRange(left.rows / 2, left.rows));
|
||||
d_right[1].upload(right.rowRange(right.rows / 2, right.rows));
|
||||
bm[1] = new StereoBM_GPU();
|
||||
bm[1] = gpu::createStereoBM();
|
||||
|
||||
// Execute calculation in two threads using two GPUs
|
||||
int devices[] = {0, 1};
|
||||
@@ -130,7 +130,7 @@ int main(int argc, char** argv)
|
||||
d_left[0].release();
|
||||
d_right[0].release();
|
||||
d_result[0].release();
|
||||
delete bm[0];
|
||||
bm[0].release();
|
||||
|
||||
// Release the second GPU resources
|
||||
setDevice(1);
|
||||
@@ -138,7 +138,7 @@ int main(int argc, char** argv)
|
||||
d_left[1].release();
|
||||
d_right[1].release();
|
||||
d_result[1].release();
|
||||
delete bm[1];
|
||||
bm[1].release();
|
||||
|
||||
waitKey();
|
||||
return 0;
|
||||
@@ -149,8 +149,7 @@ void Worker::operator()(int device_id) const
|
||||
{
|
||||
setDevice(device_id);
|
||||
|
||||
bm[device_id]->operator()(d_left[device_id], d_right[device_id],
|
||||
d_result[device_id]);
|
||||
bm[device_id]->compute(d_left[device_id], d_right[device_id], d_result[device_id]);
|
||||
|
||||
std::cout << "GPU #" << device_id << " (" << DeviceInfo().name()
|
||||
<< "): finished\n";
|
||||
|
||||
Reference in New Issue
Block a user