1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge branch '2.4'

This commit is contained in:
Andrey Kamaev
2013-03-21 20:59:18 +04:00
276 changed files with 11834 additions and 5170 deletions
+4
View File
@@ -11,6 +11,10 @@ add_subdirectory(face-detection)
add_subdirectory(image-manipulations)
add_subdirectory(color-blob-detection)
if (ANDROID_NATIVE_API_LEVEL GREATER 8)
add_subdirectory(native-activity)
endif()
add_subdirectory(tutorial-1-camerapreview)
add_subdirectory(tutorial-2-mixedprocessing)
add_subdirectory(tutorial-3-cameracontrol)
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.opencv.samples.NativeActivity"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
<application android:label="@string/app_name"
android:icon="@drawable/icon"
android:debuggable="true">
<activity android:name="CvNativeActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="android.app.NativeActivity"
android:label="@string/app_name">
<meta-data android:name="android.app.lib_name"
android:value="native_activity" />
</activity>
</application>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>
</manifest>
@@ -0,0 +1,14 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include ../../sdk/native/jni/OpenCV.mk
LOCAL_MODULE := native_activity
LOCAL_SRC_FILES := native.cpp
LOCAL_LDLIBS := -lm -llog -landroid
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
@@ -0,0 +1,2 @@
APP_ABI := armeabi-v7a
APP_PLATFORM := android-9
@@ -0,0 +1,221 @@
#include <android_native_app_glue.h>
#include <errno.h>
#include <jni.h>
#include <sys/time.h>
#include <time.h>
#include <android/log.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <queue>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#define LOG_TAG "OCV:libnative_activity"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
struct Engine
{
android_app* app;
cv::Ptr<cv::VideoCapture> capture;
};
cv::Size calc_optimal_camera_resolution(const char* supported, int width, int height)
{
int frame_width = 0;
int frame_height = 0;
size_t prev_idx = 0;
size_t idx = 0;
float min_diff = FLT_MAX;
do
{
int tmp_width;
int tmp_height;
prev_idx = idx;
while ((supported[idx] != '\0') && (supported[idx] != ','))
idx++;
sscanf(&supported[prev_idx], "%dx%d", &tmp_width, &tmp_height);
int w_diff = width - tmp_width;
int h_diff = height - tmp_height;
if ((h_diff >= 0) && (w_diff >= 0))
{
if ((h_diff <= min_diff) && (tmp_height <= 720))
{
frame_width = tmp_width;
frame_height = tmp_height;
min_diff = h_diff;
}
}
idx++; // to skip coma symbol
} while(supported[idx-1] != '\0');
return cv::Size(frame_width, frame_height);
}
static void engine_draw_frame(Engine* engine, const cv::Mat& frame)
{
if (engine->app->window == NULL)
return; // No window.
ANativeWindow_Buffer buffer;
if (ANativeWindow_lock(engine->app->window, &buffer, NULL) < 0)
{
LOGW("Unable to lock window buffer");
return;
}
void* pixels = buffer.bits;
int left_indent = (buffer.width-frame.cols)/2;
int top_indent = (buffer.height-frame.rows)/2;
for (int yy = top_indent; yy < std::min(frame.rows+top_indent, buffer.height); yy++)
{
unsigned char* line = (unsigned char*)pixels;
memcpy(line+left_indent*4*sizeof(unsigned char), frame.ptr<unsigned char>(yy),
std::min(frame.cols, buffer.width)*4*sizeof(unsigned char));
// go to next line
pixels = (int32_t*)pixels + buffer.stride;
}
ANativeWindow_unlockAndPost(engine->app->window);
}
static void engine_handle_cmd(android_app* app, int32_t cmd)
{
Engine* engine = (Engine*)app->userData;
switch (cmd)
{
case APP_CMD_INIT_WINDOW:
if (app->window != NULL)
{
LOGI("APP_CMD_INIT_WINDOW");
engine->capture = new cv::VideoCapture(0);
union {double prop; const char* name;} u;
u.prop = engine->capture->get(CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING);
int view_width = ANativeWindow_getWidth(app->window);
int view_height = ANativeWindow_getHeight(app->window);
cv::Size camera_resolution;
if (u.name)
camera_resolution = calc_optimal_camera_resolution(u.name, 640, 480);
else
{
LOGE("Cannot get supported camera camera_resolutions");
camera_resolution = cv::Size(ANativeWindow_getWidth(app->window),
ANativeWindow_getHeight(app->window));
}
if ((camera_resolution.width != 0) && (camera_resolution.height != 0))
{
engine->capture->set(CV_CAP_PROP_FRAME_WIDTH, camera_resolution.width);
engine->capture->set(CV_CAP_PROP_FRAME_HEIGHT, camera_resolution.height);
}
float scale = std::min((float)view_width/camera_resolution.width,
(float)view_height/camera_resolution.height);
if (ANativeWindow_setBuffersGeometry(app->window, (int)(view_width/scale),
int(view_height/scale), WINDOW_FORMAT_RGBA_8888) < 0)
{
LOGE("Cannot set pixel format!");
return;
}
LOGI("Camera initialized at resoution %dx%d", camera_resolution.width, camera_resolution.height);
}
break;
case APP_CMD_TERM_WINDOW:
LOGI("APP_CMD_TERM_WINDOW");
engine->capture->release();
break;
}
}
void android_main(android_app* app)
{
Engine engine;
// Make sure glue isn't stripped.
app_dummy();
memset(&engine, 0, sizeof(engine));
app->userData = &engine;
app->onAppCmd = engine_handle_cmd;
engine.app = app;
float fps = 0;
cv::Mat drawing_frame;
std::queue<int64> time_queue;
// loop waiting for stuff to do.
while (1)
{
// Read all pending events.
int ident;
int events;
android_poll_source* source;
// Process system events
while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0)
{
// Process this event.
if (source != NULL)
{
source->process(app, source);
}
// Check if we are exiting.
if (app->destroyRequested != 0)
{
LOGI("Engine thread destroy requested!");
return;
}
}
int64 then;
int64 now = cv::getTickCount();
time_queue.push(now);
// Capture frame from camera and draw it
if (!engine.capture.empty())
{
if (engine.capture->grab())
engine.capture->retrieve(drawing_frame, CV_CAP_ANDROID_COLOR_FRAME_RGBA);
char buffer[256];
sprintf(buffer, "Display performance: %dx%d @ %.3f", drawing_frame.cols, drawing_frame.rows, fps);
cv::putText(drawing_frame, std::string(buffer), cv::Point(8,64),
cv::FONT_HERSHEY_COMPLEX_SMALL, 1, cv::Scalar(0,255,0,255));
engine_draw_frame(&engine, drawing_frame);
}
if (time_queue.size() >= 2)
then = time_queue.front();
else
then = 0;
if (time_queue.size() >= 25)
time_queue.pop();
fps = time_queue.size() * (float)cv::getTickFrequency() / (now-then);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">OCV Native Activity</string>
</resources>
@@ -0,0 +1,44 @@
package org.opencv.samples.NativeActivity;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
public class CvNativeActivity extends Activity {
private static final String TAG = "OCVSample::Activity";
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
System.loadLibrary("native_activity");
Intent intent = new Intent(CvNativeActivity.this, android.app.NativeActivity.class);
CvNativeActivity.this.startActivity(intent);
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
public CvNativeActivity() {
Log.i(TAG, "Instantiated new " + this.getClass());
}
@Override
public void onResume()
{
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);
}
}
@@ -4,8 +4,8 @@
android:layout_height="match_parent" >
<org.opencv.samples.tutorial3.Tutorial3View
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:id="@+id/tutorial3_activity_java_surface_view" />
+2 -2
View File
@@ -16,7 +16,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
ocv_include_directories("${OpenCV_SOURCE_DIR}/include")#for opencv.hpp
ocv_include_modules(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
if (HAVE_opencv_gpu)
if(HAVE_opencv_gpu)
ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/include")
endif()
@@ -41,7 +41,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
add_executable(${the_target} ${srcs})
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
if (HAVE_opencv_gpu)
if(HAVE_opencv_gpu)
target_link_libraries(${the_target} opencv_gpu)
endif()
+35 -12
View File
@@ -131,7 +131,7 @@ int build_rtrees_classifier( char* data_filename,
printf( "Could not read the classifier %s\n", filename_to_load );
return -1;
}
printf( "The classifier %s is loaded.\n", data_filename );
printf( "The classifier %s is loaded.\n", filename_to_load );
}
else
{
@@ -262,7 +262,7 @@ int build_boost_classifier( char* data_filename,
printf( "Could not read the classifier %s\n", filename_to_load );
return -1;
}
printf( "The classifier %s is loaded.\n", data_filename );
printf( "The classifier %s is loaded.\n", filename_to_load );
}
else
{
@@ -403,7 +403,7 @@ int build_mlp_classifier( char* data_filename,
printf( "Could not read the classifier %s\n", filename_to_load );
return -1;
}
printf( "The classifier %s is loaded.\n", data_filename );
printf( "The classifier %s is loaded.\n", filename_to_load );
}
else
{
@@ -639,10 +639,11 @@ int build_nbayes_classifier( char* data_filename )
}
static
int build_svm_classifier( char* data_filename )
int build_svm_classifier( char* data_filename, const char* filename_to_save, const char* filename_to_load )
{
CvMat* data = 0;
CvMat* responses = 0;
CvMat* train_resp = 0;
CvMat train_data;
int nsamples_all = 0, ntrain_samples = 0;
int var_count;
@@ -666,13 +667,29 @@ int build_svm_classifier( char* data_filename )
ntrain_samples = (int)(nsamples_all*0.1);
var_count = data->cols;
// train classifier
printf( "Training the classifier (may take a few minutes)...\n");
cvGetRows( data, &train_data, 0, ntrain_samples );
CvMat* train_resp = cvCreateMat( ntrain_samples, 1, CV_32FC1);
for (int i = 0; i < ntrain_samples; i++)
train_resp->data.fl[i] = responses->data.fl[i];
svm.train(&train_data, train_resp, 0, 0, param);
// Create or load Random Trees classifier
if( filename_to_load )
{
// load classifier from the specified file
svm.load( filename_to_load );
ntrain_samples = 0;
if( svm.get_var_count() == 0 )
{
printf( "Could not read the classifier %s\n", filename_to_load );
return -1;
}
printf( "The classifier %s is loaded.\n", filename_to_load );
}
else
{
// train classifier
printf( "Training the classifier (may take a few minutes)...\n");
cvGetRows( data, &train_data, 0, ntrain_samples );
train_resp = cvCreateMat( ntrain_samples, 1, CV_32FC1);
for (int i = 0; i < ntrain_samples; i++)
train_resp->data.fl[i] = responses->data.fl[i];
svm.train(&train_data, train_resp, 0, 0, param);
}
// classification
std::vector<float> _sample(var_count * (nsamples_all - ntrain_samples));
@@ -691,7 +708,10 @@ int build_svm_classifier( char* data_filename )
CvMat *result = cvCreateMat(1, nsamples_all - ntrain_samples, CV_32FC1);
printf("Classification (may take a few minutes)...\n");
double t = (double)cvGetTickCount();
svm.predict(&sample, result);
t = (double)cvGetTickCount() - t;
printf("Prediction type: %gms\n", t/(cvGetTickFrequency()*1000.));
int true_resp = 0;
for (int i = 0; i < nsamples_all - ntrain_samples; i++)
@@ -702,6 +722,9 @@ int build_svm_classifier( char* data_filename )
printf("true_resp = %f%%\n", (float)true_resp / (nsamples_all - ntrain_samples) * 100);
if( filename_to_save )
svm.save( filename_to_save );
cvReleaseMat( &train_resp );
cvReleaseMat( &result );
cvReleaseMat( &data );
@@ -772,7 +795,7 @@ int main( int argc, char *argv[] )
method == 4 ?
build_nbayes_classifier( data_filename) :
method == 5 ?
build_svm_classifier( data_filename ):
build_svm_classifier( data_filename, filename_to_save, filename_to_load ):
-1) < 0)
{
help();
+1 -1
View File
@@ -356,7 +356,7 @@ int main(int argc, char* argv[])
Ptr<FeaturesFinder> finder;
if (features_type == "surf")
{
#ifdef HAVE_OPENCV_GPU
#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU)
if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0)
finder = new SurfFeaturesFinderGpu();
else
+8 -1
View File
@@ -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}"
+29 -3
View File
@@ -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);
+6 -1
View File
@@ -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();
-3
View File
@@ -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";
+8
View File
@@ -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")
+9 -1
View File
@@ -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)
{
-3
View File
@@ -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
View 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;
}
+15
View File
@@ -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
-4
View File
@@ -17,10 +17,6 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
ocv_include_directories(${OPENCL_INCLUDE_DIR})
endif()
if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
endif()
# ---------------------------------------------
# Define executable targets
# ---------------------------------------------
Binary file not shown.

After

Width:  |  Height:  |  Size: 720 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 722 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

+1
View File
@@ -16,6 +16,7 @@
#define USE_OPENCL
#ifdef USE_OPENCL
#include "opencv2/ocl.hpp"
#include "opencv2/nonfree/ocl.hpp"
#endif
#define TAB " "
+1
View File
@@ -50,6 +50,7 @@
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/ocl/ocl.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/nonfree/ocl.hpp"
#include "opencv2/calib3d/calib3d.hpp"
using namespace std;