Merge remote-tracking branch 'upstream/master' into svm_hog
@@ -1,3 +1,10 @@
|
||||
# Detect if we want to build samples with library binaries or not
|
||||
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_LIST_DIR)
|
||||
#
|
||||
# BUILD CASE 1: Build samples with library sources
|
||||
#
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# CMake file for samples. See root CMakeLists.txt
|
||||
#
|
||||
@@ -11,3 +18,51 @@ add_subdirectory(ocl)
|
||||
if(ANDROID AND BUILD_ANDROID_EXAMPLES)
|
||||
add_subdirectory(android)
|
||||
endif()
|
||||
|
||||
|
||||
#
|
||||
# END OF BUILD CASE 1: Build samples with library sources
|
||||
#
|
||||
else()
|
||||
#
|
||||
# BUILD CASE 2: Build samples with library binaries
|
||||
#
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(samples C CXX)
|
||||
option(BUILD_EXAMPLES "Build samples" ON)
|
||||
|
||||
find_package(OpenCV REQUIRED)
|
||||
|
||||
if(MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
|
||||
if(NOT OpenCV_SHARED)
|
||||
foreach(flag_var
|
||||
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
|
||||
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
|
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
if(${flag_var} MATCHES "/MD")
|
||||
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
|
||||
endif()
|
||||
if(${flag_var} MATCHES "/MDd")
|
||||
string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
|
||||
endif()
|
||||
endforeach(flag_var)
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcrtd.lib")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmtd.lib")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_subdirectory(c)
|
||||
add_subdirectory(cpp)
|
||||
add_subdirectory(ocl)
|
||||
# FIXIT: can't use cvconfig.h in samples: add_subdirectory(gpu)
|
||||
|
||||
#
|
||||
# END OF BUILD CASE 2: Build samples with library binaries
|
||||
#
|
||||
endif()
|
||||
@@ -2,19 +2,19 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>de.rwth-aachen.ient.FaceTracker</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>de.rwth-aachen.ient.FaceTracker</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -4,4 +4,4 @@ build.xml
|
||||
local.properties
|
||||
proguard-project.txt
|
||||
project.properties
|
||||
default.properties
|
||||
default.properties
|
||||
|
||||
@@ -9,6 +9,7 @@ ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-declarations)
|
||||
add_subdirectory(15-puzzle)
|
||||
add_subdirectory(face-detection)
|
||||
add_subdirectory(image-manipulations)
|
||||
add_subdirectory(camera-calibration)
|
||||
add_subdirectory(color-blob-detection)
|
||||
add_subdirectory(tutorial-1-camerapreview)
|
||||
add_subdirectory(tutorial-2-mixedprocessing)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>OpenCV Sample - camera-calibration</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.opencv.samples.cameracalibration"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<application
|
||||
android:label="@string/app_name"
|
||||
android:icon="@drawable/icon"
|
||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
|
||||
|
||||
<activity android:name="CameraCalibrationActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="landscape"
|
||||
android:configChanges="keyboardHidden|orientation">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
<supports-screens android:resizeable="true"
|
||||
android:smallScreens="true"
|
||||
android:normalScreens="true"
|
||||
android:largeScreens="true"
|
||||
android:anyDensity="true" />
|
||||
|
||||
<uses-sdk android:minSdkVersion="8" />
|
||||
|
||||
<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,6 @@
|
||||
set(sample example-camera-calibration)
|
||||
|
||||
add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11 ${ANDROID_SDK_TARGET})
|
||||
if(TARGET ${sample})
|
||||
add_dependencies(opencv_android_examples ${sample})
|
||||
endif()
|
||||
|
After Width: | Height: | Size: 2.1 KiB |
@@ -0,0 +1,12 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:opencv="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<org.opencv.android.JavaCameraView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:id="@+id/camera_calibration_java_surface_view" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<group android:checkableBehavior="single">
|
||||
<item android:id="@+id/calibrate"
|
||||
android:title="@string/action_calibrate"
|
||||
android:showAsAction="ifRoom|withText" />
|
||||
<item android:id="@+id/preview_mode"
|
||||
android:title="@string/preview_mode">
|
||||
<menu>
|
||||
<group android:checkableBehavior="single">
|
||||
<item android:id="@+id/calibration"
|
||||
android:title="@string/calibration"
|
||||
android:checked="true" />
|
||||
<item android:id="@+id/undistortion"
|
||||
android:title="@string/undistortion" />
|
||||
<item android:id="@+id/comparison"
|
||||
android:title="@string/comparison" />
|
||||
</group>
|
||||
</menu>
|
||||
</item>
|
||||
</group>
|
||||
</menu>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">OCV Camera Calibration</string>
|
||||
<string name="action_calibrate">Calibrate</string>
|
||||
<string name="calibration">Calibration</string>
|
||||
<string name="undistortion">Undistortion</string>
|
||||
<string name="comparison">Comparison</string>
|
||||
<string name="preview_mode">Preview mode</string>
|
||||
<string name="calibration_successful">Successfully calibrated!\nAvg. re-projection error:</string>
|
||||
<string name="calibration_unsuccessful">Unsuccessful calibration.\nTry again</string>
|
||||
<string name="more_samples">Please, capture more samples</string>
|
||||
<string name="calibrating">Calibrating...</string>
|
||||
<string name="please_wait">Please, wait</string>
|
||||
<string name="original">Original</string>
|
||||
<string name="undistorted">Undistorted</string>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,69 @@
|
||||
package org.opencv.samples.cameracalibration;
|
||||
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
public abstract class CalibrationResult {
|
||||
private static final String TAG = "OCVSample::CalibrationResult";
|
||||
|
||||
private static final int CAMERA_MATRIX_ROWS = 3;
|
||||
private static final int CAMERA_MATRIX_COLS = 3;
|
||||
private static final int DISTORTION_COEFFICIENTS_SIZE = 5;
|
||||
|
||||
public static void save(Activity activity, Mat cameraMatrix, Mat distortionCoefficients) {
|
||||
SharedPreferences sharedPref = activity.getPreferences(Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
|
||||
double[] cameraMatrixArray = new double[CAMERA_MATRIX_ROWS * CAMERA_MATRIX_COLS];
|
||||
cameraMatrix.get(0, 0, cameraMatrixArray);
|
||||
for (int i = 0; i < CAMERA_MATRIX_ROWS; i++) {
|
||||
for (int j = 0; j < CAMERA_MATRIX_COLS; j++) {
|
||||
Integer id = i * CAMERA_MATRIX_ROWS + j;
|
||||
editor.putFloat(id.toString(), (float)cameraMatrixArray[id]);
|
||||
}
|
||||
}
|
||||
|
||||
double[] distortionCoefficientsArray = new double[DISTORTION_COEFFICIENTS_SIZE];
|
||||
distortionCoefficients.get(0, 0, distortionCoefficientsArray);
|
||||
int shift = CAMERA_MATRIX_ROWS * CAMERA_MATRIX_COLS;
|
||||
for (Integer i = shift; i < DISTORTION_COEFFICIENTS_SIZE + shift; i++) {
|
||||
editor.putFloat(i.toString(), (float)distortionCoefficientsArray[i-shift]);
|
||||
}
|
||||
|
||||
editor.commit();
|
||||
Log.i(TAG, "Saved camera matrix: " + cameraMatrix.dump());
|
||||
Log.i(TAG, "Saved distortion coefficients: " + distortionCoefficients.dump());
|
||||
}
|
||||
|
||||
public static boolean tryLoad(Activity activity, Mat cameraMatrix, Mat distortionCoefficients) {
|
||||
SharedPreferences sharedPref = activity.getPreferences(Context.MODE_PRIVATE);
|
||||
if (sharedPref.getFloat("0", -1) == -1) {
|
||||
Log.i(TAG, "No previous calibration results found");
|
||||
return false;
|
||||
}
|
||||
|
||||
double[] cameraMatrixArray = new double[CAMERA_MATRIX_ROWS * CAMERA_MATRIX_COLS];
|
||||
for (int i = 0; i < CAMERA_MATRIX_ROWS; i++) {
|
||||
for (int j = 0; j < CAMERA_MATRIX_COLS; j++) {
|
||||
Integer id = i * CAMERA_MATRIX_ROWS + j;
|
||||
cameraMatrixArray[id] = sharedPref.getFloat(id.toString(), -1);
|
||||
}
|
||||
}
|
||||
cameraMatrix.put(0, 0, cameraMatrixArray);
|
||||
Log.i(TAG, "Loaded camera matrix: " + cameraMatrix.dump());
|
||||
|
||||
double[] distortionCoefficientsArray = new double[DISTORTION_COEFFICIENTS_SIZE];
|
||||
int shift = CAMERA_MATRIX_ROWS * CAMERA_MATRIX_COLS;
|
||||
for (Integer i = shift; i < DISTORTION_COEFFICIENTS_SIZE + shift; i++) {
|
||||
distortionCoefficientsArray[i - shift] = sharedPref.getFloat(i.toString(), -1);
|
||||
}
|
||||
distortionCoefficients.put(0, 0, distortionCoefficientsArray);
|
||||
Log.i(TAG, "Loaded distortion coefficients: " + distortionCoefficients.dump());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
// This sample is based on "Camera calibration With OpenCV" tutorial:
|
||||
// http://docs.opencv.org/doc/tutorials/calib3d/camera_calibration/camera_calibration.html
|
||||
//
|
||||
// It uses standard OpenCV asymmetric circles grid pattern 11x4:
|
||||
// https://github.com/Itseez/opencv/blob/2.4/doc/acircles_pattern.png.
|
||||
// The results are the camera matrix and 5 distortion coefficients.
|
||||
//
|
||||
// Tap on highlighted pattern to capture pattern corners for calibration.
|
||||
// Move pattern along the whole screen and capture data.
|
||||
//
|
||||
// When you've captured necessary amount of pattern corners (usually ~20 are enough),
|
||||
// press "Calibrate" button for performing camera calibration.
|
||||
|
||||
package org.opencv.samples.cameracalibration;
|
||||
|
||||
import org.opencv.android.BaseLoaderCallback;
|
||||
import org.opencv.android.CameraBridgeViewBase;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
|
||||
import org.opencv.android.LoaderCallbackInterface;
|
||||
import org.opencv.android.OpenCVLoader;
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.res.Resources;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class CameraCalibrationActivity extends Activity implements CvCameraViewListener2, OnTouchListener {
|
||||
private static final String TAG = "OCVSample::Activity";
|
||||
|
||||
private CameraBridgeViewBase mOpenCvCameraView;
|
||||
private CameraCalibrator mCalibrator;
|
||||
private OnCameraFrameRender mOnCameraFrameRender;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
|
||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
mOpenCvCameraView.enableView();
|
||||
mOpenCvCameraView.setOnTouchListener(CameraCalibrationActivity.this);
|
||||
} break;
|
||||
default:
|
||||
{
|
||||
super.onManagerConnected(status);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public CameraCalibrationActivity() {
|
||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "called onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
setContentView(R.layout.camera_calibration_surface_view);
|
||||
|
||||
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.camera_calibration_java_surface_view);
|
||||
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
|
||||
mOpenCvCameraView.setCvCameraViewListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.disableView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mLoaderCallback);
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.disableView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
getMenuInflater().inflate(R.menu.calibration, menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu (Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
menu.findItem(R.id.preview_mode).setEnabled(true);
|
||||
if (!mCalibrator.isCalibrated())
|
||||
menu.findItem(R.id.preview_mode).setEnabled(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.calibration:
|
||||
mOnCameraFrameRender =
|
||||
new OnCameraFrameRender(new CalibrationFrameRender(mCalibrator));
|
||||
item.setChecked(true);
|
||||
return true;
|
||||
case R.id.undistortion:
|
||||
mOnCameraFrameRender =
|
||||
new OnCameraFrameRender(new UndistortionFrameRender(mCalibrator));
|
||||
item.setChecked(true);
|
||||
return true;
|
||||
case R.id.comparison:
|
||||
mOnCameraFrameRender =
|
||||
new OnCameraFrameRender(new ComparisonFrameRender(mCalibrator, mWidth, mHeight, getResources()));
|
||||
item.setChecked(true);
|
||||
return true;
|
||||
case R.id.calibrate:
|
||||
final Resources res = getResources();
|
||||
if (mCalibrator.getCornersBufferSize() < 2) {
|
||||
(Toast.makeText(this, res.getString(R.string.more_samples), Toast.LENGTH_SHORT)).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
mOnCameraFrameRender = new OnCameraFrameRender(new PreviewFrameRender());
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
private ProgressDialog calibrationProgress;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
calibrationProgress = new ProgressDialog(CameraCalibrationActivity.this);
|
||||
calibrationProgress.setTitle(res.getString(R.string.calibrating));
|
||||
calibrationProgress.setMessage(res.getString(R.string.please_wait));
|
||||
calibrationProgress.setCancelable(false);
|
||||
calibrationProgress.setIndeterminate(true);
|
||||
calibrationProgress.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... arg0) {
|
||||
mCalibrator.calibrate();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
calibrationProgress.dismiss();
|
||||
mCalibrator.clearCorners();
|
||||
mOnCameraFrameRender = new OnCameraFrameRender(new CalibrationFrameRender(mCalibrator));
|
||||
String resultMessage = (mCalibrator.isCalibrated()) ?
|
||||
res.getString(R.string.calibration_successful) + " " + mCalibrator.getAvgReprojectionError() :
|
||||
res.getString(R.string.calibration_unsuccessful);
|
||||
(Toast.makeText(CameraCalibrationActivity.this, resultMessage, Toast.LENGTH_SHORT)).show();
|
||||
|
||||
if (mCalibrator.isCalibrated()) {
|
||||
CalibrationResult.save(CameraCalibrationActivity.this,
|
||||
mCalibrator.getCameraMatrix(), mCalibrator.getDistortionCoefficients());
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void onCameraViewStarted(int width, int height) {
|
||||
if (mWidth != width || mHeight != height) {
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
mCalibrator = new CameraCalibrator(mWidth, mHeight);
|
||||
if (CalibrationResult.tryLoad(this, mCalibrator.getCameraMatrix(), mCalibrator.getDistortionCoefficients())) {
|
||||
mCalibrator.setCalibrated();
|
||||
}
|
||||
|
||||
mOnCameraFrameRender = new OnCameraFrameRender(new CalibrationFrameRender(mCalibrator));
|
||||
}
|
||||
}
|
||||
|
||||
public void onCameraViewStopped() {
|
||||
}
|
||||
|
||||
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
|
||||
return mOnCameraFrameRender.render(inputFrame);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
Log.d(TAG, "onTouch invoked");
|
||||
|
||||
mCalibrator.addCorners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package org.opencv.samples.cameracalibration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.calib3d.Calib3d;
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfDouble;
|
||||
import org.opencv.core.MatOfPoint2f;
|
||||
import org.opencv.core.MatOfPoint3f;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.Size;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class CameraCalibrator {
|
||||
private static final String TAG = "OCVSample::CameraCalibrator";
|
||||
|
||||
private final Size mPatternSize = new Size(4, 11);
|
||||
private final int mCornersSize = (int)(mPatternSize.width * mPatternSize.height);
|
||||
private boolean mPatternWasFound = false;
|
||||
private MatOfPoint2f mCorners = new MatOfPoint2f();
|
||||
private List<Mat> mCornersBuffer = new ArrayList<Mat>();
|
||||
private boolean mIsCalibrated = false;
|
||||
|
||||
private Mat mCameraMatrix = new Mat();
|
||||
private Mat mDistortionCoefficients = new Mat();
|
||||
private int mFlags;
|
||||
private double mRms;
|
||||
private double mSquareSize = 0.0181;
|
||||
private Size mImageSize;
|
||||
|
||||
public CameraCalibrator(int width, int height) {
|
||||
mImageSize = new Size(width, height);
|
||||
mFlags = Calib3d.CALIB_FIX_PRINCIPAL_POINT +
|
||||
Calib3d.CALIB_ZERO_TANGENT_DIST +
|
||||
Calib3d.CALIB_FIX_ASPECT_RATIO +
|
||||
Calib3d.CALIB_FIX_K4 +
|
||||
Calib3d.CALIB_FIX_K5;
|
||||
Mat.eye(3, 3, CvType.CV_64FC1).copyTo(mCameraMatrix);
|
||||
mCameraMatrix.put(0, 0, 1.0);
|
||||
Mat.zeros(5, 1, CvType.CV_64FC1).copyTo(mDistortionCoefficients);
|
||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||
}
|
||||
|
||||
public void processFrame(Mat grayFrame, Mat rgbaFrame) {
|
||||
findPattern(grayFrame);
|
||||
renderFrame(rgbaFrame);
|
||||
}
|
||||
|
||||
public void calibrate() {
|
||||
ArrayList<Mat> rvecs = new ArrayList<Mat>();
|
||||
ArrayList<Mat> tvecs = new ArrayList<Mat>();
|
||||
Mat reprojectionErrors = new Mat();
|
||||
ArrayList<Mat> objectPoints = new ArrayList<Mat>();
|
||||
objectPoints.add(Mat.zeros(mCornersSize, 1, CvType.CV_32FC3));
|
||||
calcBoardCornerPositions(objectPoints.get(0));
|
||||
for (int i = 1; i < mCornersBuffer.size(); i++) {
|
||||
objectPoints.add(objectPoints.get(0));
|
||||
}
|
||||
|
||||
Calib3d.calibrateCamera(objectPoints, mCornersBuffer, mImageSize,
|
||||
mCameraMatrix, mDistortionCoefficients, rvecs, tvecs, mFlags);
|
||||
|
||||
mIsCalibrated = Core.checkRange(mCameraMatrix)
|
||||
&& Core.checkRange(mDistortionCoefficients);
|
||||
|
||||
mRms = computeReprojectionErrors(objectPoints, rvecs, tvecs, reprojectionErrors);
|
||||
Log.i(TAG, String.format("Average re-projection error: %f", mRms));
|
||||
Log.i(TAG, "Camera matrix: " + mCameraMatrix.dump());
|
||||
Log.i(TAG, "Distortion coefficients: " + mDistortionCoefficients.dump());
|
||||
}
|
||||
|
||||
public void clearCorners() {
|
||||
mCornersBuffer.clear();
|
||||
}
|
||||
|
||||
private void calcBoardCornerPositions(Mat corners) {
|
||||
final int cn = 3;
|
||||
float positions[] = new float[mCornersSize * cn];
|
||||
|
||||
for (int i = 0; i < mPatternSize.height; i++) {
|
||||
for (int j = 0; j < mPatternSize.width * cn; j += cn) {
|
||||
positions[(int) (i * mPatternSize.width * cn + j + 0)] =
|
||||
(2 * (j / cn) + i % 2) * (float) mSquareSize;
|
||||
positions[(int) (i * mPatternSize.width * cn + j + 1)] =
|
||||
i * (float) mSquareSize;
|
||||
positions[(int) (i * mPatternSize.width * cn + j + 2)] = 0;
|
||||
}
|
||||
}
|
||||
corners.create(mCornersSize, 1, CvType.CV_32FC3);
|
||||
corners.put(0, 0, positions);
|
||||
}
|
||||
|
||||
private double computeReprojectionErrors(List<Mat> objectPoints,
|
||||
List<Mat> rvecs, List<Mat> tvecs, Mat perViewErrors) {
|
||||
MatOfPoint2f cornersProjected = new MatOfPoint2f();
|
||||
double totalError = 0;
|
||||
double error;
|
||||
float viewErrors[] = new float[objectPoints.size()];
|
||||
|
||||
MatOfDouble distortionCoefficients = new MatOfDouble(mDistortionCoefficients);
|
||||
int totalPoints = 0;
|
||||
for (int i = 0; i < objectPoints.size(); i++) {
|
||||
MatOfPoint3f points = new MatOfPoint3f(objectPoints.get(i));
|
||||
Calib3d.projectPoints(points, rvecs.get(i), tvecs.get(i),
|
||||
mCameraMatrix, distortionCoefficients, cornersProjected);
|
||||
error = Core.norm(mCornersBuffer.get(i), cornersProjected, Core.NORM_L2);
|
||||
|
||||
int n = objectPoints.get(i).rows();
|
||||
viewErrors[i] = (float) Math.sqrt(error * error / n);
|
||||
totalError += error * error;
|
||||
totalPoints += n;
|
||||
}
|
||||
perViewErrors.create(objectPoints.size(), 1, CvType.CV_32FC1);
|
||||
perViewErrors.put(0, 0, viewErrors);
|
||||
|
||||
return Math.sqrt(totalError / totalPoints);
|
||||
}
|
||||
|
||||
private void findPattern(Mat grayFrame) {
|
||||
mPatternWasFound = Calib3d.findCirclesGrid(grayFrame, mPatternSize,
|
||||
mCorners, Calib3d.CALIB_CB_ASYMMETRIC_GRID);
|
||||
}
|
||||
|
||||
public void addCorners() {
|
||||
if (mPatternWasFound) {
|
||||
mCornersBuffer.add(mCorners.clone());
|
||||
}
|
||||
}
|
||||
|
||||
private void drawPoints(Mat rgbaFrame) {
|
||||
Calib3d.drawChessboardCorners(rgbaFrame, mPatternSize, mCorners, mPatternWasFound);
|
||||
}
|
||||
|
||||
private void renderFrame(Mat rgbaFrame) {
|
||||
drawPoints(rgbaFrame);
|
||||
|
||||
Core.putText(rgbaFrame, "Captured: " + mCornersBuffer.size(), new Point(rgbaFrame.cols() / 3 * 2, rgbaFrame.rows() * 0.1),
|
||||
Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(255, 255, 0));
|
||||
}
|
||||
|
||||
public Mat getCameraMatrix() {
|
||||
return mCameraMatrix;
|
||||
}
|
||||
|
||||
public Mat getDistortionCoefficients() {
|
||||
return mDistortionCoefficients;
|
||||
}
|
||||
|
||||
public int getCornersBufferSize() {
|
||||
return mCornersBuffer.size();
|
||||
}
|
||||
|
||||
public double getAvgReprojectionError() {
|
||||
return mRms;
|
||||
}
|
||||
|
||||
public boolean isCalibrated() {
|
||||
return mIsCalibrated;
|
||||
}
|
||||
|
||||
public void setCalibrated() {
|
||||
mIsCalibrated = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package org.opencv.samples.cameracalibration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Range;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
import android.content.res.Resources;
|
||||
|
||||
abstract class FrameRender {
|
||||
protected CameraCalibrator mCalibrator;
|
||||
|
||||
public abstract Mat render(CvCameraViewFrame inputFrame);
|
||||
}
|
||||
|
||||
class PreviewFrameRender extends FrameRender {
|
||||
@Override
|
||||
public Mat render(CvCameraViewFrame inputFrame) {
|
||||
return inputFrame.rgba();
|
||||
}
|
||||
}
|
||||
|
||||
class CalibrationFrameRender extends FrameRender {
|
||||
public CalibrationFrameRender(CameraCalibrator calibrator) {
|
||||
mCalibrator = calibrator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mat render(CvCameraViewFrame inputFrame) {
|
||||
Mat rgbaFrame = inputFrame.rgba();
|
||||
Mat grayFrame = inputFrame.gray();
|
||||
mCalibrator.processFrame(grayFrame, rgbaFrame);
|
||||
|
||||
return rgbaFrame;
|
||||
}
|
||||
}
|
||||
|
||||
class UndistortionFrameRender extends FrameRender {
|
||||
public UndistortionFrameRender(CameraCalibrator calibrator) {
|
||||
mCalibrator = calibrator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mat render(CvCameraViewFrame inputFrame) {
|
||||
Mat renderedFrame = new Mat(inputFrame.rgba().size(), inputFrame.rgba().type());
|
||||
Imgproc.undistort(inputFrame.rgba(), renderedFrame,
|
||||
mCalibrator.getCameraMatrix(), mCalibrator.getDistortionCoefficients());
|
||||
|
||||
return renderedFrame;
|
||||
}
|
||||
}
|
||||
|
||||
class ComparisonFrameRender extends FrameRender {
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private Resources mResources;
|
||||
public ComparisonFrameRender(CameraCalibrator calibrator, int width, int height, Resources resources) {
|
||||
mCalibrator = calibrator;
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
mResources = resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mat render(CvCameraViewFrame inputFrame) {
|
||||
Mat undistortedFrame = new Mat(inputFrame.rgba().size(), inputFrame.rgba().type());
|
||||
Imgproc.undistort(inputFrame.rgba(), undistortedFrame,
|
||||
mCalibrator.getCameraMatrix(), mCalibrator.getDistortionCoefficients());
|
||||
|
||||
Mat comparisonFrame = inputFrame.rgba();
|
||||
undistortedFrame.colRange(new Range(0, mWidth / 2)).copyTo(comparisonFrame.colRange(new Range(mWidth / 2, mWidth)));
|
||||
List<MatOfPoint> border = new ArrayList<MatOfPoint>();
|
||||
final int shift = (int)(mWidth * 0.005);
|
||||
border.add(new MatOfPoint(new Point(mWidth / 2 - shift, 0), new Point(mWidth / 2 + shift, 0),
|
||||
new Point(mWidth / 2 + shift, mHeight), new Point(mWidth / 2 - shift, mHeight)));
|
||||
Core.fillPoly(comparisonFrame, border, new Scalar(255, 255, 255));
|
||||
|
||||
Core.putText(comparisonFrame, mResources.getString(R.string.original), new Point(mWidth * 0.1, mHeight * 0.1),
|
||||
Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(255, 255, 0));
|
||||
Core.putText(comparisonFrame, mResources.getString(R.string.undistorted), new Point(mWidth * 0.6, mHeight * 0.1),
|
||||
Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(255, 255, 0));
|
||||
|
||||
return comparisonFrame;
|
||||
}
|
||||
}
|
||||
|
||||
class OnCameraFrameRender {
|
||||
private FrameRender mFrameRender;
|
||||
public OnCameraFrameRender(FrameRender frameRender) {
|
||||
mFrameRender = frameRender;
|
||||
}
|
||||
public Mat render(CvCameraViewFrame inputFrame) {
|
||||
return mFrameRender.render(inputFrame);
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,3 @@ add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenC
|
||||
if(TARGET ${sample})
|
||||
add_dependencies(opencv_android_examples ${sample})
|
||||
endif()
|
||||
|
||||
|
||||
@@ -187,4 +187,4 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe
|
||||
|
||||
return new Scalar(pointMatRgba.get(0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,3 @@ add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenC
|
||||
if(TARGET ${sample})
|
||||
add_dependencies(opencv_android_examples ${sample})
|
||||
endif()
|
||||
|
||||
|
||||
@@ -13,4 +13,4 @@ LOCAL_LDLIBS += -llog -ldl
|
||||
|
||||
LOCAL_MODULE := detection_based_tracker
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
Detector(detector)
|
||||
{
|
||||
LOGD("CascadeDetectorAdapter::Detect::Detect");
|
||||
CV_Assert(!detector.empty());
|
||||
CV_Assert(detector);
|
||||
}
|
||||
|
||||
void detect(const cv::Mat &Image, std::vector<cv::Rect> &objects)
|
||||
@@ -57,11 +57,11 @@ struct DetectorAgregator
|
||||
mainDetector(_mainDetector),
|
||||
trackingDetector(_trackingDetector)
|
||||
{
|
||||
CV_Assert(!_mainDetector.empty());
|
||||
CV_Assert(!_trackingDetector.empty());
|
||||
CV_Assert(_mainDetector);
|
||||
CV_Assert(_trackingDetector);
|
||||
|
||||
DetectionBasedTracker::Parameters DetectorParams;
|
||||
tracker = new DetectionBasedTracker(mainDetector.ptr<DetectionBasedTracker::IDetector>(), trackingDetector.ptr<DetectionBasedTracker::IDetector>(), DetectorParams);
|
||||
tracker = makePtr<DetectionBasedTracker>(mainDetector, trackingDetector, DetectorParams);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -77,8 +77,10 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker
|
||||
|
||||
try
|
||||
{
|
||||
cv::Ptr<CascadeDetectorAdapter> mainDetector = new CascadeDetectorAdapter(new CascadeClassifier(stdFileName));
|
||||
cv::Ptr<CascadeDetectorAdapter> trackingDetector = new CascadeDetectorAdapter(new CascadeClassifier(stdFileName));
|
||||
cv::Ptr<CascadeDetectorAdapter> mainDetector = makePtr<CascadeDetectorAdapter>(
|
||||
makePtr<CascadeClassifier>(stdFileName));
|
||||
cv::Ptr<CascadeDetectorAdapter> trackingDetector = makePtr<CascadeDetectorAdapter>(
|
||||
makePtr<CascadeClassifier>(stdFileName));
|
||||
result = (jlong)new DetectorAgregator(mainDetector, trackingDetector);
|
||||
if (faceSize > 0)
|
||||
{
|
||||
@@ -98,7 +100,7 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker
|
||||
{
|
||||
LOGD("nativeCreateObject caught unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeCreateObject(...)}");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code of DetectionBasedTracker.nativeCreateObject()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -131,7 +133,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_
|
||||
{
|
||||
LOGD("nativeDestroyObject caught unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDestroyObject(...)}");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code of DetectionBasedTracker.nativeDestroyObject()");
|
||||
}
|
||||
LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDestroyObject exit");
|
||||
}
|
||||
@@ -157,7 +159,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_
|
||||
{
|
||||
LOGD("nativeStart caught unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStart(...)}");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code of DetectionBasedTracker.nativeStart()");
|
||||
}
|
||||
LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStart exit");
|
||||
}
|
||||
@@ -183,7 +185,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_
|
||||
{
|
||||
LOGD("nativeStop caught unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStop(...)}");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code of DetectionBasedTracker.nativeStop()");
|
||||
}
|
||||
LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStop exit");
|
||||
}
|
||||
@@ -213,7 +215,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_
|
||||
{
|
||||
LOGD("nativeSetFaceSize caught unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeSetFaceSize(...)}");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code of DetectionBasedTracker.nativeSetFaceSize()");
|
||||
}
|
||||
LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeSetFaceSize -- END");
|
||||
}
|
||||
@@ -243,7 +245,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_
|
||||
{
|
||||
LOGD("nativeDetect caught unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDetect(...)}");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code DetectionBasedTracker.nativeDetect()");
|
||||
}
|
||||
LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDetect END");
|
||||
}
|
||||
|
||||
@@ -24,4 +24,3 @@ int main(int argc, char* argv[])
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,17 +48,12 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView
|
||||
private CameraBridgeViewBase mOpenCvCameraView;
|
||||
|
||||
private Size mSize0;
|
||||
private Size mSizeRgba;
|
||||
private Size mSizeRgbaInner;
|
||||
|
||||
private Mat mRgba;
|
||||
private Mat mGray;
|
||||
private Mat mIntermediateMat;
|
||||
private Mat mHist;
|
||||
private Mat mMat0;
|
||||
private MatOfInt mChannels[];
|
||||
private MatOfInt mHistSize;
|
||||
private int mHistSizeNum;
|
||||
private int mHistSizeNum = 25;
|
||||
private MatOfFloat mRanges;
|
||||
private Scalar mColorsRGB[];
|
||||
private Scalar mColorsHue[];
|
||||
@@ -66,10 +61,6 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView
|
||||
private Point mP1;
|
||||
private Point mP2;
|
||||
private float mBuff[];
|
||||
private Mat mRgbaInnerWindow;
|
||||
private Mat mGrayInnerWindow;
|
||||
private Mat mZoomWindow;
|
||||
private Mat mZoomCorner;
|
||||
private Mat mSepiaKernel;
|
||||
|
||||
public static int viewMode = VIEW_MODE_RGBA;
|
||||
@@ -166,13 +157,9 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView
|
||||
}
|
||||
|
||||
public void onCameraViewStarted(int width, int height) {
|
||||
mGray = new Mat();
|
||||
mRgba = new Mat();
|
||||
mIntermediateMat = new Mat();
|
||||
mSize0 = new Size();
|
||||
mHist = new Mat();
|
||||
mChannels = new MatOfInt[] { new MatOfInt(0), new MatOfInt(1), new MatOfInt(2) };
|
||||
mHistSizeNum = 25;
|
||||
mBuff = new float[mHistSizeNum];
|
||||
mHistSize = new MatOfInt(mHistSizeNum);
|
||||
mRanges = new MatOfFloat(0f, 256f);
|
||||
@@ -197,14 +184,22 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView
|
||||
mSepiaKernel.put(3, 0, /* A */0.000f, 0.000f, 0.000f, 1f);
|
||||
}
|
||||
|
||||
private void CreateAuxiliaryMats() {
|
||||
if (mRgba.empty())
|
||||
return;
|
||||
public void onCameraViewStopped() {
|
||||
// Explicitly deallocate Mats
|
||||
if (mIntermediateMat != null)
|
||||
mIntermediateMat.release();
|
||||
|
||||
mSizeRgba = mRgba.size();
|
||||
mIntermediateMat = null;
|
||||
}
|
||||
|
||||
int rows = (int) mSizeRgba.height;
|
||||
int cols = (int) mSizeRgba.width;
|
||||
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
|
||||
Mat rgba = inputFrame.rgba();
|
||||
Size sizeRgba = rgba.size();
|
||||
|
||||
Mat rgbaInnerWindow;
|
||||
|
||||
int rows = (int) sizeRgba.height;
|
||||
int cols = (int) sizeRgba.width;
|
||||
|
||||
int left = cols / 8;
|
||||
int top = rows / 8;
|
||||
@@ -212,151 +207,107 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView
|
||||
int width = cols * 3 / 4;
|
||||
int height = rows * 3 / 4;
|
||||
|
||||
if (mRgbaInnerWindow == null)
|
||||
mRgbaInnerWindow = mRgba.submat(top, top + height, left, left + width);
|
||||
mSizeRgbaInner = mRgbaInnerWindow.size();
|
||||
|
||||
if (mGrayInnerWindow == null && !mGray.empty())
|
||||
mGrayInnerWindow = mGray.submat(top, top + height, left, left + width);
|
||||
|
||||
if (mZoomCorner == null)
|
||||
mZoomCorner = mRgba.submat(0, rows / 2 - rows / 10, 0, cols / 2 - cols / 10);
|
||||
|
||||
if (mZoomWindow == null)
|
||||
mZoomWindow = mRgba.submat(rows / 2 - 9 * rows / 100, rows / 2 + 9 * rows / 100, cols / 2 - 9 * cols / 100, cols / 2 + 9 * cols / 100);
|
||||
}
|
||||
|
||||
public void onCameraViewStopped() {
|
||||
// Explicitly deallocate Mats
|
||||
if (mZoomWindow != null)
|
||||
mZoomWindow.release();
|
||||
if (mZoomCorner != null)
|
||||
mZoomCorner.release();
|
||||
if (mGrayInnerWindow != null)
|
||||
mGrayInnerWindow.release();
|
||||
if (mRgbaInnerWindow != null)
|
||||
mRgbaInnerWindow.release();
|
||||
if (mRgba != null)
|
||||
mRgba.release();
|
||||
if (mGray != null)
|
||||
mGray.release();
|
||||
if (mIntermediateMat != null)
|
||||
mIntermediateMat.release();
|
||||
|
||||
mRgba = null;
|
||||
mGray = null;
|
||||
mIntermediateMat = null;
|
||||
mRgbaInnerWindow = null;
|
||||
mGrayInnerWindow = null;
|
||||
mZoomCorner = null;
|
||||
mZoomWindow = null;
|
||||
}
|
||||
|
||||
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
|
||||
mRgba = inputFrame.rgba();
|
||||
|
||||
switch (ImageManipulationsActivity.viewMode) {
|
||||
case ImageManipulationsActivity.VIEW_MODE_RGBA:
|
||||
break;
|
||||
|
||||
case ImageManipulationsActivity.VIEW_MODE_HIST:
|
||||
if ((mSizeRgba == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height))
|
||||
CreateAuxiliaryMats();
|
||||
int thikness = (int) (mSizeRgba.width / (mHistSizeNum + 10) / 5);
|
||||
Mat hist = new Mat();
|
||||
int thikness = (int) (sizeRgba.width / (mHistSizeNum + 10) / 5);
|
||||
if(thikness > 5) thikness = 5;
|
||||
int offset = (int) ((mSizeRgba.width - (5*mHistSizeNum + 4*10)*thikness)/2);
|
||||
int offset = (int) ((sizeRgba.width - (5*mHistSizeNum + 4*10)*thikness)/2);
|
||||
// RGB
|
||||
for(int c=0; c<3; c++) {
|
||||
Imgproc.calcHist(Arrays.asList(mRgba), mChannels[c], mMat0, mHist, mHistSize, mRanges);
|
||||
Core.normalize(mHist, mHist, mSizeRgba.height/2, 0, Core.NORM_INF);
|
||||
mHist.get(0, 0, mBuff);
|
||||
Imgproc.calcHist(Arrays.asList(rgba), mChannels[c], mMat0, hist, mHistSize, mRanges);
|
||||
Core.normalize(hist, hist, sizeRgba.height/2, 0, Core.NORM_INF);
|
||||
hist.get(0, 0, mBuff);
|
||||
for(int h=0; h<mHistSizeNum; h++) {
|
||||
mP1.x = mP2.x = offset + (c * (mHistSizeNum + 10) + h) * thikness;
|
||||
mP1.y = mSizeRgba.height-1;
|
||||
mP1.y = sizeRgba.height-1;
|
||||
mP2.y = mP1.y - 2 - (int)mBuff[h];
|
||||
Core.line(mRgba, mP1, mP2, mColorsRGB[c], thikness);
|
||||
Core.line(rgba, mP1, mP2, mColorsRGB[c], thikness);
|
||||
}
|
||||
}
|
||||
// Value and Hue
|
||||
Imgproc.cvtColor(mRgba, mIntermediateMat, Imgproc.COLOR_RGB2HSV_FULL);
|
||||
Imgproc.cvtColor(rgba, mIntermediateMat, Imgproc.COLOR_RGB2HSV_FULL);
|
||||
// Value
|
||||
Imgproc.calcHist(Arrays.asList(mIntermediateMat), mChannels[2], mMat0, mHist, mHistSize, mRanges);
|
||||
Core.normalize(mHist, mHist, mSizeRgba.height/2, 0, Core.NORM_INF);
|
||||
mHist.get(0, 0, mBuff);
|
||||
Imgproc.calcHist(Arrays.asList(mIntermediateMat), mChannels[2], mMat0, hist, mHistSize, mRanges);
|
||||
Core.normalize(hist, hist, sizeRgba.height/2, 0, Core.NORM_INF);
|
||||
hist.get(0, 0, mBuff);
|
||||
for(int h=0; h<mHistSizeNum; h++) {
|
||||
mP1.x = mP2.x = offset + (3 * (mHistSizeNum + 10) + h) * thikness;
|
||||
mP1.y = mSizeRgba.height-1;
|
||||
mP1.y = sizeRgba.height-1;
|
||||
mP2.y = mP1.y - 2 - (int)mBuff[h];
|
||||
Core.line(mRgba, mP1, mP2, mWhilte, thikness);
|
||||
Core.line(rgba, mP1, mP2, mWhilte, thikness);
|
||||
}
|
||||
// Hue
|
||||
Imgproc.calcHist(Arrays.asList(mIntermediateMat), mChannels[0], mMat0, mHist, mHistSize, mRanges);
|
||||
Core.normalize(mHist, mHist, mSizeRgba.height/2, 0, Core.NORM_INF);
|
||||
mHist.get(0, 0, mBuff);
|
||||
Imgproc.calcHist(Arrays.asList(mIntermediateMat), mChannels[0], mMat0, hist, mHistSize, mRanges);
|
||||
Core.normalize(hist, hist, sizeRgba.height/2, 0, Core.NORM_INF);
|
||||
hist.get(0, 0, mBuff);
|
||||
for(int h=0; h<mHistSizeNum; h++) {
|
||||
mP1.x = mP2.x = offset + (4 * (mHistSizeNum + 10) + h) * thikness;
|
||||
mP1.y = mSizeRgba.height-1;
|
||||
mP1.y = sizeRgba.height-1;
|
||||
mP2.y = mP1.y - 2 - (int)mBuff[h];
|
||||
Core.line(mRgba, mP1, mP2, mColorsHue[h], thikness);
|
||||
Core.line(rgba, mP1, mP2, mColorsHue[h], thikness);
|
||||
}
|
||||
break;
|
||||
|
||||
case ImageManipulationsActivity.VIEW_MODE_CANNY:
|
||||
if ((mRgbaInnerWindow == null) || (mGrayInnerWindow == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height))
|
||||
CreateAuxiliaryMats();
|
||||
Imgproc.Canny(mRgbaInnerWindow, mIntermediateMat, 80, 90);
|
||||
Imgproc.cvtColor(mIntermediateMat, mRgbaInnerWindow, Imgproc.COLOR_GRAY2BGRA, 4);
|
||||
rgbaInnerWindow = rgba.submat(top, top + height, left, left + width);
|
||||
Imgproc.Canny(rgbaInnerWindow, mIntermediateMat, 80, 90);
|
||||
Imgproc.cvtColor(mIntermediateMat, rgbaInnerWindow, Imgproc.COLOR_GRAY2BGRA, 4);
|
||||
rgbaInnerWindow.release();
|
||||
break;
|
||||
|
||||
case ImageManipulationsActivity.VIEW_MODE_SOBEL:
|
||||
mGray = inputFrame.gray();
|
||||
|
||||
if ((mRgbaInnerWindow == null) || (mGrayInnerWindow == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height))
|
||||
CreateAuxiliaryMats();
|
||||
|
||||
Imgproc.Sobel(mGrayInnerWindow, mIntermediateMat, CvType.CV_8U, 1, 1);
|
||||
Mat gray = inputFrame.gray();
|
||||
Mat grayInnerWindow = gray.submat(top, top + height, left, left + width);
|
||||
rgbaInnerWindow = rgba.submat(top, top + height, left, left + width);
|
||||
Imgproc.Sobel(grayInnerWindow, mIntermediateMat, CvType.CV_8U, 1, 1);
|
||||
Core.convertScaleAbs(mIntermediateMat, mIntermediateMat, 10, 0);
|
||||
Imgproc.cvtColor(mIntermediateMat, mRgbaInnerWindow, Imgproc.COLOR_GRAY2BGRA, 4);
|
||||
Imgproc.cvtColor(mIntermediateMat, rgbaInnerWindow, Imgproc.COLOR_GRAY2BGRA, 4);
|
||||
grayInnerWindow.release();
|
||||
rgbaInnerWindow.release();
|
||||
break;
|
||||
|
||||
case ImageManipulationsActivity.VIEW_MODE_SEPIA:
|
||||
if ((mRgbaInnerWindow == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height))
|
||||
CreateAuxiliaryMats();
|
||||
Core.transform(mRgbaInnerWindow, mRgbaInnerWindow, mSepiaKernel);
|
||||
rgbaInnerWindow = rgba.submat(top, top + height, left, left + width);
|
||||
Core.transform(rgbaInnerWindow, rgbaInnerWindow, mSepiaKernel);
|
||||
rgbaInnerWindow.release();
|
||||
break;
|
||||
|
||||
case ImageManipulationsActivity.VIEW_MODE_ZOOM:
|
||||
if ((mZoomCorner == null) || (mZoomWindow == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height))
|
||||
CreateAuxiliaryMats();
|
||||
Imgproc.resize(mZoomWindow, mZoomCorner, mZoomCorner.size());
|
||||
|
||||
Mat zoomCorner = rgba.submat(0, rows / 2 - rows / 10, 0, cols / 2 - cols / 10);
|
||||
Mat mZoomWindow = rgba.submat(rows / 2 - 9 * rows / 100, rows / 2 + 9 * rows / 100, cols / 2 - 9 * cols / 100, cols / 2 + 9 * cols / 100);
|
||||
Imgproc.resize(mZoomWindow, zoomCorner, zoomCorner.size());
|
||||
Size wsize = mZoomWindow.size();
|
||||
Core.rectangle(mZoomWindow, new Point(1, 1), new Point(wsize.width - 2, wsize.height - 2), new Scalar(255, 0, 0, 255), 2);
|
||||
zoomCorner.release();
|
||||
mZoomWindow.release();
|
||||
break;
|
||||
|
||||
case ImageManipulationsActivity.VIEW_MODE_PIXELIZE:
|
||||
if ((mRgbaInnerWindow == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height))
|
||||
CreateAuxiliaryMats();
|
||||
Imgproc.resize(mRgbaInnerWindow, mIntermediateMat, mSize0, 0.1, 0.1, Imgproc.INTER_NEAREST);
|
||||
Imgproc.resize(mIntermediateMat, mRgbaInnerWindow, mSizeRgbaInner, 0., 0., Imgproc.INTER_NEAREST);
|
||||
rgbaInnerWindow = rgba.submat(top, top + height, left, left + width);
|
||||
Imgproc.resize(rgbaInnerWindow, mIntermediateMat, mSize0, 0.1, 0.1, Imgproc.INTER_NEAREST);
|
||||
Imgproc.resize(mIntermediateMat, rgbaInnerWindow, rgbaInnerWindow.size(), 0., 0., Imgproc.INTER_NEAREST);
|
||||
rgbaInnerWindow.release();
|
||||
break;
|
||||
|
||||
case ImageManipulationsActivity.VIEW_MODE_POSTERIZE:
|
||||
if ((mRgbaInnerWindow == null) || (mRgba.cols() != mSizeRgba.width) || (mRgba.height() != mSizeRgba.height))
|
||||
CreateAuxiliaryMats();
|
||||
/*
|
||||
Imgproc.cvtColor(mRgbaInnerWindow, mIntermediateMat, Imgproc.COLOR_RGBA2RGB);
|
||||
Imgproc.cvtColor(rgbaInnerWindow, mIntermediateMat, Imgproc.COLOR_RGBA2RGB);
|
||||
Imgproc.pyrMeanShiftFiltering(mIntermediateMat, mIntermediateMat, 5, 50);
|
||||
Imgproc.cvtColor(mIntermediateMat, mRgbaInnerWindow, Imgproc.COLOR_RGB2RGBA);
|
||||
Imgproc.cvtColor(mIntermediateMat, rgbaInnerWindow, Imgproc.COLOR_RGB2RGBA);
|
||||
*/
|
||||
|
||||
Imgproc.Canny(mRgbaInnerWindow, mIntermediateMat, 80, 90);
|
||||
mRgbaInnerWindow.setTo(new Scalar(0, 0, 0, 255), mIntermediateMat);
|
||||
Core.convertScaleAbs(mRgbaInnerWindow, mIntermediateMat, 1./16, 0);
|
||||
Core.convertScaleAbs(mIntermediateMat, mRgbaInnerWindow, 16, 0);
|
||||
rgbaInnerWindow = rgba.submat(top, top + height, left, left + width);
|
||||
Imgproc.Canny(rgbaInnerWindow, mIntermediateMat, 80, 90);
|
||||
rgbaInnerWindow.setTo(new Scalar(0, 0, 0, 255), mIntermediateMat);
|
||||
Core.convertScaleAbs(rgbaInnerWindow, mIntermediateMat, 1./16, 0);
|
||||
Core.convertScaleAbs(mIntermediateMat, rgbaInnerWindow, 16, 0);
|
||||
rgbaInnerWindow.release();
|
||||
break;
|
||||
}
|
||||
|
||||
return mRgba;
|
||||
return rgba;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
#include <math.h>
|
||||
#include <queue>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
#define LOG_TAG "OCV:libnative_activity"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
@@ -115,10 +116,10 @@ static void engine_handle_cmd(android_app* app, int32_t cmd)
|
||||
{
|
||||
LOGI("APP_CMD_INIT_WINDOW");
|
||||
|
||||
engine->capture = new cv::VideoCapture(0);
|
||||
engine->capture = cv::makePtr<cv::VideoCapture>(0);
|
||||
|
||||
union {double prop; const char* name;} u;
|
||||
u.prop = engine->capture->get(CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING);
|
||||
u.prop = engine->capture->get(cv::CAP_PROP_ANDROID_PREVIEW_SIZES_STRING);
|
||||
|
||||
int view_width = ANativeWindow_getWidth(app->window);
|
||||
int view_height = ANativeWindow_getHeight(app->window);
|
||||
@@ -135,8 +136,8 @@ static void engine_handle_cmd(android_app* app, int32_t cmd)
|
||||
|
||||
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);
|
||||
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,
|
||||
@@ -210,7 +211,7 @@ void android_main(android_app* app)
|
||||
if (!engine.capture.empty())
|
||||
{
|
||||
if (engine.capture->grab())
|
||||
engine.capture->retrieve(drawing_frame, CV_CAP_ANDROID_COLOR_FRAME_RGBA);
|
||||
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);
|
||||
|
||||
@@ -40,4 +40,4 @@ public class CvNativeActivity extends Activity {
|
||||
super.onResume();
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,4 +84,4 @@ public class Tutorial3View extends JavaCameraView implements PictureCallback {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
|
||||
endif()
|
||||
install(TARGETS ${the_target}
|
||||
RUNTIME DESTINATION "samples/c" COMPONENT main)
|
||||
RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/c" COMPONENT main)
|
||||
endif()
|
||||
ENDMACRO()
|
||||
|
||||
@@ -57,4 +57,3 @@ if (INSTALL_C_EXAMPLES AND NOT WIN32)
|
||||
DESTINATION share/OpenCV/samples/c
|
||||
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
|
||||
endif ()
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
@@ -42,6 +41,10 @@
|
||||
#include "opencv2/contrib/compat.hpp"
|
||||
#include "opencv2/highgui/highgui_c.h"
|
||||
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
static void help(char **argv)
|
||||
{
|
||||
std::cout << "\nThis program demonstrates the contributed flesh detector CvAdaptiveSkinDetector which can be found in contrib.cpp\n"
|
||||
@@ -410,4 +413,3 @@ int main(int argc, char** argv )
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
|
||||
/* Select appropriate case insensitive string comparison function: */
|
||||
#if defined WIN32 || defined _MSC_VER
|
||||
#define MY_STRNICMP strnicmp
|
||||
#define MY_STRICMP stricmp
|
||||
# define MY_STRNICMP _strnicmp
|
||||
# define MY_STRICMP _stricmp
|
||||
# define MY_STRDUP _strdup
|
||||
#else
|
||||
#define MY_STRNICMP strncasecmp
|
||||
#define MY_STRICMP strcasecmp
|
||||
# define MY_STRNICMP strncasecmp
|
||||
# define MY_STRICMP strcasecmp
|
||||
# define MY_STRDUP strdup
|
||||
#endif
|
||||
|
||||
/* List of foreground (FG) DETECTION modules: */
|
||||
@@ -239,7 +241,7 @@ static int RunBlobTrackingAuto( CvCapture* pCap, CvBlobTrackerAuto* pTracker,cha
|
||||
|
||||
if(pS)
|
||||
{
|
||||
char* pStr = strdup(pS);
|
||||
char* pStr = MY_STRDUP(pS);
|
||||
char* pStrFree = pStr;
|
||||
|
||||
while (pStr && strlen(pStr) > 0)
|
||||
@@ -751,6 +753,3 @@ int main(int argc, char* argv[])
|
||||
return 0;
|
||||
|
||||
} /* main() */
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ $# -gt 0 ] ; then
|
||||
base=`basename $1 .c`
|
||||
echo "compiling $base"
|
||||
gcc -ggdb `pkg-config opencv --cflags --libs` $base.c -o $base
|
||||
base=`basename $1 .c`
|
||||
echo "compiling $base"
|
||||
gcc -ggdb `pkg-config opencv --cflags --libs` $base.c -o $base
|
||||
else
|
||||
for i in *.c; do
|
||||
echo "compiling $i"
|
||||
gcc -ggdb `pkg-config --cflags opencv` -o `basename $i .c` $i `pkg-config --libs opencv`;
|
||||
done
|
||||
for i in *.cpp; do
|
||||
echo "compiling $i"
|
||||
g++ -ggdb `pkg-config --cflags opencv` -o `basename $i .cpp` $i `pkg-config --libs opencv`;
|
||||
done
|
||||
for i in *.c; do
|
||||
echo "compiling $i"
|
||||
gcc -ggdb `pkg-config --cflags opencv` -o `basename $i .c` $i `pkg-config --libs opencv`;
|
||||
done
|
||||
for i in *.cpp; do
|
||||
echo "compiling $i"
|
||||
g++ -ggdb `pkg-config --cflags opencv` -o `basename $i .cpp` $i `pkg-config --libs opencv`;
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -13,6 +13,3 @@ ADD_EXECUTABLE(opencv_example minarea.c)
|
||||
TARGET_LINK_LIBRARIES(opencv_example ${OpenCV_LIBS})
|
||||
|
||||
#MESSAGE(STATUS "OpenCV_LIBS: ${OpenCV_LIBS}")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,8 +25,3 @@ the CMake gui with:
|
||||
$ cmake-gui <OPENCV_SRC_PATH>/samples/c/example_cmake/
|
||||
|
||||
And pick the correct value for OpenCV_DIR.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -114,4 +114,3 @@ int main( int argc, char** argv )
|
||||
#ifdef _EiC
|
||||
main(1,"convexhull.c");
|
||||
#endif
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ static int mushroom_read_database( const char* filename, CvMat** data, CvMat** m
|
||||
}
|
||||
|
||||
cvReleaseMemStorage( &storage );
|
||||
delete el_ptr;
|
||||
delete [] el_ptr;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
SET(OPENCV_CPP_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc
|
||||
opencv_highgui opencv_ml opencv_video opencv_objdetect opencv_photo opencv_nonfree opencv_softcascade
|
||||
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_stitching opencv_videostab opencv_bioinspired)
|
||||
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_stitching opencv_videostab opencv_bioinspired opencv_shape)
|
||||
|
||||
ocv_check_dependencies(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
|
||||
|
||||
@@ -16,17 +16,17 @@ 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_gpuoptflow)
|
||||
ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpuoptflow/include")
|
||||
if(HAVE_opencv_cudaoptflow)
|
||||
ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaoptflow/include")
|
||||
endif()
|
||||
if(HAVE_opencv_gpuimgproc)
|
||||
ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpuimgproc/include")
|
||||
if(HAVE_opencv_cudaimgproc)
|
||||
ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaimgproc/include")
|
||||
endif()
|
||||
if(HAVE_opencv_gpuarithm)
|
||||
ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpuarithm/include")
|
||||
if(HAVE_opencv_cudaarithm)
|
||||
ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaarithm/include")
|
||||
endif()
|
||||
if(HAVE_opencv_gpufilters)
|
||||
ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpufilters/include")
|
||||
if(HAVE_opencv_cudafilters)
|
||||
ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudafilters/include")
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
|
||||
@@ -41,11 +41,11 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
if("${srcs}" MATCHES "tutorial_code")
|
||||
set(sample_kind tutorial)
|
||||
set(sample_KIND TUTORIAL)
|
||||
set(sample_folder "samples//tutorials")
|
||||
set(sample_subfolder "tutorials")
|
||||
else()
|
||||
set(sample_kind example)
|
||||
set(sample_KIND EXAMPLE)
|
||||
set(sample_folder "samples//cpp")
|
||||
set(sample_subfolder "cpp")
|
||||
endif()
|
||||
|
||||
set(the_target "${sample_kind}_${name}")
|
||||
@@ -53,7 +53,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
|
||||
|
||||
if("${srcs}" MATCHES "gpu/")
|
||||
target_link_libraries(${the_target} opencv_gpuarithm opencv_gpufilters)
|
||||
target_link_libraries(${the_target} opencv_cudaarithm opencv_cudafilters)
|
||||
endif()
|
||||
|
||||
set_target_properties(${the_target} PROPERTIES
|
||||
@@ -61,7 +61,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
PROJECT_LABEL "(${sample_KIND}) ${name}")
|
||||
|
||||
if(ENABLE_SOLUTION_FOLDERS)
|
||||
set_target_properties(${the_target} PROPERTIES FOLDER "${sample_folder}")
|
||||
set_target_properties(${the_target} PROPERTIES FOLDER "samples/${sample_subfolder}")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
@@ -69,7 +69,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
|
||||
endif()
|
||||
install(TARGETS ${the_target}
|
||||
RUNTIME DESTINATION "${sample_folder}" COMPONENT main)
|
||||
RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${sample_subfolder}" COMPONENT main)
|
||||
endif()
|
||||
ENDMACRO()
|
||||
|
||||
@@ -79,10 +79,12 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
ocv_list_filterout(cpp_samples Qt_sample)
|
||||
endif()
|
||||
|
||||
if(NOT HAVE_opencv_gpuarithm OR NOT HAVE_opencv_gpufilters)
|
||||
if(NOT HAVE_opencv_cudaarithm OR NOT HAVE_opencv_cudafilters)
|
||||
ocv_list_filterout(cpp_samples "/gpu/")
|
||||
endif()
|
||||
|
||||
ocv_list_filterout(cpp_samples "viz")
|
||||
|
||||
foreach(sample_filename ${cpp_samples})
|
||||
get_filename_component(sample ${sample_filename} NAME_WE)
|
||||
OPENCV_DEFINE_CPP_EXAMPLE(${sample} ${sample_filename})
|
||||
@@ -95,4 +97,3 @@ if (INSTALL_C_EXAMPLES AND NOT WIN32)
|
||||
DESTINATION share/OpenCV/samples/cpp
|
||||
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
//============================================================================
|
||||
// Name : HighDynamicRange_RetinaCompression.cpp
|
||||
// Name : OpenEXRimages_HDR_Retina_toneMapping.cpp
|
||||
// Author : Alexandre Benoit (benoit.alexandre.vision@gmail.com)
|
||||
// Version : 0.1
|
||||
// Copyright : Alexandre Benoit, LISTIC Lab, july 2011
|
||||
// Description : HighDynamicRange compression (tone mapping) with the help of the Gipsa/Listic's retina in C++, Ansi-style
|
||||
// Description : HighDynamicRange retina tone mapping with the help of the Gipsa/Listic's retina in C++, Ansi-style
|
||||
//============================================================================
|
||||
|
||||
#include <iostream>
|
||||
@@ -17,10 +17,10 @@
|
||||
static void help(std::string errorMessage)
|
||||
{
|
||||
std::cout<<"Program init error : "<<errorMessage<<std::endl;
|
||||
std::cout<<"\nProgram call procedure : ./OpenEXRimages_HighDynamicRange_Retina_toneMapping [OpenEXR image to process]"<<std::endl;
|
||||
std::cout<<"\nProgram call procedure : ./OpenEXRimages_HDR_Retina_toneMapping [OpenEXR image to process]"<<std::endl;
|
||||
std::cout<<"\t[OpenEXR image to process] : the input HDR image to process, must be an OpenEXR format, see http://www.openexr.com/ to get some samples or create your own using camera bracketing and Photoshop or equivalent software for OpenEXR image synthesis"<<std::endl;
|
||||
std::cout<<"\nExamples:"<<std::endl;
|
||||
std::cout<<"\t-Image processing : ./OpenEXRimages_HighDynamicRange_Retina_toneMapping memorial.exr"<<std::endl;
|
||||
std::cout<<"\t-Image processing : ./OpenEXRimages_HDR_Retina_toneMapping memorial.exr"<<std::endl;
|
||||
}
|
||||
|
||||
// simple procedure for 1D curve tracing
|
||||
@@ -71,7 +71,7 @@ static void drawPlot(const cv::Mat curve, const std::string figureTitle, const i
|
||||
{
|
||||
cv::Mat rgbIntImg;
|
||||
outputMat.convertTo(rgbIntImg, CV_8UC3);
|
||||
cv::cvtColor(rgbIntImg, intGrayImage, cv::COLOR_BGR2GRAY);
|
||||
cvtColor(rgbIntImg, intGrayImage, cv::COLOR_BGR2GRAY);
|
||||
}
|
||||
|
||||
// get histogram density probability in order to cut values under above edges limits (here 5-95%)... usefull for HDR pixel errors cancellation
|
||||
@@ -302,5 +302,3 @@ static void drawPlot(const cv::Mat curve, const std::string figureTitle, const i
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
//============================================================================
|
||||
// Name : OpenEXRimages_HighDynamicRange_Retina_toneMapping_video.cpp
|
||||
// Name : OpenEXRimages_HDR_Retina_toneMapping_video.cpp
|
||||
// Author : Alexandre Benoit (benoit.alexandre.vision@gmail.com)
|
||||
// Version : 0.2
|
||||
// Copyright : Alexandre Benoit, LISTIC Lab, december 2011
|
||||
// Description : HighDynamicRange compression (tone mapping) for image sequences with the help of the Gipsa/Listic's retina in C++, Ansi-style
|
||||
// Description : HighDynamicRange retina tone mapping for image sequences with the help of the Gipsa/Listic's retina in C++, Ansi-style
|
||||
// Known issues: the input OpenEXR sequences can have bad computed pixels that should be removed
|
||||
// => a simple method consists of cutting histogram edges (a slider for this on the UI is provided)
|
||||
// => however, in image sequences, this histogramm cut must be done in an elegant way from frame to frame... still not done...
|
||||
@@ -18,17 +18,21 @@
|
||||
#include "opencv2/imgproc.hpp" // cvCvtcolor function
|
||||
#include "opencv2/highgui.hpp" // display
|
||||
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
static void help(std::string errorMessage)
|
||||
{
|
||||
std::cout<<"Program init error : "<<errorMessage<<std::endl;
|
||||
std::cout<<"\nProgram call procedure : ./OpenEXRimages_HighDynamicRange_Retina_toneMapping [OpenEXR image sequence to process] [OPTIONNAL start frame] [OPTIONNAL end frame]"<<std::endl;
|
||||
std::cout<<"\nProgram call procedure : ./OpenEXRimages_HDR_Retina_toneMapping [OpenEXR image sequence to process] [OPTIONNAL start frame] [OPTIONNAL end frame]"<<std::endl;
|
||||
std::cout<<"\t[OpenEXR image sequence to process] : std::sprintf style ready prototype filename of the input HDR images to process, must be an OpenEXR format, see http://www.openexr.com/ to get some samples or create your own using camera bracketing and Photoshop or equivalent software for OpenEXR image synthesis"<<std::endl;
|
||||
std::cout<<"\t\t => WARNING : image index number of digits cannot exceed 10"<<std::endl;
|
||||
std::cout<<"\t[start frame] : the starting frame tat should be considered"<<std::endl;
|
||||
std::cout<<"\t[end frame] : the ending frame tat should be considered"<<std::endl;
|
||||
std::cout<<"\nExamples:"<<std::endl;
|
||||
std::cout<<"\t-Image processing : ./OpenEXRimages_HighDynamicRange_Retina_toneMapping_video memorial%3d.exr 20 45"<<std::endl;
|
||||
std::cout<<"\t-Image processing : ./OpenEXRimages_HighDynamicRange_Retina_toneMapping_video memorial%3d.exr 20 45 log"<<std::endl;
|
||||
std::cout<<"\t-Image processing : ./OpenEXRimages_HDR_Retina_toneMapping_video memorial%3d.exr 20 45"<<std::endl;
|
||||
std::cout<<"\t-Image processing : ./OpenEXRimages_HDR_Retina_toneMapping_video memorial%3d.exr 20 45 log"<<std::endl;
|
||||
std::cout<<"\t ==> to process images from memorial020d.exr to memorial045d.exr"<<std::endl;
|
||||
|
||||
}
|
||||
@@ -90,7 +94,7 @@ static void rescaleGrayLevelMat(const cv::Mat &inputMat, cv::Mat &outputMat, con
|
||||
{
|
||||
cv::Mat rgbIntImg;
|
||||
normalisedImage.convertTo(rgbIntImg, CV_8UC3);
|
||||
cv::cvtColor(rgbIntImg, intGrayImage, cv::COLOR_BGR2GRAY);
|
||||
cvtColor(rgbIntImg, intGrayImage, cv::COLOR_BGR2GRAY);
|
||||
}
|
||||
|
||||
// get histogram density probability in order to cut values under above edges limits (here 5-95%)... usefull for HDR pixel errors cancellation
|
||||
@@ -359,5 +363,3 @@ static void loadNewFrame(const std::string filenamePrototype, const int currentF
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,15 +4,11 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <opencv2/core/core_c.h>
|
||||
#include <opencv2/imgproc/imgproc_c.h>
|
||||
#include <opencv2/legacy/compat.hpp>
|
||||
#include <opencv2/calib3d/calib3d_c.h>
|
||||
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/calib3d.hpp>
|
||||
#include <opencv2/legacy/compat.hpp>
|
||||
|
||||
#if defined WIN32 || defined _WIN32 || defined WINCE
|
||||
#include <windows.h>
|
||||
@@ -116,19 +112,16 @@ static void initPOSIT(std::vector<CvPoint3D32f> *modelPoints)
|
||||
modelPoints->push_back(cvPoint3D32f(0.0f, CUBE_SIZE, 0.0f));
|
||||
}
|
||||
|
||||
static void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImage* grayImage)
|
||||
static void foundCorners(vector<CvPoint2D32f> *srcImagePoints, const Mat& source, Mat& grayImage)
|
||||
{
|
||||
cvCvtColor(source,grayImage,CV_RGB2GRAY);
|
||||
cvSmooth( grayImage, grayImage,CV_GAUSSIAN,11);
|
||||
cvNormalize(grayImage, grayImage, 0, 255, CV_MINMAX);
|
||||
cvThreshold( grayImage, grayImage, 26, 255, CV_THRESH_BINARY_INV);//25
|
||||
cvtColor(source, grayImage, COLOR_RGB2GRAY);
|
||||
GaussianBlur(grayImage, grayImage, Size(11,11), 0, 0);
|
||||
normalize(grayImage, grayImage, 0, 255, NORM_MINMAX);
|
||||
threshold(grayImage, grayImage, 26, 255, THRESH_BINARY_INV); //25
|
||||
|
||||
Mat MgrayImage = cv::cvarrToMat(grayImage);
|
||||
//For debug
|
||||
//MgrayImage = MgrayImage.clone();//deep copy
|
||||
vector<vector<Point> > contours;
|
||||
vector<Vec4i> hierarchy;
|
||||
findContours(MgrayImage, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_NONE);
|
||||
findContours(grayImage, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_NONE);
|
||||
|
||||
Point p;
|
||||
vector<CvPoint2D32f> srcImagePoints_temp(4,cvPoint2D32f(0,0));
|
||||
@@ -189,17 +182,17 @@ static void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source,
|
||||
}
|
||||
srcImagePoints->at(3) = srcImagePoints_temp.at(index);
|
||||
|
||||
Mat Msource = cv::cvarrToMat(source);
|
||||
Mat Msource = source;
|
||||
stringstream ss;
|
||||
for(size_t i = 0 ; i<srcImagePoints_temp.size(); i++ )
|
||||
{
|
||||
ss<<i;
|
||||
circle(Msource,srcImagePoints->at(i),5,CV_RGB(255,0,0));
|
||||
putText( Msource, ss.str(), srcImagePoints->at(i),CV_FONT_HERSHEY_SIMPLEX,1,CV_RGB(255,0,0));
|
||||
circle(Msource,srcImagePoints->at(i),5,Scalar(0,0,255));
|
||||
putText(Msource,ss.str(),srcImagePoints->at(i),FONT_HERSHEY_SIMPLEX,1,Scalar(0,0,255));
|
||||
ss.str("");
|
||||
|
||||
//new coordinate system in the middle of the frame and reversed (camera coordinate system)
|
||||
srcImagePoints->at(i) = cvPoint2D32f(srcImagePoints_temp.at(i).x-source->width/2,source->height/2-srcImagePoints_temp.at(i).y);
|
||||
srcImagePoints->at(i) = cvPoint2D32f(srcImagePoints_temp.at(i).x-source.cols/2,source.rows/2-srcImagePoints_temp.at(i).y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,15 +225,14 @@ int main(void)
|
||||
VideoCapture video("cube4.avi");
|
||||
CV_Assert(video.isOpened());
|
||||
|
||||
Mat frame; video >> frame;
|
||||
Mat source, grayImage;
|
||||
|
||||
IplImage* grayImage = cvCreateImage(frame.size(),8,1);
|
||||
video >> source;
|
||||
|
||||
namedWindow("original", WINDOW_AUTOSIZE | WINDOW_FREERATIO);
|
||||
namedWindow("POSIT", WINDOW_AUTOSIZE | WINDOW_FREERATIO);
|
||||
displayOverlay("POSIT", "We lost the 4 corners' detection quite often (the red circles disappear). This demo is only to illustrate how to use OpenGL callback.\n -- Press ESC to exit.", 10000);
|
||||
//For debug
|
||||
//cvNamedWindow("tempGray",CV_WINDOW_AUTOSIZE);
|
||||
|
||||
float OpenGLMatrix[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
setOpenGlDrawCallback("POSIT",on_opengl,OpenGLMatrix);
|
||||
|
||||
@@ -259,25 +251,20 @@ int main(void)
|
||||
|
||||
while(waitKey(33) != 27)
|
||||
{
|
||||
video >> frame;
|
||||
imshow("original", frame);
|
||||
video >> source;
|
||||
imshow("original",source);
|
||||
|
||||
IplImage source = frame;
|
||||
foundCorners(&srcImagePoints, &source, grayImage);
|
||||
foundCorners(&srcImagePoints, source, grayImage);
|
||||
cvPOSIT( positObject, &srcImagePoints[0], FOCAL_LENGTH, criteria, rotation_matrix, translation_vector );
|
||||
createOpenGLMatrixFrom(OpenGLMatrix,rotation_matrix,translation_vector);
|
||||
|
||||
imshow("POSIT", frame);
|
||||
//For debug
|
||||
//cvShowImage("tempGray",grayImage);
|
||||
imshow("POSIT",source);
|
||||
|
||||
if (video.get(CAP_PROP_POS_AVI_RATIO) > 0.99)
|
||||
video.set(CAP_PROP_POS_AVI_RATIO, 0);
|
||||
}
|
||||
|
||||
destroyAllWindows();
|
||||
cvReleaseImage(&grayImage);
|
||||
video.release();
|
||||
cvReleasePOSITObject(&positObject);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -54,10 +54,6 @@ static void help(char** argv)
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void makeDir( const string& dir )
|
||||
{
|
||||
#if defined WIN32 || defined _WIN32
|
||||
@@ -2563,19 +2559,19 @@ int main(int argc, char** argv)
|
||||
Ptr<FeatureDetector> featureDetector = FeatureDetector::create( ddmParams.detectorType );
|
||||
Ptr<DescriptorExtractor> descExtractor = DescriptorExtractor::create( ddmParams.descriptorType );
|
||||
Ptr<BOWImgDescriptorExtractor> bowExtractor;
|
||||
if( featureDetector.empty() || descExtractor.empty() )
|
||||
if( !featureDetector || !descExtractor )
|
||||
{
|
||||
cout << "featureDetector or descExtractor was not created" << endl;
|
||||
return -1;
|
||||
}
|
||||
{
|
||||
Ptr<DescriptorMatcher> descMatcher = DescriptorMatcher::create( ddmParams.matcherType );
|
||||
if( featureDetector.empty() || descExtractor.empty() || descMatcher.empty() )
|
||||
if( !featureDetector || !descExtractor || !descMatcher )
|
||||
{
|
||||
cout << "descMatcher was not created" << endl;
|
||||
return -1;
|
||||
}
|
||||
bowExtractor = new BOWImgDescriptorExtractor( descExtractor, descMatcher );
|
||||
bowExtractor = makePtr<BOWImgDescriptorExtractor>( descExtractor, descMatcher );
|
||||
}
|
||||
|
||||
// Print configuration to screen
|
||||
|
||||
@@ -35,7 +35,7 @@ int main(int argc, char** argv)
|
||||
setNumThreads(8);
|
||||
|
||||
Ptr<BackgroundSubtractor> fgbg = createBackgroundSubtractorGMG(20, 0.7);
|
||||
if (fgbg.empty())
|
||||
if (!fgbg)
|
||||
{
|
||||
std::cerr << "Failed to create BackgroundSubtractor.GMG Algorithm." << std::endl;
|
||||
return -1;
|
||||
@@ -78,4 +78,3 @@ int main(int argc, char** argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -332,4 +332,3 @@ Mat cv::ChessBoardGenerator::operator ()(const Mat& bg, const Mat& camMat, const
|
||||
|
||||
return generageChessBoard(bg, camMat, distCoeffs, zero, pb1, pb2, sqWidth, sqHeight, pts3d, corners);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class CascadeDetectorAdapter: public DetectionBasedTracker::IDetector
|
||||
IDetector(),
|
||||
Detector(detector)
|
||||
{
|
||||
CV_Assert(!detector.empty());
|
||||
CV_Assert(detector);
|
||||
}
|
||||
|
||||
void detect(const cv::Mat &Image, std::vector<cv::Rect> &objects)
|
||||
@@ -51,11 +51,11 @@ int main(int , char** )
|
||||
}
|
||||
|
||||
std::string cascadeFrontalfilename = "../../data/lbpcascades/lbpcascade_frontalface.xml";
|
||||
cv::Ptr<cv::CascadeClassifier> cascade = new cv::CascadeClassifier(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> MainDetector = new CascadeDetectorAdapter(cascade);
|
||||
cv::Ptr<cv::CascadeClassifier> cascade = makePtr<cv::CascadeClassifier>(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> MainDetector = makePtr<CascadeDetectorAdapter>(cascade);
|
||||
|
||||
cascade = new cv::CascadeClassifier(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> TrackingDetector = new CascadeDetectorAdapter(cascade);
|
||||
cascade = makePtr<cv::CascadeClassifier>(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> TrackingDetector = makePtr<CascadeDetectorAdapter>(cascade);
|
||||
|
||||
DetectionBasedTracker::Parameters params;
|
||||
DetectionBasedTracker Detector(MainDetector, TrackingDetector, params);
|
||||
|
||||
@@ -153,7 +153,7 @@ static void doIteration( const Mat& img1, Mat& img2, bool isWarpPerspective,
|
||||
{
|
||||
cout << "< Evaluate descriptor matcher..." << endl;
|
||||
vector<Point2f> curve;
|
||||
Ptr<GenericDescriptorMatcher> gdm = new VectorDescriptorMatcher( descriptorExtractor, descriptorMatcher );
|
||||
Ptr<GenericDescriptorMatcher> gdm = makePtr<VectorDescriptorMatcher>( descriptorExtractor, descriptorMatcher );
|
||||
evaluateGenericDescriptorMatcher( img1, img2, H12, keypoints1, keypoints2, 0, 0, curve, gdm );
|
||||
|
||||
Point2f firstPoint = *curve.begin();
|
||||
@@ -208,7 +208,7 @@ static void doIteration( const Mat& img1, Mat& img2, bool isWarpPerspective,
|
||||
matchesMask[i1] = 1;
|
||||
}
|
||||
// draw inliers
|
||||
drawMatches( img1, keypoints1, img2, keypoints2, filteredMatches, drawImg, Scalar(0, 255, 0), Scalar(0, 0, 255), matchesMask
|
||||
drawMatches( img1, keypoints1, img2, keypoints2, filteredMatches, drawImg, Scalar(0, 255, 0), Scalar(255, 0, 0), matchesMask
|
||||
#if DRAW_RICH_KEYPOINTS_MODE
|
||||
, DrawMatchesFlags::DRAW_RICH_KEYPOINTS
|
||||
#endif
|
||||
@@ -218,7 +218,7 @@ static void doIteration( const Mat& img1, Mat& img2, bool isWarpPerspective,
|
||||
// draw outliers
|
||||
for( size_t i1 = 0; i1 < matchesMask.size(); i1++ )
|
||||
matchesMask[i1] = !matchesMask[i1];
|
||||
drawMatches( img1, keypoints1, img2, keypoints2, filteredMatches, drawImg, Scalar(0, 0, 255), Scalar(255, 0, 0), matchesMask,
|
||||
drawMatches( img1, keypoints1, img2, keypoints2, filteredMatches, drawImg, Scalar(255, 0, 0), Scalar(0, 0, 255), matchesMask,
|
||||
DrawMatchesFlags::DRAW_OVER_OUTIMG | DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
|
||||
#endif
|
||||
|
||||
@@ -253,7 +253,7 @@ int main(int argc, char** argv)
|
||||
int mactherFilterType = getMatcherFilterType( argv[4] );
|
||||
bool eval = !isWarpPerspective ? false : (atoi(argv[6]) == 0 ? false : true);
|
||||
cout << ">" << endl;
|
||||
if( detector.empty() || descriptorExtractor.empty() || descriptorMatcher.empty() )
|
||||
if( !detector || !descriptorExtractor || !descriptorMatcher )
|
||||
{
|
||||
cout << "Can not create detector or descriptor exstractor or descriptor matcher of given types" << endl;
|
||||
return -1;
|
||||
|
||||
@@ -67,7 +67,7 @@ class CascadeDetectorAdapter: public DetectionBasedTracker::IDetector
|
||||
CascadeDetectorAdapter(cv::Ptr<cv::CascadeClassifier> detector):
|
||||
Detector(detector)
|
||||
{
|
||||
CV_Assert(!detector.empty());
|
||||
CV_Assert(detector);
|
||||
}
|
||||
|
||||
void detect(const cv::Mat &Image, std::vector<cv::Rect> &objects)
|
||||
@@ -117,11 +117,11 @@ static int test_FaceDetector(int argc, char *argv[])
|
||||
}
|
||||
|
||||
std::string cascadeFrontalfilename=cascadefile;
|
||||
cv::Ptr<cv::CascadeClassifier> cascade = new cv::CascadeClassifier(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> MainDetector = new CascadeDetectorAdapter(cascade);
|
||||
cv::Ptr<cv::CascadeClassifier> cascade = makePtr<cv::CascadeClassifier>(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> MainDetector = makePtr<CascadeDetectorAdapter>(cascade);
|
||||
|
||||
cascade = new cv::CascadeClassifier(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> TrackingDetector = new CascadeDetectorAdapter(cascade);
|
||||
cascade = makePtr<cv::CascadeClassifier>(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> TrackingDetector = makePtr<CascadeDetectorAdapter>(cascade);
|
||||
|
||||
DetectionBasedTracker::Parameters params;
|
||||
DetectionBasedTracker fd(MainDetector, TrackingDetector, params);
|
||||
|
||||
@@ -535,7 +535,7 @@ void DetectorQualityEvaluator::readAlgorithm ()
|
||||
{
|
||||
defaultDetector = FeatureDetector::create( algName );
|
||||
specificDetector = FeatureDetector::create( algName );
|
||||
if( defaultDetector.empty() )
|
||||
if( !defaultDetector )
|
||||
{
|
||||
printf( "Algorithm can not be read\n" );
|
||||
exit(-1);
|
||||
@@ -769,14 +769,14 @@ void DescriptorQualityEvaluator::readAlgorithm( )
|
||||
defaultDescMatcher = GenericDescriptorMatcher::create( algName );
|
||||
specificDescMatcher = GenericDescriptorMatcher::create( algName );
|
||||
|
||||
if( defaultDescMatcher.empty() )
|
||||
if( !defaultDescMatcher )
|
||||
{
|
||||
Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create( algName );
|
||||
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create( matcherName );
|
||||
defaultDescMatcher = new VectorDescriptorMatch( extractor, matcher );
|
||||
specificDescMatcher = new VectorDescriptorMatch( extractor, matcher );
|
||||
defaultDescMatcher = makePtr<VectorDescriptorMatch>( extractor, matcher );
|
||||
specificDescMatcher = makePtr<VectorDescriptorMatch>( extractor, matcher );
|
||||
|
||||
if( extractor.empty() || matcher.empty() )
|
||||
if( !extractor || !matcher )
|
||||
{
|
||||
printf("Algorithm can not be read\n");
|
||||
exit(-1);
|
||||
@@ -881,8 +881,9 @@ public:
|
||||
virtual void readAlgorithm( )
|
||||
{
|
||||
string classifierFile = data_path + "/features2d/calonder_classifier.rtc";
|
||||
defaultDescMatcher = new VectorDescriptorMatch( new CalonderDescriptorExtractor<float>( classifierFile ),
|
||||
new BFMatcher(NORM_L2) );
|
||||
defaultDescMatcher = makePtr<VectorDescriptorMatch>(
|
||||
makePtr<CalonderDescriptorExtractor<float> >( classifierFile ),
|
||||
makePtr<BFMatcher>(int(NORM_L2)));
|
||||
specificDescMatcher = defaultDescMatcher;
|
||||
}
|
||||
};
|
||||
@@ -922,10 +923,11 @@ void OneWayDescriptorQualityTest::processRunParamsFile ()
|
||||
|
||||
readAllDatasetsRunParams();
|
||||
|
||||
OneWayDescriptorBase *base = new OneWayDescriptorBase(patchSize, poseCount, pcaFilename,
|
||||
trainPath, trainImagesList);
|
||||
Ptr<OneWayDescriptorBase> base(
|
||||
new OneWayDescriptorBase(patchSize, poseCount, pcaFilename,
|
||||
trainPath, trainImagesList));
|
||||
|
||||
OneWayDescriptorMatch *match = new OneWayDescriptorMatch ();
|
||||
Ptr<OneWayDescriptorMatch> match = makePtr<OneWayDescriptorMatch>();
|
||||
match->initialize( OneWayDescriptorMatch::Params (), base );
|
||||
defaultDescMatcher = match;
|
||||
writeAllDatasetsRunParams();
|
||||
@@ -958,18 +960,18 @@ int main( int argc, char** argv )
|
||||
|
||||
Ptr<BaseQualityEvaluator> evals[] =
|
||||
{
|
||||
new DetectorQualityEvaluator( "FAST", "quality-detector-fast" ),
|
||||
new DetectorQualityEvaluator( "GFTT", "quality-detector-gftt" ),
|
||||
new DetectorQualityEvaluator( "HARRIS", "quality-detector-harris" ),
|
||||
new DetectorQualityEvaluator( "MSER", "quality-detector-mser" ),
|
||||
new DetectorQualityEvaluator( "STAR", "quality-detector-star" ),
|
||||
new DetectorQualityEvaluator( "SIFT", "quality-detector-sift" ),
|
||||
new DetectorQualityEvaluator( "SURF", "quality-detector-surf" ),
|
||||
makePtr<DetectorQualityEvaluator>( "FAST", "quality-detector-fast" ),
|
||||
makePtr<DetectorQualityEvaluator>( "GFTT", "quality-detector-gftt" ),
|
||||
makePtr<DetectorQualityEvaluator>( "HARRIS", "quality-detector-harris" ),
|
||||
makePtr<DetectorQualityEvaluator>( "MSER", "quality-detector-mser" ),
|
||||
makePtr<DetectorQualityEvaluator>( "STAR", "quality-detector-star" ),
|
||||
makePtr<DetectorQualityEvaluator>( "SIFT", "quality-detector-sift" ),
|
||||
makePtr<DetectorQualityEvaluator>( "SURF", "quality-detector-surf" ),
|
||||
|
||||
new DescriptorQualityEvaluator( "SIFT", "quality-descriptor-sift", "BruteForce" ),
|
||||
new DescriptorQualityEvaluator( "SURF", "quality-descriptor-surf", "BruteForce" ),
|
||||
new DescriptorQualityEvaluator( "FERN", "quality-descriptor-fern"),
|
||||
new CalonderDescriptorQualityEvaluator()
|
||||
makePtr<DescriptorQualityEvaluator>( "SIFT", "quality-descriptor-sift", "BruteForce" ),
|
||||
makePtr<DescriptorQualityEvaluator>( "SURF", "quality-descriptor-surf", "BruteForce" ),
|
||||
makePtr<DescriptorQualityEvaluator>( "FERN", "quality-descriptor-fern"),
|
||||
makePtr<CalonderDescriptorQualityEvaluator>()
|
||||
};
|
||||
|
||||
for( size_t i = 0; i < sizeof(evals)/sizeof(evals[0]); i++ )
|
||||
|
||||
@@ -80,4 +80,3 @@ int main(int argc, const char ** argv)
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ int main( int argc, const char** argv )
|
||||
// Call to update the view
|
||||
onTrackbar(0, 0);
|
||||
|
||||
int c = waitKey() & 255;
|
||||
int c = waitKey(0) & 255;
|
||||
|
||||
if( c == 27 )
|
||||
break;
|
||||
|
||||
@@ -59,7 +59,7 @@ int main( int /*argc*/, char** /*argv*/ )
|
||||
params.cov_mat_type = CvEM::COV_MAT_DIAGONAL;
|
||||
params.start_step = CvEM::START_E_STEP;
|
||||
params.means = em_model.get_means();
|
||||
params.covs = (const CvMat**)em_model.get_covs();
|
||||
params.covs = em_model.get_covs();
|
||||
params.weights = em_model.get_weights();
|
||||
|
||||
em_model2.train( samples, Mat(), params, &labels );
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// A demo program of the Extremal Region Filter algorithm described in
|
||||
// Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, CVPR 2012
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "opencv2/objdetect.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void er_draw(Mat &src, Mat &dst, ERStat& er);
|
||||
|
||||
void er_draw(Mat &src, Mat &dst, ERStat& er)
|
||||
{
|
||||
|
||||
if (er.parent != NULL) // deprecate the root region
|
||||
{
|
||||
int newMaskVal = 255;
|
||||
int flags = 4 + (newMaskVal << 8) + FLOODFILL_FIXED_RANGE + FLOODFILL_MASK_ONLY;
|
||||
floodFill(src,dst,Point(er.pixel%src.cols,er.pixel/src.cols),Scalar(255),0,Scalar(er.level),Scalar(0),flags);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
|
||||
|
||||
vector<ERStat> regions;
|
||||
|
||||
if (argc < 2) {
|
||||
cout << "Demo program of the Extremal Region Filter algorithm described in " << endl;
|
||||
cout << "Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, CVPR 2012" << endl << endl;
|
||||
cout << " Usage: " << argv[0] << " input_image <optional_groundtruth_image>" << endl;
|
||||
cout << " Default classifier files (trained_classifierNM*.xml) should be in ./" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Mat original = imread(argv[1]);
|
||||
Mat gt;
|
||||
if (argc > 2)
|
||||
{
|
||||
gt = imread(argv[2]);
|
||||
cvtColor(gt, gt, COLOR_RGB2GRAY);
|
||||
threshold(gt, gt, 254, 255, THRESH_BINARY);
|
||||
}
|
||||
Mat grey(original.size(),CV_8UC1);
|
||||
cvtColor(original,grey,COLOR_RGB2GRAY);
|
||||
|
||||
double t = (double)getTickCount();
|
||||
|
||||
// Build ER tree and filter with the 1st stage default classifier
|
||||
Ptr<ERFilter> er_filter1 = createERFilterNM1();
|
||||
|
||||
er_filter1->run(grey, regions);
|
||||
|
||||
t = (double)getTickCount() - t;
|
||||
cout << " --------------------------------------------------------------------------------------------------" << endl;
|
||||
cout << "\t FIRST STAGE CLASSIFIER done in " << t * 1000. / getTickFrequency() << " ms." << endl;
|
||||
cout << " --------------------------------------------------------------------------------------------------" << endl;
|
||||
cout << setw(9) << regions.size()+er_filter1->getNumRejected() << "\t Extremal Regions extracted " << endl;
|
||||
cout << setw(9) << regions.size() << "\t Extremal Regions selected by the first stage of the sequential classifier." << endl;
|
||||
cout << "\t \t (saving into out_second_stage.jpg)" << endl;
|
||||
cout << " --------------------------------------------------------------------------------------------------" << endl;
|
||||
|
||||
er_filter1.release();
|
||||
|
||||
// draw regions
|
||||
Mat mask = Mat::zeros(grey.rows+2,grey.cols+2,CV_8UC1);
|
||||
for (int r=0; r<(int)regions.size(); r++)
|
||||
er_draw(grey, mask, regions.at(r));
|
||||
mask = 255-mask;
|
||||
imwrite("out_first_stage.jpg", mask);
|
||||
|
||||
if (argc > 2)
|
||||
{
|
||||
Mat tmp_mask = (255-gt) & (255-mask(Rect(Point(1,1),Size(mask.cols-2,mask.rows-2))));
|
||||
cout << "Recall for the 1st stage filter = " << (float)countNonZero(tmp_mask) / countNonZero(255-gt) << endl;
|
||||
}
|
||||
|
||||
t = (double)getTickCount();
|
||||
|
||||
// Default second stage classifier
|
||||
Ptr<ERFilter> er_filter2 = createERFilterNM2();
|
||||
er_filter2->run(grey, regions);
|
||||
|
||||
t = (double)getTickCount() - t;
|
||||
cout << " --------------------------------------------------------------------------------------------------" << endl;
|
||||
cout << "\t SECOND STAGE CLASSIFIER done in " << t * 1000. / getTickFrequency() << " ms." << endl;
|
||||
cout << " --------------------------------------------------------------------------------------------------" << endl;
|
||||
cout << setw(9) << regions.size() << "\t Extremal Regions selected by the second stage of the sequential classifier." << endl;
|
||||
cout << "\t \t (saving into out_second_stage.jpg)" << endl;
|
||||
cout << " --------------------------------------------------------------------------------------------------" << endl;
|
||||
|
||||
er_filter2.release();
|
||||
|
||||
// draw regions
|
||||
mask = mask*0;
|
||||
for (int r=0; r<(int)regions.size(); r++)
|
||||
er_draw(grey, mask, regions.at(r));
|
||||
mask = 255-mask;
|
||||
imwrite("out_second_stage.jpg", mask);
|
||||
|
||||
if (argc > 2)
|
||||
{
|
||||
Mat tmp_mask = (255-gt) & (255-mask(Rect(Point(1,1),Size(mask.cols-2,mask.rows-2))));
|
||||
cout << "Recall for the 2nd stage filter = " << (float)countNonZero(tmp_mask) / countNonZero(255-gt) << endl;
|
||||
}
|
||||
|
||||
regions.clear();
|
||||
|
||||
}
|
||||
@@ -131,11 +131,11 @@ int main(int argc, char * argv[]) {
|
||||
//generate test data
|
||||
cout << "Extracting Test Data from images" << endl <<
|
||||
endl;
|
||||
Ptr<FeatureDetector> detector =
|
||||
Ptr<FeatureDetector> detector(
|
||||
new DynamicAdaptedFeatureDetector(
|
||||
AdjusterAdapter::create("STAR"), 130, 150, 5);
|
||||
Ptr<DescriptorExtractor> extractor =
|
||||
new SurfDescriptorExtractor(1000, 4, 2, false, true);
|
||||
AdjusterAdapter::create("STAR"), 130, 150, 5));
|
||||
Ptr<DescriptorExtractor> extractor(
|
||||
new SurfDescriptorExtractor(1000, 4, 2, false, true));
|
||||
Ptr<DescriptorMatcher> matcher =
|
||||
DescriptorMatcher::create("FlannBased");
|
||||
|
||||
@@ -183,8 +183,8 @@ int main(int argc, char * argv[]) {
|
||||
endl;
|
||||
Ptr<of2::FabMap> fabmap;
|
||||
|
||||
fabmap = new of2::FabMap2(tree, 0.39, 0, of2::FabMap::SAMPLED |
|
||||
of2::FabMap::CHOW_LIU);
|
||||
fabmap.reset(new of2::FabMap2(tree, 0.39, 0, of2::FabMap::SAMPLED |
|
||||
of2::FabMap::CHOW_LIU));
|
||||
fabmap->addTraining(trainData);
|
||||
|
||||
vector<of2::IMatch> matches;
|
||||
|
||||
@@ -33,7 +33,7 @@ int main(int argc, char** argv)
|
||||
std::string params_filename = std::string(argv[4]);
|
||||
|
||||
Ptr<GenericDescriptorMatcher> descriptorMatcher = GenericDescriptorMatcher::create(alg_name, params_filename);
|
||||
if( descriptorMatcher.empty() )
|
||||
if( !descriptorMatcher )
|
||||
{
|
||||
printf ("Cannot create descriptor\n");
|
||||
return 0;
|
||||
@@ -80,7 +80,7 @@ Mat DrawCorrespondences(const Mat& img1, const vector<KeyPoint>& features1, cons
|
||||
|
||||
for (size_t i = 0; i < features1.size(); i++)
|
||||
{
|
||||
circle(img_corr, features1[i].pt, 3, Scalar(255, 0, 0));
|
||||
circle(img_corr, features1[i].pt, 3, Scalar(0, 0, 255));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < features2.size(); i++)
|
||||
|
||||
@@ -296,15 +296,15 @@ int main( int argc, char** argv )
|
||||
help();
|
||||
|
||||
const string winName = "image";
|
||||
namedWindow( winName.c_str(), WINDOW_AUTOSIZE );
|
||||
setMouseCallback( winName.c_str(), on_mouse, 0 );
|
||||
namedWindow( winName, WINDOW_AUTOSIZE );
|
||||
setMouseCallback( winName, on_mouse, 0 );
|
||||
|
||||
gcapp.setImageAndWinName( image, winName );
|
||||
gcapp.showImage();
|
||||
|
||||
for(;;)
|
||||
{
|
||||
int c = waitKey();
|
||||
int c = waitKey(0);
|
||||
switch( (char) c )
|
||||
{
|
||||
case '\x1b':
|
||||
@@ -331,6 +331,6 @@ int main( int argc, char** argv )
|
||||
}
|
||||
|
||||
exit_main:
|
||||
destroyWindow( winName.c_str() );
|
||||
destroyWindow( winName );
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -61,4 +61,3 @@ int main(int argc, char** argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/contrib/hybridtracker.hpp"
|
||||
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ int main( int argc, char** argv )
|
||||
help();
|
||||
const char* imagename = argc > 1 ? argv[1] : "lena.jpg";
|
||||
#if DEMO_MIXED_API_USE
|
||||
Ptr<IplImage> iplimg = cvLoadImage(imagename); // Ptr<T> is safe ref-conting pointer class
|
||||
if(iplimg.empty())
|
||||
Ptr<IplImage> iplimg(cvLoadImage(imagename)); // Ptr<T> is safe ref-counting pointer class
|
||||
if(!iplimg)
|
||||
{
|
||||
fprintf(stderr, "Can not load image %s\n", imagename);
|
||||
return -1;
|
||||
|
||||
@@ -10,14 +10,14 @@ static void help(char** argv)
|
||||
{
|
||||
cout << "\nThis sample shows you how to read a sequence of images using the VideoCapture interface.\n"
|
||||
<< "Usage: " << argv[0] << " <image_mask> (example mask: example_%%02d.jpg)\n"
|
||||
<< "Image mask defines the name variation for the input images that have to be read as a sequence. \n"
|
||||
<< "Using the mask example_%%02d.jpg will read in images labeled as 'example_00.jpg', 'example_01.jpg', etc."
|
||||
<< "Image mask defines the name variation for the input images that have to be read as a sequence. \n"
|
||||
<< "Using the mask example_%%02d.jpg will read in images labeled as 'example_00.jpg', 'example_01.jpg', etc."
|
||||
<< endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc != 2)
|
||||
if(argc != 2)
|
||||
{
|
||||
help(argv);
|
||||
return 1;
|
||||
@@ -25,28 +25,28 @@ int main(int argc, char** argv)
|
||||
|
||||
string first_file = argv[1];
|
||||
VideoCapture sequence(first_file);
|
||||
|
||||
|
||||
if (!sequence.isOpened())
|
||||
{
|
||||
cerr << "Failed to open the image sequence!\n" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Mat image;
|
||||
namedWindow("Image sequence | press ESC to close", 1);
|
||||
|
||||
|
||||
for(;;)
|
||||
{
|
||||
// Read in image from sequence
|
||||
sequence >> image;
|
||||
|
||||
|
||||
// If no image was retrieved -> end of sequence
|
||||
if(image.empty())
|
||||
{
|
||||
cout << "End of Sequence" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
imshow("Image sequence | press ESC to close", image);
|
||||
|
||||
if(waitKey(500) == 27)
|
||||
|
||||
@@ -88,6 +88,8 @@ static void readDirectory( const string& directoryName, vector<String>& filename
|
||||
else
|
||||
filenames.push_back( string(dent->d_name) );
|
||||
}
|
||||
|
||||
closedir( dir );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ private:
|
||||
// Functions to store detector and templates in single XML/YAML file
|
||||
static cv::Ptr<cv::linemod::Detector> readLinemod(const std::string& filename)
|
||||
{
|
||||
cv::Ptr<cv::linemod::Detector> detector = new cv::linemod::Detector;
|
||||
cv::Ptr<cv::linemod::Detector> detector = cv::makePtr<cv::linemod::Detector>();
|
||||
cv::FileStorage fs(filename, cv::FileStorage::READ);
|
||||
detector->read(fs.root());
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ int main(int argc, char** argv)
|
||||
|
||||
// Create and LSD detector with standard or no refinement.
|
||||
#if 1
|
||||
Ptr<LineSegmentDetector> ls = createLineSegmentDetectorPtr(LSD_REFINE_STD);
|
||||
Ptr<LineSegmentDetector> ls = createLineSegmentDetector(LSD_REFINE_STD);
|
||||
#else
|
||||
Ptr<LineSegmentDetector> ls = createLineSegmentDetectorPtr(LSD_REFINE_NONE);
|
||||
Ptr<LineSegmentDetector> ls = createLineSegmentDetector(LSD_REFINE_NONE);
|
||||
#endif
|
||||
|
||||
double start = double(getTickCount());
|
||||
|
||||
@@ -84,7 +84,7 @@ static bool createDetectorDescriptorMatcher( const string& detectorType, const s
|
||||
descriptorMatcher = DescriptorMatcher::create( matcherType );
|
||||
cout << ">" << endl;
|
||||
|
||||
bool isCreated = !( featureDetector.empty() || descriptorExtractor.empty() || descriptorMatcher.empty() );
|
||||
bool isCreated = featureDetector && descriptorExtractor && descriptorMatcher;
|
||||
if( !isCreated )
|
||||
cout << "Can not create feature detector or descriptor extractor or descriptor matcher of given types." << endl << ">" << endl;
|
||||
|
||||
|
||||
@@ -8,12 +8,13 @@ using namespace std;
|
||||
|
||||
static void help()
|
||||
{
|
||||
cout << "This program demonstrates finding the minimum enclosing box or circle of a set\n"
|
||||
"of points using functions: minAreaRect() minEnclosingCircle().\n"
|
||||
"Random points are generated and then enclosed.\n"
|
||||
"Call:\n"
|
||||
"./minarea\n"
|
||||
"Using OpenCV v" << CV_VERSION << "\n" << endl;
|
||||
cout << "This program demonstrates finding the minimum enclosing box, triangle or circle of a set\n"
|
||||
<< "of points using functions: minAreaRect() minEnclosingTriangle() minEnclosingCircle().\n"
|
||||
<< "Random points are generated and then enclosed.\n\n"
|
||||
<< "Press ESC, 'q' or 'Q' to exit and any other key to regenerate the set of points.\n\n"
|
||||
<< "Call:\n"
|
||||
<< "./minarea\n"
|
||||
<< "Using OpenCV v" << CV_VERSION << "\n" << endl;
|
||||
}
|
||||
|
||||
int main( int /*argc*/, char** /*argv*/ )
|
||||
@@ -27,6 +28,8 @@ int main( int /*argc*/, char** /*argv*/ )
|
||||
{
|
||||
int i, count = rng.uniform(1, 101);
|
||||
vector<Point> points;
|
||||
|
||||
// Generate a random set of points
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
Point pt;
|
||||
@@ -36,23 +39,38 @@ int main( int /*argc*/, char** /*argv*/ )
|
||||
points.push_back(pt);
|
||||
}
|
||||
|
||||
// Find the minimum area enclosing bounding box
|
||||
RotatedRect box = minAreaRect(Mat(points));
|
||||
|
||||
// Find the minimum area enclosing triangle
|
||||
vector<Point2f> triangle;
|
||||
|
||||
minEnclosingTriangle(points, triangle);
|
||||
|
||||
// Find the minimum area enclosing circle
|
||||
Point2f center, vtx[4];
|
||||
float radius = 0;
|
||||
minEnclosingCircle(Mat(points), center, radius);
|
||||
box.points(vtx);
|
||||
|
||||
img = Scalar::all(0);
|
||||
|
||||
// Draw the points
|
||||
for( i = 0; i < count; i++ )
|
||||
circle( img, points[i], 3, Scalar(0, 0, 255), FILLED, LINE_AA );
|
||||
|
||||
// Draw the bounding box
|
||||
for( i = 0; i < 4; i++ )
|
||||
line(img, vtx[i], vtx[(i+1)%4], Scalar(0, 255, 0), 1, LINE_AA);
|
||||
|
||||
// Draw the triangle
|
||||
for( i = 0; i < 3; i++ )
|
||||
line(img, triangle[i], triangle[(i+1)%3], Scalar(255, 255, 0), 1, LINE_AA);
|
||||
|
||||
// Draw the circle
|
||||
circle(img, center, cvRound(radius), Scalar(0, 255, 255), 1, LINE_AA);
|
||||
|
||||
imshow( "rect & circle", img );
|
||||
imshow( "Rectangle, triangle & circle", img );
|
||||
|
||||
char key = (char)waitKey();
|
||||
if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC'
|
||||
|
||||
@@ -77,7 +77,7 @@ int main( int argc, char** argv )
|
||||
|
||||
OpenClose(open_close_pos, 0);
|
||||
ErodeDilate(erode_dilate_pos, 0);
|
||||
c = waitKey();
|
||||
c = waitKey(0);
|
||||
|
||||
if( (char)c == 27 )
|
||||
break;
|
||||
|
||||
@@ -43,7 +43,3 @@ int main(int, char* [])
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
const Scalar WHITE_COLOR = CV_RGB(255,255,255);
|
||||
const Scalar WHITE_COLOR = Scalar(255,255,255);
|
||||
const string winName = "points";
|
||||
const int testStep = 5;
|
||||
|
||||
@@ -69,15 +69,15 @@ static void on_mouse( int event, int x, int y, int /*flags*/, void* )
|
||||
// put the text
|
||||
stringstream text;
|
||||
text << "current class " << classColors.size()-1;
|
||||
putText( img, text.str(), Point(10,25), CV_FONT_HERSHEY_SIMPLEX, 0.8f, WHITE_COLOR, 2 );
|
||||
putText( img, text.str(), Point(10,25), FONT_HERSHEY_SIMPLEX, 0.8f, WHITE_COLOR, 2 );
|
||||
|
||||
text.str("");
|
||||
text << "total classes " << classColors.size();
|
||||
putText( img, text.str(), Point(10,50), CV_FONT_HERSHEY_SIMPLEX, 0.8f, WHITE_COLOR, 2 );
|
||||
putText( img, text.str(), Point(10,50), FONT_HERSHEY_SIMPLEX, 0.8f, WHITE_COLOR, 2 );
|
||||
|
||||
text.str("");
|
||||
text << "total points " << trainedPoints.size();
|
||||
putText(img, text.str(), cvPoint(10,75), CV_FONT_HERSHEY_SIMPLEX, 0.8f, WHITE_COLOR, 2 );
|
||||
putText(img, text.str(), Point(10,75), FONT_HERSHEY_SIMPLEX, 0.8f, WHITE_COLOR, 2 );
|
||||
|
||||
// draw points
|
||||
for( size_t i = 0; i < trainedPoints.size(); i++ )
|
||||
@@ -178,7 +178,7 @@ static void find_decision_boundary_SVM( CvSVMParams params )
|
||||
for( int i = 0; i < svmClassifier.get_support_vector_count(); i++ )
|
||||
{
|
||||
const float* supportVector = svmClassifier.get_support_vector(i);
|
||||
circle( imgDst, Point(supportVector[0],supportVector[1]), 5, CV_RGB(255,255,255), -1 );
|
||||
circle( imgDst, Point(supportVector[0],supportVector[1]), 5, Scalar(255,255,255), -1 );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -526,7 +526,7 @@ int main()
|
||||
{
|
||||
#if _NBC_
|
||||
find_decision_boundary_NBC();
|
||||
cvNamedWindow( "NormalBayesClassifier", WINDOW_AUTOSIZE );
|
||||
namedWindow( "NormalBayesClassifier", WINDOW_AUTOSIZE );
|
||||
imshow( "NormalBayesClassifier", imgDst );
|
||||
#endif
|
||||
#if _KNN_
|
||||
@@ -560,7 +560,7 @@ int main()
|
||||
|
||||
params.C = 10;
|
||||
find_decision_boundary_SVM( params );
|
||||
cvNamedWindow( "classificationSVM2", WINDOW_AUTOSIZE );
|
||||
namedWindow( "classificationSVM2", WINDOW_AUTOSIZE );
|
||||
imshow( "classificationSVM2", imgDst );
|
||||
#endif
|
||||
|
||||
|
||||
@@ -156,4 +156,3 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 95 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 111 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
@@ -96,8 +96,6 @@ int main(int argc, char** argv)
|
||||
if( !tmp_frame.data )
|
||||
break;
|
||||
bgsubtractor->apply(tmp_frame, bgmask, update_bg_model ? -1 : 0);
|
||||
//CvMat _bgmask = bgmask;
|
||||
//cvSegmentFGMask(&_bgmask);
|
||||
refineSegments(tmp_frame, bgmask, out_frame);
|
||||
imshow("video", tmp_frame);
|
||||
imshow("segmented", out_frame);
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* shape_context.cpp -- Shape context demo for shape matching
|
||||
*/
|
||||
|
||||
#include "opencv2/shape.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
static void help()
|
||||
{
|
||||
printf("\n"
|
||||
"This program demonstrates a method for shape comparisson based on Shape Context\n"
|
||||
"You should run the program providing a number between 1 and 20 for selecting an image in the folder shape_sample.\n"
|
||||
"Call\n"
|
||||
"./shape_example [number between 1 and 20]\n\n");
|
||||
}
|
||||
|
||||
static vector<Point> simpleContour( const Mat& currentQuery, int n=300 )
|
||||
{
|
||||
vector<vector<Point> > _contoursQuery;
|
||||
vector <Point> contoursQuery;
|
||||
findContours(currentQuery, _contoursQuery, RETR_LIST, CHAIN_APPROX_NONE);
|
||||
for (size_t border=0; border<_contoursQuery.size(); border++)
|
||||
{
|
||||
for (size_t p=0; p<_contoursQuery[border].size(); p++)
|
||||
{
|
||||
contoursQuery.push_back( _contoursQuery[border][p] );
|
||||
}
|
||||
}
|
||||
|
||||
// In case actual number of points is less than n
|
||||
int dummy=0;
|
||||
for (int add=(int)contoursQuery.size()-1; add<n; add++)
|
||||
{
|
||||
contoursQuery.push_back(contoursQuery[dummy++]); //adding dummy values
|
||||
}
|
||||
|
||||
// Uniformly sampling
|
||||
random_shuffle(contoursQuery.begin(), contoursQuery.end());
|
||||
vector<Point> cont;
|
||||
for (int i=0; i<n; i++)
|
||||
{
|
||||
cont.push_back(contoursQuery[i]);
|
||||
}
|
||||
return cont;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
help();
|
||||
string path = "./shape_sample/";
|
||||
int indexQuery = 1;
|
||||
if( argc < 2 )
|
||||
{
|
||||
std::cout<<"Using first image as query."<<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
sscanf( argv[1], "%i", &indexQuery );
|
||||
}
|
||||
cv::Ptr <cv::ShapeContextDistanceExtractor> mysc = cv::createShapeContextDistanceExtractor();
|
||||
|
||||
Size sz2Sh(300,300);
|
||||
stringstream queryName;
|
||||
queryName<<path<<indexQuery<<".png";
|
||||
Mat query=imread(queryName.str(), IMREAD_GRAYSCALE);
|
||||
Mat queryToShow;
|
||||
resize(query, queryToShow, sz2Sh);
|
||||
imshow("QUERY", queryToShow);
|
||||
moveWindow("TEST", 0,0);
|
||||
vector<Point> contQuery = simpleContour(query);
|
||||
int bestMatch = 0;
|
||||
float bestDis=FLT_MAX;
|
||||
for ( int ii=1; ii<=20; ii++ )
|
||||
{
|
||||
if (ii==indexQuery) continue;
|
||||
waitKey(30);
|
||||
stringstream iiname;
|
||||
iiname<<path<<ii<<".png";
|
||||
cout<<"name: "<<iiname.str()<<endl;
|
||||
Mat iiIm=imread(iiname.str(), 0);
|
||||
Mat iiToShow;
|
||||
resize(iiIm, iiToShow, sz2Sh);
|
||||
imshow("TEST", iiToShow);
|
||||
moveWindow("TEST", sz2Sh.width+50,0);
|
||||
vector<Point> contii = simpleContour(iiIm);
|
||||
float dis = mysc->computeDistance( contQuery, contii );
|
||||
if ( dis<bestDis )
|
||||
{
|
||||
bestMatch = ii;
|
||||
bestDis = dis;
|
||||
}
|
||||
std::cout<<" distance between "<<queryName.str()<<" and "<<iiname.str()<<" is: "<<dis<<std::endl;
|
||||
}
|
||||
destroyWindow("TEST");
|
||||
stringstream bestname;
|
||||
bestname<<path<<bestMatch<<".png";
|
||||
Mat iiIm=imread(bestname.str(), 0);
|
||||
Mat bestToShow;
|
||||
resize(iiIm, bestToShow, sz2Sh);
|
||||
imshow("BEST MATCH", bestToShow);
|
||||
moveWindow("BEST MATCH", sz2Sh.width+50,0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
After Width: | Height: | Size: 705 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 722 B |
|
After Width: | Height: | Size: 437 B |
|
After Width: | Height: | Size: 443 B |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 803 B |
|
After Width: | Height: | Size: 830 B |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 813 B |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 852 B |
|
After Width: | Height: | Size: 969 B |
|
After Width: | Height: | Size: 874 B |
|
After Width: | Height: | Size: 851 B |
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* shape_context.cpp -- Shape context demo for shape matching
|
||||
*/
|
||||
|
||||
#include "opencv2/shape.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/nonfree/nonfree.hpp"
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
static void help()
|
||||
{
|
||||
printf("\nThis program demonstrates how to use common interface for shape transformers\n"
|
||||
"Call\n"
|
||||
"shape_transformation [image1] [image2]\n");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
help();
|
||||
Mat img1 = imread(argv[1], IMREAD_GRAYSCALE);
|
||||
Mat img2 = imread(argv[2], IMREAD_GRAYSCALE);
|
||||
if(img1.empty() || img2.empty() || argc<2)
|
||||
{
|
||||
printf("Can't read one of the images\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// detecting keypoints
|
||||
SurfFeatureDetector detector(5000);
|
||||
vector<KeyPoint> keypoints1, keypoints2;
|
||||
detector.detect(img1, keypoints1);
|
||||
detector.detect(img2, keypoints2);
|
||||
|
||||
// computing descriptors
|
||||
SurfDescriptorExtractor extractor;
|
||||
Mat descriptors1, descriptors2;
|
||||
extractor.compute(img1, keypoints1, descriptors1);
|
||||
extractor.compute(img2, keypoints2, descriptors2);
|
||||
|
||||
// matching descriptors
|
||||
BFMatcher matcher(NORM_L2);
|
||||
vector<DMatch> matches;
|
||||
matcher.match(descriptors1, descriptors2, matches);
|
||||
|
||||
// drawing the results
|
||||
namedWindow("matches", 1);
|
||||
Mat img_matches;
|
||||
drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
|
||||
imshow("matches", img_matches);
|
||||
|
||||
// extract points
|
||||
vector<Point2f> pts1, pts2;
|
||||
for (size_t ii=0; ii<keypoints1.size(); ii++)
|
||||
pts1.push_back( keypoints1[ii].pt );
|
||||
for (size_t ii=0; ii<keypoints2.size(); ii++)
|
||||
pts2.push_back( keypoints2[ii].pt );
|
||||
|
||||
// Apply TPS
|
||||
Ptr<ThinPlateSplineShapeTransformer> mytps = createThinPlateSplineShapeTransformer(25000); //TPS with a relaxed constraint
|
||||
mytps->estimateTransformation(pts1, pts2, matches);
|
||||
mytps->warpImage(img2, img2);
|
||||
|
||||
imshow("Tranformed", img2);
|
||||
waitKey(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -41,15 +41,15 @@ namespace {
|
||||
cout << "press space to save a picture. q or esc to quit" << endl;
|
||||
namedWindow(window_name, WINDOW_KEEPRATIO); //resizable window;
|
||||
Mat frame;
|
||||
|
||||
|
||||
for (;;) {
|
||||
capture >> frame;
|
||||
if (frame.empty())
|
||||
break;
|
||||
|
||||
|
||||
imshow(window_name, frame);
|
||||
char key = (char)waitKey(30); //delay N millis, usually long enough to display and capture input
|
||||
|
||||
|
||||
switch (key) {
|
||||
case 'q':
|
||||
case 'Q':
|
||||
|
||||
@@ -401,4 +401,3 @@ int main(int argc, char** argv)
|
||||
StereoCalib(imagelist, boardSize, true, showRectified);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,5 +134,3 @@ int parseCmdArgs(int argc, char** argv)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||