1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Alekhin
2023-01-09 11:08:02 +00:00
880 changed files with 83958 additions and 9368 deletions
+2
View File
@@ -23,6 +23,8 @@ IF %ERRORLEVEL% EQU 0 (
GOTO :PYTHON_FOUND
)
CALL :QUERY_PYTHON 3.11
IF %ERRORLEVEL% EQU 0 GOTO :PYTHON_FOUND
CALL :QUERY_PYTHON 3.10
IF %ERRORLEVEL% EQU 0 GOTO :PYTHON_FOUND
CALL :QUERY_PYTHON 3.9
@@ -8,6 +8,7 @@
android:label="@string/app_name">
<activity
android:exported="true"
android:name=".Puzzle15Activity"
android:label="@string/app_name"
android:screenOrientation="landscape"
+10
View File
@@ -35,6 +35,7 @@ task clean(type: Delete) {
// }
//}
def opencv_strict_build_configuration = @ANDROID_STRICT_BUILD_CONFIGURATION@;
gradle.afterProject { project ->
if (project.pluginManager.hasPlugin('com.android.application')
@@ -90,5 +91,14 @@ gradle.afterProject { project ->
}
}
// Android Gradle Plugin (AGP) 3.5+ is required
// https://github.com/android/ndk-samples/wiki/Configure-NDK-Path
def isNdkVersionSupported = project.android.metaClass.getProperties().find { it.name == 'ndkVersion' } != null
if ((false || opencv_strict_build_configuration) && isNdkVersionSupported) {
gradle.println("Override ndkVersion for the project ${project.name}")
project.android {
ndkVersion '@ANDROID_NDK_REVISION@'
}
}
}
}
@@ -7,7 +7,9 @@
android:label="@string/app_name"
android:icon="@drawable/icon">
<activity android:name="CameraCalibrationActivity"
<activity
android:exported="true"
android:name="CameraCalibrationActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
@@ -8,7 +8,9 @@
android:icon="@drawable/icon"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<activity android:name="ColorBlobDetectionActivity"
<activity
android:exported="true"
android:name="ColorBlobDetectionActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
@@ -7,7 +7,9 @@
android:label="@string/app_name"
android:icon="@drawable/icon">
<activity android:name="FdActivity"
<activity
android:exported="true"
android:name="FdActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
@@ -7,7 +7,9 @@
android:label="@string/app_name"
android:icon="@drawable/icon">
<activity android:name="ImageManipulationsActivity"
<activity
android:exported="true"
android:name="ImageManipulationsActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
@@ -10,8 +10,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar"> <!--Full screen mode-->
<activity android:name=".MainActivity"
android:screenOrientation="landscape"> <!--Screen orientation-->
<activity
android:exported="true"
android:name=".MainActivity"
android:screenOrientation="landscape"> <!--Screen orientation-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@@ -8,7 +8,9 @@
android:icon="@drawable/icon"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<activity android:name="Tutorial1Activity"
<activity
android:exported="true"
android:name="Tutorial1Activity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
@@ -7,7 +7,9 @@
android:label="@string/app_name"
android:icon="@drawable/icon">
<activity android:name="Tutorial2Activity"
<activity
android:exported="true"
android:name="Tutorial2Activity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
@@ -7,7 +7,9 @@
android:label="@string/app_name"
android:icon="@drawable/icon">
<activity android:name="Tutorial3Activity"
<activity
android:exported="true"
android:name="Tutorial3Activity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
@@ -1,31 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.opencv.samples.tutorial4"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera2" android:required="false"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:icon="@drawable/icon">
<activity
android:name=".Tutorial4Activity"
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>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.opencv.samples.tutorial4"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera2" android:required="false"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:icon="@drawable/icon">
<activity
android:exported="true"
android:name=".Tutorial4Activity"
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>
</manifest>
+49 -13
View File
@@ -39,9 +39,6 @@ const char * usage =
"</images>\n"
"</opencv_storage>\n";
const char* liveCaptureHelp =
"When the live video from camera is used as input, the following hot-keys may be used:\n"
" <ESC>, 'q' - quit the program\n"
@@ -60,19 +57,25 @@ static void help(char** argv)
" # of board views actually available)\n"
" [-d=<delay>] # a minimum delay in ms between subsequent attempts to capture a next view\n"
" # (used only for video capturing)\n"
" [-s=<squareSize>] # square size in some user-defined units (1 by default)\n"
" [-s=<squareSize>] # square size in some user-defined units (1 by default)\n"
" [-o=<out_camera_params>] # the output filename for intrinsic [and extrinsic] parameters\n"
" [-op] # write detected feature points\n"
" [-oe] # write extrinsic parameters\n"
" [-oo] # write refined 3D object points\n"
" [-zt] # assume zero tangential distortion\n"
" [-a=<aspectRatio>] # fix aspect ratio (fx/fy)\n"
" [-a=<aspectRatio>] # fix aspect ratio (fx/fy)\n"
" [-p] # fix the principal point at the center\n"
" [-v] # flip the captured images around the horizontal axis\n"
" [-V] # use a video file, and not an image list, uses\n"
" # [input_data] string for the video file name\n"
" [-su] # show undistorted images after calibration\n"
" [-ws=<number_of_pixel>] # Half of search window for cornerSubPix (11 by default)\n"
" [-ws=<number_of_pixel>] # half of search window for cornerSubPix (11 by default)\n"
" [-fx=<X focal length>] # focal length in X-dir as an initial intrinsic guess (if this flag is used, fx, fy, cx, cy must be set)\n"
" [-fy=<Y focal length>] # focal length in Y-dir as an initial intrinsic guess (if this flag is used, fx, fy, cx, cy must be set)\n"
" [-cx=<X center point>] # camera center point in X-dir as an initial intrinsic guess (if this flag is used, fx, fy, cx, cy must be set)\n"
" [-cy=<Y center point>] # camera center point in Y-dir as an initial intrinsic guess (if this flag is used, fx, fy, cx, cy must be set)\n"
" [-imshow-scale # image resize scaling factor when displaying the results (must be >= 1)\n"
" [-enable-k3=<0/1> # to enable (1) or disable (0) K3 coefficient for the distortion model\n"
" [-dt=<distance>] # actual distance between top-left and top-right corners of\n"
" # the calibration grid. If this parameter is specified, a more\n"
" # accurate calibration method will be used which may be better\n"
@@ -152,7 +155,6 @@ static bool runCalibration( vector<vector<Point2f> > imagePoints,
vector<Point3f>& newObjPoints,
double& totalAvgErr)
{
cameraMatrix = Mat::eye(3, 3, CV_64F);
if( flags & CALIB_FIX_ASPECT_RATIO )
cameraMatrix.at<double>(0,0) = aspectRatio;
@@ -171,7 +173,7 @@ static bool runCalibration( vector<vector<Point2f> > imagePoints,
iFixedPoint = boardSize.width - 1;
rms = calibrateCameraRO(objectPoints, imagePoints, imageSize, iFixedPoint,
cameraMatrix, distCoeffs, rvecs, tvecs, newObjPoints,
flags | CALIB_FIX_K3 | CALIB_USE_LU);
flags | CALIB_USE_LU);
printf("RMS error reported by calibrateCamera: %g\n", rms);
bool ok = checkRange(cameraMatrix) && checkRange(distCoeffs);
@@ -192,7 +194,6 @@ static bool runCalibration( vector<vector<Point2f> > imagePoints,
return ok;
}
static void saveCameraParams( const string& filename,
Size imageSize, Size boardSize,
float squareSize, float aspectRatio, int flags,
@@ -347,7 +348,6 @@ static bool runAndSave(const string& outputFilename,
return ok;
}
int main( int argc, char** argv )
{
Size boardSize, imageSize;
@@ -376,6 +376,8 @@ int main( int argc, char** argv )
"{help ||}{w||}{h||}{pt|chessboard|}{n|10|}{d|1000|}{s|1|}{o|out_camera_data.yml|}"
"{op||}{oe||}{zt||}{a||}{p||}{v||}{V||}{su||}"
"{oo||}{ws|11|}{dt||}"
"{fx||}{fy||}{cx||}{cy||}"
"{imshow-scale|1|}{enable-k3|0|}"
"{@input_data|0|}");
if (parser.has("help"))
{
@@ -420,6 +422,23 @@ int main( int argc, char** argv )
else
inputFilename = parser.get<string>("@input_data");
int winSize = parser.get<int>("ws");
cameraMatrix = Mat::eye(3, 3, CV_64F);
if (parser.has("fx") && parser.has("fy") && parser.has("cx") && parser.has("cy"))
{
cameraMatrix.at<double>(0,0) = parser.get<double>("fx");
cameraMatrix.at<double>(0,2) = parser.get<double>("cx");
cameraMatrix.at<double>(1,1) = parser.get<double>("fy");
cameraMatrix.at<double>(1,2) = parser.get<double>("cy");
flags |= CALIB_USE_INTRINSIC_GUESS;
std::cout << "Use the following camera matrix as an initial guess:\n" << cameraMatrix << std::endl;
}
int viewScaleFactor = parser.get<int>("imshow-scale");
bool useK3 = parser.get<bool>("enable-k3");
std::cout << "Use K3 distortion coefficient? " << useK3 << std::endl;
if (!useK3)
{
flags |= CALIB_FIX_K3;
}
float grid_width = squareSize * (boardSize.width - 1);
bool release_object = false;
if (parser.has("dt")) {
@@ -555,8 +574,17 @@ int main( int argc, char** argv )
Mat temp = view.clone();
undistort(temp, view, cameraMatrix, distCoeffs);
}
if (viewScaleFactor > 1)
{
Mat viewScale;
resize(view, viewScale, Size(), 1.0/viewScaleFactor, 1.0/viewScaleFactor, INTER_AREA);
imshow("Image View", viewScale);
}
else
{
imshow("Image View", view);
}
imshow("Image View", view);
char key = (char)waitKey(capture.isOpened() ? 50 : 500);
if( key == 27 )
@@ -597,9 +625,17 @@ int main( int argc, char** argv )
view = imread(imageList[i], 1);
if(view.empty())
continue;
//undistort( view, rview, cameraMatrix, distCoeffs, cameraMatrix );
remap(view, rview, map1, map2, INTER_LINEAR);
imshow("Image View", rview);
if (viewScaleFactor > 1)
{
Mat rviewScale;
resize(rview, rviewScale, Size(), 1.0/viewScaleFactor, 1.0/viewScaleFactor, INTER_AREA);
imshow("Image View", rviewScale);
}
else
{
imshow("Image View", rview);
}
char c = (char)waitKey();
if( c == 27 || c == 'q' || c == 'Q' )
break;
@@ -0,0 +1,108 @@
/**
@file generalizedHoughTransform.cpp
@author Markus Heck
@brief Detects an object, given by a template, in an image using GeneralizedHoughBallard and GeneralizedHoughGuil.
*/
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
using namespace cv;
using namespace std;
int main() {
//! [generalized-hough-transform-load-and-setup]
// load source image and grayscale template
Mat image = imread("images/generalized_hough_mini_image.jpg");
Mat templ = imread("images/generalized_hough_mini_template.jpg", IMREAD_GRAYSCALE);
// create grayscale image
Mat grayImage;
cvtColor(image, grayImage, COLOR_RGB2GRAY);
// create variable for location, scale and rotation of detected templates
vector<Vec4f> positionBallard, positionGuil;
// template width and height
int w = templ.cols;
int h = templ.rows;
//! [generalized-hough-transform-load-and-setup]
//! [generalized-hough-transform-setup-parameters]
// create ballard and set options
Ptr<GeneralizedHoughBallard> ballard = createGeneralizedHoughBallard();
ballard->setMinDist(10);
ballard->setLevels(360);
ballard->setDp(2);
ballard->setMaxBufferSize(1000);
ballard->setVotesThreshold(40);
ballard->setCannyLowThresh(30);
ballard->setCannyHighThresh(110);
ballard->setTemplate(templ);
// create guil and set options
Ptr<GeneralizedHoughGuil> guil = createGeneralizedHoughGuil();
guil->setMinDist(10);
guil->setLevels(360);
guil->setDp(3);
guil->setMaxBufferSize(1000);
guil->setMinAngle(0);
guil->setMaxAngle(360);
guil->setAngleStep(1);
guil->setAngleThresh(1500);
guil->setMinScale(0.5);
guil->setMaxScale(2.0);
guil->setScaleStep(0.05);
guil->setScaleThresh(50);
guil->setPosThresh(10);
guil->setCannyLowThresh(30);
guil->setCannyHighThresh(110);
guil->setTemplate(templ);
//! [generalized-hough-transform-setup-parameters]
//! [generalized-hough-transform-run]
// execute ballard detection
ballard->detect(grayImage, positionBallard);
// execute guil detection
guil->detect(grayImage, positionGuil);
//! [generalized-hough-transform-run]
//! [generalized-hough-transform-draw-results]
// draw ballard
for (vector<Vec4f>::iterator iter = positionBallard.begin(); iter != positionBallard.end(); ++iter) {
RotatedRect rRect = RotatedRect(Point2f((*iter)[0], (*iter)[1]),
Size2f(w * (*iter)[2], h * (*iter)[2]),
(*iter)[3]);
Point2f vertices[4];
rRect.points(vertices);
for (int i = 0; i < 4; i++)
line(image, vertices[i], vertices[(i + 1) % 4], Scalar(255, 0, 0), 6);
}
// draw guil
for (vector<Vec4f>::iterator iter = positionGuil.begin(); iter != positionGuil.end(); ++iter) {
RotatedRect rRect = RotatedRect(Point2f((*iter)[0], (*iter)[1]),
Size2f(w * (*iter)[2], h * (*iter)[2]),
(*iter)[3]);
Point2f vertices[4];
rRect.points(vertices);
for (int i = 0; i < 4; i++)
line(image, vertices[i], vertices[(i + 1) % 4], Scalar(0, 255, 0), 2);
}
imshow("result_img", image);
waitKey();
//! [generalized-hough-transform-draw-results]
return EXIT_SUCCESS;
}
@@ -58,7 +58,7 @@ int main(int argc, char **argv)
calcHist(&hsv_roi, 1, channels, mask, roi_hist, 1, histSize, range);
normalize(roi_hist, roi_hist, 0, 255, NORM_MINMAX);
// Setup the termination criteria, either 10 iteration or move by atleast 1 pt
// Setup the termination criteria, either 10 iteration or move by at least 1 pt
TermCriteria term_crit(TermCriteria::EPS | TermCriteria::COUNT, 10, 1);
while(true){
@@ -58,7 +58,7 @@ int main(int argc, char **argv)
calcHist(&hsv_roi, 1, channels, mask, roi_hist, 1, histSize, range);
normalize(roi_hist, roi_hist, 0, 255, NORM_MINMAX);
// Setup the termination criteria, either 10 iteration or move by atleast 1 pt
// Setup the termination criteria, either 10 iteration or move by at least 1 pt
TermCriteria term_crit(TermCriteria::EPS | TermCriteria::COUNT, 10, 1);
while(true){
Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 27 KiB

@@ -1,8 +1,8 @@
person
bicycle
car
motorcycle
airplane
motorbike
aeroplane
bus
train
truck
@@ -55,12 +55,12 @@ pizza
donut
cake
chair
couch
potted plant
sofa
pottedplant
bed
dining table
diningtable
toilet
tv
tvmonitor
laptop
mouse
remote
+12
View File
@@ -19,4 +19,16 @@ foreach(sample_filename ${all_samples})
ocv_define_sample(tgt ${sample_filename} directx)
ocv_target_link_libraries(${tgt} PRIVATE ${OPENCV_LINKER_LIBS} ${OPENCV_DIRECTX_SAMPLES_REQUIRED_DEPS})
ocv_target_link_libraries(${tgt} PRIVATE "gdi32")
if(sample_filename STREQUAL "d3d9_interop.cpp")
ocv_target_link_libraries(${tgt} PRIVATE d3d9)
endif()
if(sample_filename STREQUAL "d3d9ex_interop.cpp")
ocv_target_link_libraries(${tgt} PRIVATE d3d9)
endif()
if(sample_filename STREQUAL "d3d10_interop.cpp")
ocv_target_link_libraries(${tgt} PRIVATE d3d10)
endif()
if(sample_filename STREQUAL "d3d11_interop.cpp")
ocv_target_link_libraries(${tgt} PRIVATE d3d11)
endif()
endforeach()
-1
View File
@@ -17,7 +17,6 @@
#include "d3dsample.hpp"
#pragma comment (lib, "d3d10.lib")
class D3D10WinApp : public D3DSample
{
-1
View File
@@ -17,7 +17,6 @@
#include "d3dsample.hpp"
#pragma comment (lib, "d3d11.lib")
class D3D11WinApp : public D3DSample
{
-1
View File
@@ -17,7 +17,6 @@
#include "d3dsample.hpp"
#pragma comment (lib, "d3d9.lib")
class D3D9WinApp : public D3DSample
-1
View File
@@ -17,7 +17,6 @@
#include "d3dsample.hpp"
#pragma comment (lib, "d3d9.lib")
class D3D9ExWinApp : public D3DSample
+5 -5
View File
@@ -23,16 +23,16 @@ opencv_fd:
# Might be used for all YOLOv2, TinyYolov2, YOLOv3, YOLOv4 and TinyYolov4
yolo:
load_info:
url: "https://pjreddie.com/media/files/yolov3.weights"
sha1: "520878f12e97cf820529daea502acca380f1cb8e"
model: "yolov3.weights"
config: "yolov3.cfg"
url: "https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights"
sha1: "0143deb6c46fcc7f74dd35bf3c14edc3784e99ee"
model: "yolov4.weights"
config: "yolov4.cfg"
mean: [0, 0, 0]
scale: 0.00392
width: 416
height: 416
rgb: true
classes: "object_detection_classes_yolov3.txt"
classes: "object_detection_classes_yolov4.txt"
sample: "object_detection"
tiny-yolo-voc:
+183
View File
@@ -0,0 +1,183 @@
// NanoTrack
// Link to original inference code: https://github.com/HonglinChu/NanoTrack
// Link to original training repo: https://github.com/HonglinChu/SiamTrackers/tree/master/NanoTrack
// backBone model: https://github.com/HonglinChu/SiamTrackers/blob/master/NanoTrack/models/onnx/nanotrack_backbone_sim.onnx
// headNeck model: https://github.com/HonglinChu/SiamTrackers/blob/master/NanoTrack/models/onnx/nanotrack_head_sim.onnx
#include <iostream>
#include <cmath>
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
using namespace cv;
using namespace cv::dnn;
const char *keys =
"{ help h | | Print help message }"
"{ input i | | Full path to input video folder, the specific camera index. (empty for camera 0) }"
"{ backbone | backbone.onnx | Path to onnx model of backbone.onnx}"
"{ headneck | headneck.onnx | Path to onnx model of headneck.onnx }"
"{ backend | 0 | Choose one of computation backends: "
"0: automatically (by default), "
"1: Halide language (http://halide-lang.org/), "
"2: Intel's Deep Learning Inference Engine (https://software.intel.com/openvino-toolkit), "
"3: OpenCV implementation, "
"4: VKCOM, "
"5: CUDA },"
"{ target | 0 | Choose one of target computation devices: "
"0: CPU target (by default), "
"1: OpenCL, "
"2: OpenCL fp16 (half-float precision), "
"3: VPU, "
"4: Vulkan, "
"6: CUDA, "
"7: CUDA fp16 (half-float preprocess) }"
;
static
int run(int argc, char** argv)
{
// Parse command line arguments.
CommandLineParser parser(argc, argv, keys);
if (parser.has("help"))
{
parser.printMessage();
return 0;
}
std::string inputName = parser.get<String>("input");
std::string backbone = parser.get<String>("backbone");
std::string headneck = parser.get<String>("headneck");
int backend = parser.get<int>("backend");
int target = parser.get<int>("target");
Ptr<TrackerNano> tracker;
try
{
TrackerNano::Params params;
params.backbone = samples::findFile(backbone);
params.neckhead = samples::findFile(headneck);
params.backend = backend;
params.target = target;
tracker = TrackerNano::create(params);
}
catch (const cv::Exception& ee)
{
std::cerr << "Exception: " << ee.what() << std::endl;
std::cout << "Can't load the network by using the following files:" << std::endl;
std::cout << "backbone : " << backbone << std::endl;
std::cout << "headneck : " << headneck << std::endl;
return 2;
}
const std::string winName = "NanoTrack";
namedWindow(winName, WINDOW_AUTOSIZE);
// Open a video file or an image file or a camera stream.
VideoCapture cap;
if (inputName.empty() || (isdigit(inputName[0]) && inputName.size() == 1))
{
int c = inputName.empty() ? 0 : inputName[0] - '0';
std::cout << "Trying to open camera #" << c << " ..." << std::endl;
if (!cap.open(c))
{
std::cout << "Capture from camera #" << c << " didn't work. Specify -i=<video> parameter to read from video file" << std::endl;
return 2;
}
}
else if (inputName.size())
{
inputName = samples::findFileOrKeep(inputName);
if (!cap.open(inputName))
{
std::cout << "Could not open: " << inputName << std::endl;
return 2;
}
}
// Read the first image.
Mat image;
cap >> image;
if (image.empty())
{
std::cerr << "Can't capture frame!" << std::endl;
return 2;
}
Mat image_select = image.clone();
putText(image_select, "Select initial bounding box you want to track.", Point(0, 15), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0));
putText(image_select, "And Press the ENTER key.", Point(0, 35), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0));
Rect selectRect = selectROI(winName, image_select);
std::cout << "ROI=" << selectRect << std::endl;
tracker->init(image, selectRect);
TickMeter tickMeter;
for (int count = 0; ; ++count)
{
cap >> image;
if (image.empty())
{
std::cerr << "Can't capture frame " << count << ". End of video stream?" << std::endl;
break;
}
Rect rect;
tickMeter.start();
bool ok = tracker->update(image, rect);
tickMeter.stop();
float score = tracker->getTrackingScore();
std::cout << "frame " << count <<
": predicted score=" << score <<
" rect=" << rect <<
" time=" << tickMeter.getTimeMilli() << "ms" <<
std::endl;
Mat render_image = image.clone();
if (ok)
{
rectangle(render_image, rect, Scalar(0, 255, 0), 2);
std::string timeLabel = format("Inference time: %.2f ms", tickMeter.getTimeMilli());
std::string scoreLabel = format("Score: %f", score);
putText(render_image, timeLabel, Point(0, 15), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0));
putText(render_image, scoreLabel, Point(0, 35), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0));
}
imshow(winName, render_image);
tickMeter.reset();
int c = waitKey(1);
if (c == 27 /*ESC*/)
break;
}
std::cout << "Exit" << std::endl;
return 0;
}
int main(int argc, char **argv)
{
try
{
return run(argc, argv);
}
catch (const std::exception& e)
{
std::cerr << "FATAL: C++ exception: " << e.what() << std::endl;
return 1;
}
}
+19 -43
View File
@@ -22,65 +22,41 @@ int main(int argc, const char* argv[])
const std::string fname(argv[1]);
cv::namedWindow("CPU", cv::WINDOW_NORMAL);
#if defined(HAVE_OPENGL)
cv::namedWindow("GPU", cv::WINDOW_OPENGL);
cv::cuda::setGlDevice();
#else
cv::namedWindow("GPU", cv::WINDOW_NORMAL);
#endif
cv::TickMeter tm;
cv::Mat frame;
cv::VideoCapture reader(fname);
for (;;)
{
if (!reader.read(frame))
break;
cv::imshow("CPU", frame);
if (cv::waitKey(3) > 0)
break;
}
cv::cuda::GpuMat d_frame;
cv::Ptr<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(fname);
cv::TickMeter tm;
std::vector<double> cpu_times;
std::vector<double> gpu_times;
int gpu_frame_count=0, cpu_frame_count=0;
for (;;)
{
tm.reset(); tm.start();
if (!reader.read(frame))
break;
tm.stop();
cpu_times.push_back(tm.getTimeMilli());
cpu_frame_count++;
cv::imshow("CPU", frame);
if (cv::waitKey(3) > 0)
break;
}
for (;;)
{
tm.reset(); tm.start();
if (!d_reader->nextFrame(d_frame))
break;
tm.stop();
gpu_times.push_back(tm.getTimeMilli());
gpu_frame_count++;
cv::imshow("GPU", d_frame);
#if defined(HAVE_OPENGL)
cv::imshow("GPU", cv::ogl::Texture2D(d_frame));
#else
d_frame.download(frame);
cv::imshow("GPU", frame);
#endif
if (cv::waitKey(3) > 0)
break;
}
if (!cpu_times.empty() && !gpu_times.empty())
{
std::cout << std::endl << "Results:" << std::endl;
std::sort(cpu_times.begin(), cpu_times.end());
std::sort(gpu_times.begin(), gpu_times.end());
double cpu_avg = std::accumulate(cpu_times.begin(), cpu_times.end(), 0.0) / cpu_times.size();
double gpu_avg = std::accumulate(gpu_times.begin(), gpu_times.end(), 0.0) / gpu_times.size();
std::cout << "CPU : Avg : " << cpu_avg << " ms FPS : " << 1000.0 / cpu_avg << " Frames " << cpu_frame_count << std::endl;
std::cout << "GPU : Avg : " << gpu_avg << " ms FPS : " << 1000.0 / gpu_avg << " Frames " << gpu_frame_count << std::endl;
}
return 0;
}
+10 -35
View File
@@ -2,7 +2,7 @@
#include "opencv2/opencv_modules.hpp"
#if defined(HAVE_OPENCV_CUDACODEC) && defined(_WIN32)
#if defined(HAVE_OPENCV_CUDACODEC)
#include <vector>
#include <numeric>
@@ -20,7 +20,7 @@ int main(int argc, const char* argv[])
return -1;
}
const double FPS = 25.0;
constexpr double fps = 25.0;
cv::VideoCapture reader(argv[1]);
@@ -37,17 +37,12 @@ int main(int argc, const char* argv[])
cv::Mat frame;
cv::cuda::GpuMat d_frame;
std::vector<double> cpu_times;
std::vector<double> gpu_times;
TickMeter tm;
cv::cuda::Stream stream;
for (int i = 1;; ++i)
{
std::cout << "Read " << i << " frame" << std::endl;
reader >> frame;
if (frame.empty())
{
std::cout << "Stop" << std::endl;
@@ -57,47 +52,27 @@ int main(int argc, const char* argv[])
if (!writer.isOpened())
{
std::cout << "Frame Size : " << frame.cols << "x" << frame.rows << std::endl;
std::cout << "Open CPU Writer" << std::endl;
if (!writer.open("output_cpu.avi", cv::VideoWriter::fourcc('X', 'V', 'I', 'D'), FPS, frame.size()))
const String outputFilename = "output_cpu.avi";
if (!writer.open(outputFilename, cv::VideoWriter::fourcc('X', 'V', 'I', 'D'), fps, frame.size()))
return -1;
std::cout << "Writing to " << outputFilename << std::endl;
}
if (d_writer.empty())
{
std::cout << "Open CUDA Writer" << std::endl;
const cv::String outputFilename = "output_gpu.avi";
d_writer = cv::cudacodec::createVideoWriter(outputFilename, frame.size(), FPS);
const cv::String outputFilename = "output_gpu.h264";
d_writer = cv::cudacodec::createVideoWriter(outputFilename, frame.size(), cv::cudacodec::Codec::H264, fps, cv::cudacodec::ColorFormat::BGR, 0, stream);
std::cout << "Writing to " << outputFilename << std::endl;
}
d_frame.upload(frame);
d_frame.upload(frame, stream);
std::cout << "Write " << i << " frame" << std::endl;
tm.reset(); tm.start();
writer.write(frame);
tm.stop();
cpu_times.push_back(tm.getTimeMilli());
tm.reset(); tm.start();
d_writer->write(d_frame);
tm.stop();
gpu_times.push_back(tm.getTimeMilli());
}
std::cout << std::endl << "Results:" << std::endl;
std::sort(cpu_times.begin(), cpu_times.end());
std::sort(gpu_times.begin(), gpu_times.end());
double cpu_avg = std::accumulate(cpu_times.begin(), cpu_times.end(), 0.0) / cpu_times.size();
double gpu_avg = std::accumulate(gpu_times.begin(), gpu_times.end(), 0.0) / gpu_times.size();
std::cout << "CPU [XVID] : Avg : " << cpu_avg << " ms FPS : " << 1000.0 / cpu_avg << std::endl;
std::cout << "GPU [H264] : Avg : " << gpu_avg << " ms FPS : " << 1000.0 / gpu_avg << std::endl;
return 0;
}
@@ -35,7 +35,7 @@ class Camshift {
Imgproc.calcHist(Arrays.asList(hsv_roi), channels, mask, roi_hist, histSize, range);
Core.normalize(roi_hist, roi_hist, 0, 255, Core.NORM_MINMAX);
// Setup the termination criteria, either 10 iteration or move by atleast 1 pt
// Setup the termination criteria, either 10 iteration or move by at least 1 pt
TermCriteria term_crit = new TermCriteria(TermCriteria.EPS | TermCriteria.COUNT, 10, 1);
while (true) {
@@ -34,7 +34,7 @@ class Meanshift {
Imgproc.calcHist(Arrays.asList(hsv_roi), channels, mask, roi_hist, histSize, range);
Core.normalize(roi_hist, roi_hist, 0, 255, Core.NORM_MINMAX);
// Setup the termination criteria, either 10 iteration or move by atleast 1 pt
// Setup the termination criteria, either 10 iteration or move by at least 1 pt
TermCriteria term_crit = new TermCriteria(TermCriteria.EPS | TermCriteria.COUNT, 10, 1);
while (true) {
-6
View File
@@ -27,12 +27,6 @@
#include "winapp.hpp"
#if defined(_WIN32)
# pragma comment(lib, "opengl32.lib")
# pragma comment(lib, "glu32.lib")
#endif
class GLWinApp : public WinApp
{
public:
+13 -2
View File
@@ -9,6 +9,9 @@ For DaSiamRPN:
network: https://www.dropbox.com/s/rr1lk9355vzolqv/dasiamrpn_model.onnx?dl=0
kernel_r1: https://www.dropbox.com/s/999cqx5zrfi7w4p/dasiamrpn_kernel_r1.onnx?dl=0
kernel_cls1: https://www.dropbox.com/s/qvmtszx5h339a0w/dasiamrpn_kernel_cls1.onnx?dl=0
For NanoTrack:
nanotrack_backbone: https://github.com/HonglinChu/SiamTrackers/blob/master/NanoTrack/models/nanotrackv2/nanotrack_backbone_sim.onnx
nanotrack_headneck: https://github.com/HonglinChu/SiamTrackers/blob/master/NanoTrack/models/nanotrackv2/nanotrack_head_sim.onnx
USAGE:
tracker.py [-h] [--input INPUT] [--tracker_algo TRACKER_ALGO]
@@ -18,6 +21,7 @@ USAGE:
[--dasiamrpn_kernel_cls1 DASIAMRPN_KERNEL_CLS1]
[--dasiamrpn_backend DASIAMRPN_BACKEND]
[--dasiamrpn_target DASIAMRPN_TARGET]
[--nanotrack_backbone NANOTRACK_BACKEND] [--nanotrack_headneck NANOTRACK_TARGET]
'''
# Python 2/3 compatibility
@@ -52,8 +56,13 @@ class App(object):
params.kernel_cls1 = self.args.dasiamrpn_kernel_cls1
params.kernel_r1 = self.args.dasiamrpn_kernel_r1
tracker = cv.TrackerDaSiamRPN_create(params)
elif self.trackerAlgorithm == 'nanotrack':
params = cv.TrackerNano_Params()
params.backbone = args.nanotrack_backbone
params.neckhead = args.nanotrack_headneck
tracker = cv.TrackerNano_create(params)
else:
sys.exit("Tracker {} is not recognized. Please use one of three available: mil, goturn, dasiamrpn.".format(self.trackerAlgorithm))
sys.exit("Tracker {} is not recognized. Please use one of three available: mil, goturn, dasiamrpn, nanotrack.".format(self.trackerAlgorithm))
return tracker
def initializeTracker(self, image):
@@ -117,12 +126,14 @@ if __name__ == '__main__':
print(__doc__)
parser = argparse.ArgumentParser(description="Run tracker")
parser.add_argument("--input", type=str, default="vtest.avi", help="Path to video source")
parser.add_argument("--tracker_algo", type=str, default="mil", help="One of available tracking algorithms: mil, goturn, dasiamrpn")
parser.add_argument("--tracker_algo", type=str, default="nanotrack", help="One of available tracking algorithms: mil, goturn, dasiamrpn, nanotrack")
parser.add_argument("--goturn", type=str, default="goturn.prototxt", help="Path to GOTURN architecture")
parser.add_argument("--goturn_model", type=str, default="goturn.caffemodel", help="Path to GOTERN model")
parser.add_argument("--dasiamrpn_net", type=str, default="dasiamrpn_model.onnx", help="Path to onnx model of DaSiamRPN net")
parser.add_argument("--dasiamrpn_kernel_r1", type=str, default="dasiamrpn_kernel_r1.onnx", help="Path to onnx model of DaSiamRPN kernel_r1")
parser.add_argument("--dasiamrpn_kernel_cls1", type=str, default="dasiamrpn_kernel_cls1.onnx", help="Path to onnx model of DaSiamRPN kernel_cls1")
parser.add_argument("--nanotrack_backbone", type=str, default="nanotrack_backbone_sim.onnx", help="Path to onnx model of NanoTrack backBone")
parser.add_argument("--nanotrack_headneck", type=str, default="nanotrack_head_sim.onnx", help="Path to onnx model of NanoTrack headNeck")
args = parser.parse_args()
App(args).run()
@@ -91,7 +91,7 @@ void MainPage::InvalidateSize()
// We have different widths to use depending on the view state
if (ApplicationView::Value != ApplicationViewState::Snapped)
{
// Make us as big as the the left over space, factoring in the ListBox width, the ListBox margins.
// Make us as big as the left over space, factoring in the ListBox width, the ListBox margins.
// and the LayoutRoot's margins
InputSection->Width = ((availableWidth) -
(layoutRootMarginLeft + layoutRootMarginRight + listBoxMarginLeft + listBoxMarginRight));