Merge branch '2.4'
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
SET(OPENCV_GPU_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc opencv_highgui
|
||||
opencv_ml opencv_video opencv_objdetect opencv_features2d
|
||||
opencv_calib3d opencv_legacy opencv_contrib opencv_gpu
|
||||
opencv_nonfree opencv_softcascade)
|
||||
opencv_nonfree opencv_softcascade opencv_superres)
|
||||
|
||||
ocv_check_dependencies(${OPENCV_GPU_SAMPLES_REQUIRED_DEPS})
|
||||
|
||||
@@ -17,6 +17,10 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
"${OpenCV_SOURCE_DIR}/modules/gpu/src/nvidia/core"
|
||||
)
|
||||
|
||||
if(HAVE_opencv_nonfree)
|
||||
ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/nonfree/include")
|
||||
endif()
|
||||
|
||||
if(HAVE_CUDA)
|
||||
ocv_include_directories(${CUDA_INCLUDE_DIRS})
|
||||
endif()
|
||||
@@ -33,6 +37,9 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
add_executable(${the_target} ${srcs})
|
||||
|
||||
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_GPU_SAMPLES_REQUIRED_DEPS})
|
||||
if(HAVE_opencv_nonfree)
|
||||
target_link_libraries(${the_target} opencv_nonfree)
|
||||
endif()
|
||||
|
||||
set_target_properties(${the_target} PROPERTIES
|
||||
OUTPUT_NAME "${project}-example-${name}"
|
||||
|
@@ -15,7 +15,9 @@ enum Method
|
||||
FGD_STAT,
|
||||
MOG,
|
||||
MOG2,
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
VIBE,
|
||||
#endif
|
||||
GMG
|
||||
};
|
||||
|
||||
@@ -38,13 +40,25 @@ int main(int argc, const char** argv)
|
||||
string file = cmd.get<string>("file");
|
||||
string method = cmd.get<string>("method");
|
||||
|
||||
if (method != "fgd" && method != "mog" && method != "mog2" && method != "vibe" && method != "gmg")
|
||||
if (method != "fgd"
|
||||
&& method != "mog"
|
||||
&& method != "mog2"
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
&& method != "vibe"
|
||||
#endif
|
||||
&& method != "gmg")
|
||||
{
|
||||
cerr << "Incorrect method" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Method m = method == "fgd" ? FGD_STAT : method == "mog" ? MOG : method == "mog2" ? MOG2 : method == "vibe" ? VIBE : GMG;
|
||||
Method m = method == "fgd" ? FGD_STAT :
|
||||
method == "mog" ? MOG :
|
||||
method == "mog2" ? MOG2 :
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
method == "vibe" ? VIBE :
|
||||
#endif
|
||||
GMG;
|
||||
|
||||
VideoCapture cap;
|
||||
|
||||
@@ -67,7 +81,9 @@ int main(int argc, const char** argv)
|
||||
FGDStatModel fgd_stat;
|
||||
MOG_GPU mog;
|
||||
MOG2_GPU mog2;
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
VIBE_GPU vibe;
|
||||
#endif
|
||||
GMG_GPU gmg;
|
||||
gmg.numInitializationFrames = 40;
|
||||
|
||||
@@ -93,9 +109,11 @@ int main(int argc, const char** argv)
|
||||
mog2(d_frame, d_fgmask);
|
||||
break;
|
||||
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
case VIBE:
|
||||
vibe.initialize(d_frame);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case GMG:
|
||||
gmg.initialize(d_frame.size());
|
||||
@@ -105,8 +123,14 @@ int main(int argc, const char** argv)
|
||||
namedWindow("image", WINDOW_NORMAL);
|
||||
namedWindow("foreground mask", WINDOW_NORMAL);
|
||||
namedWindow("foreground image", WINDOW_NORMAL);
|
||||
if (m != VIBE && m != GMG)
|
||||
if (m != GMG
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
&& m != VIBE
|
||||
#endif
|
||||
)
|
||||
{
|
||||
namedWindow("mean background image", WINDOW_NORMAL);
|
||||
}
|
||||
|
||||
for(;;)
|
||||
{
|
||||
@@ -136,9 +160,11 @@ int main(int argc, const char** argv)
|
||||
mog2.getBackgroundImage(d_bgimg);
|
||||
break;
|
||||
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
case VIBE:
|
||||
vibe(d_frame, d_fgmask);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case GMG:
|
||||
gmg(d_frame, d_fgmask);
|
||||
|
@@ -216,7 +216,7 @@ int main(int argc, const char *argv[])
|
||||
|
||||
if (useGPU)
|
||||
{
|
||||
cascade_gpu.visualizeInPlace = true;
|
||||
//cascade_gpu.visualizeInPlace = true;
|
||||
cascade_gpu.findLargestObject = findLargestObject;
|
||||
|
||||
detections_num = cascade_gpu.detectMultiScale(resized_gpu, facesBuf_gpu, 1.2,
|
||||
@@ -245,6 +245,11 @@ int main(int argc, const char *argv[])
|
||||
if (useGPU)
|
||||
{
|
||||
resized_gpu.download(resized_cpu);
|
||||
|
||||
for (int i = 0; i < detections_num; ++i)
|
||||
{
|
||||
rectangle(resized_cpu, faces_downloaded.ptr<cv::Rect>()[i], Scalar(255));
|
||||
}
|
||||
}
|
||||
|
||||
tm.stop();
|
||||
|
@@ -73,9 +73,6 @@ GpuMat d_right[2];
|
||||
StereoBM_GPU* bm[2];
|
||||
GpuMat d_result[2];
|
||||
|
||||
// CPU result
|
||||
Mat result;
|
||||
|
||||
static void printHelp()
|
||||
{
|
||||
std::cout << "Usage: driver_api_stereo_multi_gpu --left <left_image> --right <right_image>\n";
|
||||
|
@@ -3,9 +3,17 @@ set(the_target "example_gpu_performance")
|
||||
file(GLOB sources "performance/*.cpp")
|
||||
file(GLOB headers "performance/*.h")
|
||||
|
||||
if(HAVE_opencv_nonfree)
|
||||
ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/nonfree/include")
|
||||
endif()
|
||||
|
||||
add_executable(${the_target} ${sources} ${headers})
|
||||
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_GPU_SAMPLES_REQUIRED_DEPS})
|
||||
|
||||
if(HAVE_opencv_nonfree)
|
||||
target_link_libraries(${the_target} opencv_nonfree)
|
||||
endif()
|
||||
|
||||
set_target_properties(${the_target} PROPERTIES
|
||||
OUTPUT_NAME "performance_gpu"
|
||||
PROJECT_LABEL "(EXAMPLE_GPU) performance")
|
||||
|
@@ -4,10 +4,15 @@
|
||||
#include "opencv2/calib3d/calib3d.hpp"
|
||||
#include "opencv2/video/video.hpp"
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
#include "opencv2/nonfree/nonfree.hpp"
|
||||
#include "opencv2/legacy/legacy.hpp"
|
||||
#include "performance.h"
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
#include "opencv2/nonfree/gpu.hpp"
|
||||
#include "opencv2/nonfree/nonfree.hpp"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
@@ -266,6 +271,7 @@ TEST(meanShift)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
|
||||
TEST(SURF)
|
||||
{
|
||||
@@ -294,6 +300,8 @@ TEST(SURF)
|
||||
GPU_OFF;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
TEST(FAST)
|
||||
{
|
||||
|
@@ -44,9 +44,6 @@ GpuMat d_right[2];
|
||||
StereoBM_GPU* bm[2];
|
||||
GpuMat d_result[2];
|
||||
|
||||
// CPU result
|
||||
Mat result;
|
||||
|
||||
static void printHelp()
|
||||
{
|
||||
std::cout << "Usage: stereo_multi_gpu --left <image> --right <image>\n";
|
||||
|
153
samples/gpu/super_resolution.cpp
Normal file
153
samples/gpu/super_resolution.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/core/utility.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/contrib.hpp"
|
||||
#include "opencv2/superres.hpp"
|
||||
#include "opencv2/superres/optical_flow.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::superres;
|
||||
|
||||
#define MEASURE_TIME(op) \
|
||||
{ \
|
||||
TickMeter tm; \
|
||||
tm.start(); \
|
||||
op; \
|
||||
tm.stop(); \
|
||||
cout << tm.getTimeSec() << " sec" << endl; \
|
||||
}
|
||||
|
||||
static Ptr<DenseOpticalFlowExt> createOptFlow(const string& name, bool useGpu)
|
||||
{
|
||||
if (name == "farneback")
|
||||
{
|
||||
if (useGpu)
|
||||
return createOptFlow_Farneback_GPU();
|
||||
else
|
||||
return createOptFlow_Farneback();
|
||||
}
|
||||
else if (name == "simple")
|
||||
return createOptFlow_Simple();
|
||||
else if (name == "tvl1")
|
||||
{
|
||||
if (useGpu)
|
||||
return createOptFlow_DualTVL1_GPU();
|
||||
else
|
||||
return createOptFlow_DualTVL1();
|
||||
}
|
||||
else if (name == "brox")
|
||||
return createOptFlow_Brox_GPU();
|
||||
else if (name == "pyrlk")
|
||||
return createOptFlow_PyrLK_GPU();
|
||||
else
|
||||
{
|
||||
cerr << "Incorrect Optical Flow algorithm - " << name << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
return Ptr<DenseOpticalFlowExt>();
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
CommandLineParser cmd(argc, argv,
|
||||
"{ v video | | Input video }"
|
||||
"{ o output | | Output video }"
|
||||
"{ s scale | 4 | Scale factor }"
|
||||
"{ i iterations | 180 | Iteration count }"
|
||||
"{ t temporal | 4 | Radius of the temporal search area }"
|
||||
"{ f flow | farneback | Optical flow algorithm (farneback, simple, tvl1, brox, pyrlk) }"
|
||||
"{ gpu | false | Use GPU }"
|
||||
"{ h help | false | Print help message }"
|
||||
);
|
||||
|
||||
if (cmd.get<bool>("help"))
|
||||
{
|
||||
cout << "This sample demonstrates Super Resolution algorithms for video sequence" << endl;
|
||||
cmd.printMessage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
const string inputVideoName = cmd.get<string>("video");
|
||||
const string outputVideoName = cmd.get<string>("output");
|
||||
const int scale = cmd.get<int>("scale");
|
||||
const int iterations = cmd.get<int>("iterations");
|
||||
const int temporalAreaRadius = cmd.get<int>("temporal");
|
||||
const string optFlow = cmd.get<string>("flow");
|
||||
const bool useGpu = cmd.get<bool>("gpu");
|
||||
|
||||
Ptr<SuperResolution> superRes;
|
||||
if (useGpu)
|
||||
superRes = createSuperResolution_BTVL1_GPU();
|
||||
else
|
||||
superRes = createSuperResolution_BTVL1();
|
||||
|
||||
superRes->set("scale", scale);
|
||||
superRes->set("iterations", iterations);
|
||||
superRes->set("temporalAreaRadius", temporalAreaRadius);
|
||||
superRes->set("opticalFlow", createOptFlow(optFlow, useGpu));
|
||||
|
||||
Ptr<FrameSource> frameSource;
|
||||
if (useGpu)
|
||||
{
|
||||
// Try to use gpu Video Decoding
|
||||
try
|
||||
{
|
||||
frameSource = createFrameSource_Video_GPU(inputVideoName);
|
||||
Mat frame;
|
||||
frameSource->nextFrame(frame);
|
||||
}
|
||||
catch (const cv::Exception&)
|
||||
{
|
||||
frameSource.release();
|
||||
}
|
||||
}
|
||||
if (frameSource.empty())
|
||||
frameSource = createFrameSource_Video(inputVideoName);
|
||||
|
||||
// skip first frame, it is usually corrupted
|
||||
{
|
||||
Mat frame;
|
||||
frameSource->nextFrame(frame);
|
||||
cout << "Input : " << inputVideoName << " " << frame.size() << endl;
|
||||
cout << "Scale factor : " << scale << endl;
|
||||
cout << "Iterations : " << iterations << endl;
|
||||
cout << "Temporal radius : " << temporalAreaRadius << endl;
|
||||
cout << "Optical Flow : " << optFlow << endl;
|
||||
cout << "Mode : " << (useGpu ? "GPU" : "CPU") << endl;
|
||||
}
|
||||
|
||||
superRes->setInput(frameSource);
|
||||
|
||||
VideoWriter writer;
|
||||
|
||||
for (int i = 0;; ++i)
|
||||
{
|
||||
cout << '[' << setw(3) << i << "] : ";
|
||||
|
||||
Mat result;
|
||||
MEASURE_TIME(superRes->nextFrame(result));
|
||||
|
||||
if (result.empty())
|
||||
break;
|
||||
|
||||
imshow("Super Resolution", result);
|
||||
|
||||
if (waitKey(1000) > 0)
|
||||
break;
|
||||
|
||||
if (!outputVideoName.empty())
|
||||
{
|
||||
if (!writer.isOpened())
|
||||
writer.open(outputVideoName, CV_FOURCC('X', 'V', 'I', 'D'), 25.0, result.size());
|
||||
writer << result;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,9 +1,14 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
#include "opencv2/nonfree/gpu.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
@@ -81,3 +86,13 @@ int main(int argc, char* argv[])
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "OpenCV was built without nonfree module" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user