Merge remote-tracking branch 'upstream/master'
Conflicts: modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <stdio.h>
|
||||
|
||||
|
@@ -5,6 +5,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
using namespace cv;
|
||||
|
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
|
||||
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
|
||||
#include <opencv2/videoio/videoio.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
|
||||
|
||||
using namespace std;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#include <string> // for strings
|
||||
|
||||
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat)
|
||||
#include <opencv2/highgui/highgui.hpp> // Video write
|
||||
#include <opencv2/videoio/videoio.hpp> // Video write
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
@@ -60,7 +61,7 @@ void MatchingMethod( int, void* )
|
||||
int result_cols = img.cols - templ.cols + 1;
|
||||
int result_rows = img.rows - templ.rows + 1;
|
||||
|
||||
result.create( result_cols, result_rows, CV_32FC1 );
|
||||
result.create( result_rows, result_cols, CV_32FC1 );
|
||||
|
||||
/// Do the Matching and Normalize
|
||||
matchTemplate( img, templ, result, match_method );
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <iostream>
|
||||
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <iostream>
|
||||
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author Ana Huaman
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -3,6 +3,7 @@
|
||||
* @brief Demo code for detecting corners using OpenCV built-in functions
|
||||
* @author OpenCV team
|
||||
*/
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
|
@@ -7,6 +7,8 @@
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/calib3d.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include <iostream>
|
||||
#include "opencv2/calib3d/calib3d.hpp"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
using namespace cv;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
|
||||
@@ -24,6 +25,7 @@ static void help( char* progName)
|
||||
|
||||
#ifdef DEMO_MIXED_API_USE
|
||||
# include <opencv2/highgui/highgui_c.h>
|
||||
# include <opencv2/imgcodecs/imgcodecs_c.h>
|
||||
#endif
|
||||
|
||||
int main( int argc, char** argv )
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <iostream>
|
||||
|
79
samples/cpp/tutorial_code/features2D/AKAZE_match.cpp
Executable file
79
samples/cpp/tutorial_code/features2D/AKAZE_match.cpp
Executable file
@@ -0,0 +1,79 @@
|
||||
#include <opencv2/features2d.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
const float inlier_threshold = 2.5f; // Distance threshold to identify inliers
|
||||
const float nn_match_ratio = 0.8f; // Nearest neighbor matching ratio
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Mat img1 = imread("graf1.png", IMREAD_GRAYSCALE);
|
||||
Mat img2 = imread("graf3.png", IMREAD_GRAYSCALE);
|
||||
|
||||
Mat homography;
|
||||
FileStorage fs("H1to3p.xml", FileStorage::READ);
|
||||
fs.getFirstTopLevelNode() >> homography;
|
||||
|
||||
vector<KeyPoint> kpts1, kpts2;
|
||||
Mat desc1, desc2;
|
||||
|
||||
AKAZE akaze;
|
||||
akaze(img1, noArray(), kpts1, desc1);
|
||||
akaze(img2, noArray(), kpts2, desc2);
|
||||
|
||||
BFMatcher matcher(NORM_HAMMING);
|
||||
vector< vector<DMatch> > nn_matches;
|
||||
matcher.knnMatch(desc1, desc2, nn_matches, 2);
|
||||
|
||||
vector<KeyPoint> matched1, matched2, inliers1, inliers2;
|
||||
vector<DMatch> good_matches;
|
||||
for(size_t i = 0; i < nn_matches.size(); i++) {
|
||||
DMatch first = nn_matches[i][0];
|
||||
float dist1 = nn_matches[i][0].distance;
|
||||
float dist2 = nn_matches[i][1].distance;
|
||||
|
||||
if(dist1 < nn_match_ratio * dist2) {
|
||||
matched1.push_back(kpts1[first.queryIdx]);
|
||||
matched2.push_back(kpts2[first.trainIdx]);
|
||||
}
|
||||
}
|
||||
|
||||
for(unsigned i = 0; i < matched1.size(); i++) {
|
||||
Mat col = Mat::ones(3, 1, CV_64F);
|
||||
col.at<double>(0) = matched1[i].pt.x;
|
||||
col.at<double>(1) = matched1[i].pt.y;
|
||||
|
||||
col = homography * col;
|
||||
col /= col.at<double>(2);
|
||||
double dist = sqrt( pow(col.at<double>(0) - matched2[i].pt.x, 2) +
|
||||
pow(col.at<double>(1) - matched2[i].pt.y, 2));
|
||||
|
||||
if(dist < inlier_threshold) {
|
||||
int new_i = static_cast<int>(inliers1.size());
|
||||
inliers1.push_back(matched1[i]);
|
||||
inliers2.push_back(matched2[i]);
|
||||
good_matches.push_back(DMatch(new_i, new_i, 0));
|
||||
}
|
||||
}
|
||||
|
||||
Mat res;
|
||||
drawMatches(img1, inliers1, img2, inliers2, good_matches, res);
|
||||
imwrite("res.png", res);
|
||||
|
||||
double inlier_ratio = inliers1.size() * 1.0 / matched1.size();
|
||||
cout << "A-KAZE Matching Results" << endl;
|
||||
cout << "*******************************" << endl;
|
||||
cout << "# Keypoints 1: \t" << kpts1.size() << endl;
|
||||
cout << "# Keypoints 2: \t" << kpts2.size() << endl;
|
||||
cout << "# Matches: \t" << matched1.size() << endl;
|
||||
cout << "# Inliers: \t" << inliers1.size() << endl;
|
||||
cout << "# Inliers Ratio: \t" << inlier_ratio << endl;
|
||||
cout << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -8,6 +8,7 @@
|
||||
#include <iostream>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/nonfree/features2d.hpp"
|
||||
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include <iostream>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/calib3d/calib3d.hpp"
|
||||
#include "opencv2/nonfree/features2d.hpp"
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include <iostream>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/nonfree/features2d.hpp"
|
||||
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include <iostream>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/nonfree/features2d.hpp"
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#include <opencv2/core.hpp> // Basic OpenCV structures
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/imgproc.hpp>// Image processing methods for the CPU
|
||||
#include <opencv2/highgui.hpp>// Read images
|
||||
#include <opencv2/imgcodecs.hpp>// Read images
|
||||
|
||||
// CUDA structures and methods
|
||||
#include <opencv2/cudaarithm.hpp>
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
@@ -1,31 +1,32 @@
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/ml/ml.hpp>
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::ml;
|
||||
|
||||
int main()
|
||||
int main(int, char**)
|
||||
{
|
||||
// Data for visual representation
|
||||
int width = 512, height = 512;
|
||||
Mat image = Mat::zeros(height, width, CV_8UC3);
|
||||
|
||||
// Set up training data
|
||||
float labels[4] = {1.0, -1.0, -1.0, -1.0};
|
||||
Mat labelsMat(4, 1, CV_32FC1, labels);
|
||||
int labels[4] = {1, -1, -1, -1};
|
||||
Mat labelsMat(4, 1, CV_32SC1, labels);
|
||||
|
||||
float trainingData[4][2] = { {501, 10}, {255, 10}, {501, 255}, {10, 501} };
|
||||
Mat trainingDataMat(4, 2, CV_32FC1, trainingData);
|
||||
|
||||
// Set up SVM's parameters
|
||||
CvSVMParams params;
|
||||
params.svm_type = CvSVM::C_SVC;
|
||||
params.kernel_type = CvSVM::LINEAR;
|
||||
params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);
|
||||
SVM::Params params;
|
||||
params.svmType = SVM::C_SVC;
|
||||
params.kernelType = SVM::LINEAR;
|
||||
params.termCrit = TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6);
|
||||
|
||||
// Train the SVM
|
||||
CvSVM SVM;
|
||||
SVM.train(trainingDataMat, labelsMat, Mat(), Mat(), params);
|
||||
Ptr<SVM> svm = StatModel::train<SVM>(trainingDataMat, ROW_SAMPLE, labelsMat, params);
|
||||
|
||||
Vec3b green(0,255,0), blue (255,0,0);
|
||||
// Show the decision regions given by the SVM
|
||||
@@ -33,30 +34,30 @@ int main()
|
||||
for (int j = 0; j < image.cols; ++j)
|
||||
{
|
||||
Mat sampleMat = (Mat_<float>(1,2) << j,i);
|
||||
float response = SVM.predict(sampleMat);
|
||||
float response = svm->predict(sampleMat);
|
||||
|
||||
if (response == 1)
|
||||
image.at<Vec3b>(i,j) = green;
|
||||
else if (response == -1)
|
||||
image.at<Vec3b>(i,j) = blue;
|
||||
image.at<Vec3b>(i,j) = blue;
|
||||
}
|
||||
|
||||
// Show the training data
|
||||
int thickness = -1;
|
||||
int lineType = 8;
|
||||
circle( image, Point(501, 10), 5, Scalar( 0, 0, 0), thickness, lineType);
|
||||
circle( image, Point(255, 10), 5, Scalar(255, 255, 255), thickness, lineType);
|
||||
circle( image, Point(501, 255), 5, Scalar(255, 255, 255), thickness, lineType);
|
||||
circle( image, Point( 10, 501), 5, Scalar(255, 255, 255), thickness, lineType);
|
||||
circle( image, Point(501, 10), 5, Scalar( 0, 0, 0), thickness, lineType );
|
||||
circle( image, Point(255, 10), 5, Scalar(255, 255, 255), thickness, lineType );
|
||||
circle( image, Point(501, 255), 5, Scalar(255, 255, 255), thickness, lineType );
|
||||
circle( image, Point( 10, 501), 5, Scalar(255, 255, 255), thickness, lineType );
|
||||
|
||||
// Show support vectors
|
||||
thickness = 2;
|
||||
lineType = 8;
|
||||
int c = SVM.get_support_vector_count();
|
||||
Mat sv = svm->getSupportVectors();
|
||||
|
||||
for (int i = 0; i < c; ++i)
|
||||
for (int i = 0; i < sv.rows; ++i)
|
||||
{
|
||||
const float* v = SVM.get_support_vector(i);
|
||||
const float* v = sv.ptr<float>(i);
|
||||
circle( image, Point( (int) v[0], (int) v[1]), 6, Scalar(128, 128, 128), thickness, lineType);
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/ml/ml.hpp>
|
||||
|
||||
@@ -7,6 +8,7 @@
|
||||
#define FRAC_LINEAR_SEP 0.9f // Fraction of samples which compose the linear separable part
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::ml;
|
||||
using namespace std;
|
||||
|
||||
static void help()
|
||||
@@ -29,7 +31,7 @@ int main()
|
||||
|
||||
//--------------------- 1. Set up training data randomly ---------------------------------------
|
||||
Mat trainData(2*NTRAINING_SAMPLES, 2, CV_32FC1);
|
||||
Mat labels (2*NTRAINING_SAMPLES, 1, CV_32FC1);
|
||||
Mat labels (2*NTRAINING_SAMPLES, 1, CV_32SC1);
|
||||
|
||||
RNG rng(100); // Random value generation class
|
||||
|
||||
@@ -70,16 +72,15 @@ int main()
|
||||
labels.rowRange(NTRAINING_SAMPLES, 2*NTRAINING_SAMPLES).setTo(2); // Class 2
|
||||
|
||||
//------------------------ 2. Set up the support vector machines parameters --------------------
|
||||
CvSVMParams params;
|
||||
params.svm_type = SVM::C_SVC;
|
||||
SVM::Params params;
|
||||
params.svmType = SVM::C_SVC;
|
||||
params.C = 0.1;
|
||||
params.kernel_type = SVM::LINEAR;
|
||||
params.term_crit = TermCriteria(CV_TERMCRIT_ITER, (int)1e7, 1e-6);
|
||||
params.kernelType = SVM::LINEAR;
|
||||
params.termCrit = TermCriteria(TermCriteria::MAX_ITER, (int)1e7, 1e-6);
|
||||
|
||||
//------------------------ 3. Train the svm ----------------------------------------------------
|
||||
cout << "Starting training process" << endl;
|
||||
CvSVM svm;
|
||||
svm.train(trainData, labels, Mat(), Mat(), params);
|
||||
Ptr<SVM> svm = StatModel::train<SVM>(trainData, ROW_SAMPLE, labels, params);
|
||||
cout << "Finished training process" << endl;
|
||||
|
||||
//------------------------ 4. Show the decision regions ----------------------------------------
|
||||
@@ -88,7 +89,7 @@ int main()
|
||||
for (int j = 0; j < I.cols; ++j)
|
||||
{
|
||||
Mat sampleMat = (Mat_<float>(1,2) << i, j);
|
||||
float response = svm.predict(sampleMat);
|
||||
float response = svm->predict(sampleMat);
|
||||
|
||||
if (response == 1) I.at<Vec3b>(j, i) = green;
|
||||
else if (response == 2) I.at<Vec3b>(j, i) = blue;
|
||||
@@ -116,11 +117,11 @@ int main()
|
||||
//------------------------- 6. Show support vectors --------------------------------------------
|
||||
thick = 2;
|
||||
lineType = 8;
|
||||
int x = svm.get_support_vector_count();
|
||||
Mat sv = svm->getSupportVectors();
|
||||
|
||||
for (int i = 0; i < x; ++i)
|
||||
for (int i = 0; i < sv.rows; ++i)
|
||||
{
|
||||
const float* v = svm.get_support_vector(i);
|
||||
const float* v = sv.ptr<float>(i);
|
||||
circle( I, Point( (int) v[0], (int) v[1]), 6, Scalar(128, 128, 128), thick, lineType);
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "opencv2/objdetect.hpp"
|
||||
#include "opencv2/videoio.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @brief A simplified version of facedetect.cpp, show how to load a cascade classifier and how to find objects (Face + eyes) in a video stream - Using LBP here
|
||||
*/
|
||||
#include "opencv2/objdetect.hpp"
|
||||
#include "opencv2/videoio.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
|
||||
|
40
samples/cpp/tutorial_code/photo/decolorization/decolor.cpp
Normal file
40
samples/cpp/tutorial_code/photo/decolorization/decolor.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* decolor.cpp
|
||||
*
|
||||
* Author:
|
||||
* Siddharth Kherada <siddharthkherada27[at]gmail[dot]com>
|
||||
*
|
||||
* This tutorial demonstrates how to use OpenCV Decolorization Module.
|
||||
*
|
||||
* Input:
|
||||
* Color Image
|
||||
*
|
||||
* Output:
|
||||
* 1) Grayscale image
|
||||
* 2) Color boost image
|
||||
*
|
||||
*/
|
||||
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
CV_Assert(argc == 2);
|
||||
Mat I;
|
||||
I = imread(argv[1]);
|
||||
|
||||
Mat gray = Mat(I.size(),CV_8UC1);
|
||||
Mat color_boost = Mat(I.size(),CV_8UC3);
|
||||
|
||||
decolor(I,gray,color_boost);
|
||||
imshow("grayscale",gray);
|
||||
imshow("color_boost",color_boost);
|
||||
waitKey(0);
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
#include <opencv2/photo.hpp>
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* npr_demo.cpp
|
||||
*
|
||||
* Author:
|
||||
* Siddharth Kherada <siddharthkherada27[at]gmail[dot]com>
|
||||
*
|
||||
* This tutorial demonstrates how to use OpenCV Non-Photorealistic Rendering Module.
|
||||
* 1) Edge Preserve Smoothing
|
||||
* -> Using Normalized convolution Filter
|
||||
* -> Using Recursive Filter
|
||||
* 2) Detail Enhancement
|
||||
* 3) Pencil sketch/Color Pencil Drawing
|
||||
* 4) Stylization
|
||||
*
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if(argc < 2)
|
||||
{
|
||||
cout << "usage: " << argv[0] << " <Input image> " << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int num,type;
|
||||
|
||||
Mat I = imread(argv[1]);
|
||||
|
||||
if(!I.data)
|
||||
{
|
||||
cout << "Image not found" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
cout << " Edge Preserve Filter" << endl;
|
||||
cout << "----------------------" << endl;
|
||||
|
||||
cout << "Options: " << endl;
|
||||
cout << endl;
|
||||
|
||||
cout << "1) Edge Preserve Smoothing" << endl;
|
||||
cout << " -> Using Normalized convolution Filter" << endl;
|
||||
cout << " -> Using Recursive Filter" << endl;
|
||||
cout << "2) Detail Enhancement" << endl;
|
||||
cout << "3) Pencil sketch/Color Pencil Drawing" << endl;
|
||||
cout << "4) Stylization" << endl;
|
||||
cout << endl;
|
||||
|
||||
cout << "Press number 1-4 to choose from above techniques: ";
|
||||
|
||||
cin >> num;
|
||||
|
||||
Mat img;
|
||||
|
||||
if(num == 1)
|
||||
{
|
||||
cout << endl;
|
||||
cout << "Press 1 for Normalized Convolution Filter and 2 for Recursive Filter: ";
|
||||
|
||||
cin >> type;
|
||||
|
||||
edgePreservingFilter(I,img,type);
|
||||
imshow("Edge Preserve Smoothing",img);
|
||||
|
||||
}
|
||||
else if(num == 2)
|
||||
{
|
||||
detailEnhance(I,img);
|
||||
imshow("Detail Enhanced",img);
|
||||
}
|
||||
else if(num == 3)
|
||||
{
|
||||
Mat img1;
|
||||
pencilSketch(I,img1, img, 10 , 0.1f, 0.03f);
|
||||
imshow("Pencil Sketch",img1);
|
||||
imshow("Color Pencil Sketch",img);
|
||||
}
|
||||
else if(num == 4)
|
||||
{
|
||||
stylization(I,img);
|
||||
imshow("Stylization",img);
|
||||
}
|
||||
waitKey(0);
|
||||
}
|
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* cloning_demo.cpp
|
||||
*
|
||||
* Author:
|
||||
* Siddharth Kherada <siddharthkherada27[at]gmail[dot]com>
|
||||
*
|
||||
* This tutorial demonstrates how to use OpenCV seamless cloning
|
||||
* module without GUI.
|
||||
*
|
||||
* 1- Normal Cloning
|
||||
* 2- Mixed Cloning
|
||||
* 3- Monochrome Transfer
|
||||
* 4- Color Change
|
||||
* 5- Illumination change
|
||||
* 6- Texture Flattening
|
||||
|
||||
* The program takes as input a source and a destination image (for 1-3 methods)
|
||||
* and ouputs the cloned image.
|
||||
*
|
||||
* Download test images from opencv_extra folder @github.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << endl;
|
||||
cout << "Cloning Module" << endl;
|
||||
cout << "---------------" << endl;
|
||||
cout << "Options: " << endl;
|
||||
cout << endl;
|
||||
cout << "1) Normal Cloning " << endl;
|
||||
cout << "2) Mixed Cloning " << endl;
|
||||
cout << "3) Monochrome Transfer " << endl;
|
||||
cout << "4) Local Color Change " << endl;
|
||||
cout << "5) Local Illumination Change " << endl;
|
||||
cout << "6) Texture Flattening " << endl;
|
||||
cout << endl;
|
||||
cout << "Press number 1-6 to choose from above techniques: ";
|
||||
int num = 1;
|
||||
cin >> num;
|
||||
cout << endl;
|
||||
|
||||
if(num == 1)
|
||||
{
|
||||
string folder = "cloning/Normal_Cloning/";
|
||||
string original_path1 = folder + "source1.png";
|
||||
string original_path2 = folder + "destination1.png";
|
||||
string original_path3 = folder + "mask.png";
|
||||
|
||||
Mat source = imread(original_path1, IMREAD_COLOR);
|
||||
Mat destination = imread(original_path2, IMREAD_COLOR);
|
||||
Mat mask = imread(original_path3, IMREAD_COLOR);
|
||||
|
||||
if(source.empty())
|
||||
{
|
||||
cout << "Could not load source image " << original_path1 << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(destination.empty())
|
||||
{
|
||||
cout << "Could not load destination image " << original_path2 << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(mask.empty())
|
||||
{
|
||||
cout << "Could not load mask image " << original_path3 << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
Mat result;
|
||||
Point p;
|
||||
p.x = 400;
|
||||
p.y = 100;
|
||||
|
||||
seamlessClone(source, destination, mask, p, result, 1);
|
||||
|
||||
imshow("Output",result);
|
||||
imwrite(folder + "cloned.png", result);
|
||||
}
|
||||
else if(num == 2)
|
||||
{
|
||||
string folder = "cloning/Mixed_Cloning/";
|
||||
string original_path1 = folder + "source1.png";
|
||||
string original_path2 = folder + "destination1.png";
|
||||
string original_path3 = folder + "mask.png";
|
||||
|
||||
Mat source = imread(original_path1, IMREAD_COLOR);
|
||||
Mat destination = imread(original_path2, IMREAD_COLOR);
|
||||
Mat mask = imread(original_path3, IMREAD_COLOR);
|
||||
|
||||
if(source.empty())
|
||||
{
|
||||
cout << "Could not load source image " << original_path1 << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(destination.empty())
|
||||
{
|
||||
cout << "Could not load destination image " << original_path2 << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(mask.empty())
|
||||
{
|
||||
cout << "Could not load mask image " << original_path3 << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
Mat result;
|
||||
Point p;
|
||||
p.x = destination.size().width/2;
|
||||
p.y = destination.size().height/2;
|
||||
|
||||
seamlessClone(source, destination, mask, p, result, 2);
|
||||
|
||||
imshow("Output",result);
|
||||
imwrite(folder + "cloned.png", result);
|
||||
}
|
||||
else if(num == 3)
|
||||
{
|
||||
string folder = "cloning/Monochrome_Transfer/";
|
||||
string original_path1 = folder + "source1.png";
|
||||
string original_path2 = folder + "destination1.png";
|
||||
string original_path3 = folder + "mask.png";
|
||||
|
||||
Mat source = imread(original_path1, IMREAD_COLOR);
|
||||
Mat destination = imread(original_path2, IMREAD_COLOR);
|
||||
Mat mask = imread(original_path3, IMREAD_COLOR);
|
||||
|
||||
if(source.empty())
|
||||
{
|
||||
cout << "Could not load source image " << original_path1 << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(destination.empty())
|
||||
{
|
||||
cout << "Could not load destination image " << original_path2 << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(mask.empty())
|
||||
{
|
||||
cout << "Could not load mask image " << original_path3 << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
Mat result;
|
||||
Point p;
|
||||
p.x = destination.size().width/2;
|
||||
p.y = destination.size().height/2;
|
||||
|
||||
seamlessClone(source, destination, mask, p, result, 3);
|
||||
|
||||
imshow("Output",result);
|
||||
imwrite(folder + "cloned.png", result);
|
||||
}
|
||||
else if(num == 4)
|
||||
{
|
||||
string folder = "cloning/Color_Change/";
|
||||
string original_path1 = folder + "source1.png";
|
||||
string original_path2 = folder + "mask.png";
|
||||
|
||||
Mat source = imread(original_path1, IMREAD_COLOR);
|
||||
Mat mask = imread(original_path2, IMREAD_COLOR);
|
||||
|
||||
if(source.empty())
|
||||
{
|
||||
cout << "Could not load source image " << original_path1 << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(mask.empty())
|
||||
{
|
||||
cout << "Could not load mask image " << original_path2 << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
Mat result;
|
||||
|
||||
colorChange(source, mask, result, 1.5, .5, .5);
|
||||
|
||||
imshow("Output",result);
|
||||
imwrite(folder + "cloned.png", result);
|
||||
}
|
||||
else if(num == 5)
|
||||
{
|
||||
string folder = "cloning/Illumination_Change/";
|
||||
string original_path1 = folder + "source1.png";
|
||||
string original_path2 = folder + "mask.png";
|
||||
|
||||
Mat source = imread(original_path1, IMREAD_COLOR);
|
||||
Mat mask = imread(original_path2, IMREAD_COLOR);
|
||||
|
||||
if(source.empty())
|
||||
{
|
||||
cout << "Could not load source image " << original_path1 << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(mask.empty())
|
||||
{
|
||||
cout << "Could not load mask image " << original_path2 << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
Mat result;
|
||||
|
||||
illuminationChange(source, mask, result, 0.2f, 0.4f);
|
||||
|
||||
imshow("Output",result);
|
||||
imwrite(folder + "cloned.png", result);
|
||||
}
|
||||
else if(num == 6)
|
||||
{
|
||||
string folder = "cloning/Texture_Flattening/";
|
||||
string original_path1 = folder + "source1.png";
|
||||
string original_path2 = folder + "mask.png";
|
||||
|
||||
Mat source = imread(original_path1, IMREAD_COLOR);
|
||||
Mat mask = imread(original_path2, IMREAD_COLOR);
|
||||
|
||||
if(source.empty())
|
||||
{
|
||||
cout << "Could not load source image " << original_path1 << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(mask.empty())
|
||||
{
|
||||
cout << "Could not load mask image " << original_path2 << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
Mat result;
|
||||
|
||||
textureFlattening(source, mask, result, 30, 45, 3);
|
||||
|
||||
imshow("Output",result);
|
||||
imwrite(folder + "cloned.png", result);
|
||||
}
|
||||
waitKey(0);
|
||||
}
|
546
samples/cpp/tutorial_code/photo/seamless_cloning/cloning_gui.cpp
Normal file
546
samples/cpp/tutorial_code/photo/seamless_cloning/cloning_gui.cpp
Normal file
@@ -0,0 +1,546 @@
|
||||
/*
|
||||
* cloning.cpp
|
||||
*
|
||||
* Author:
|
||||
* Siddharth Kherada <siddharthkherada27[at]gmail[dot]com>
|
||||
*
|
||||
* This tutorial demonstrates how to use OpenCV seamless cloning
|
||||
* module.
|
||||
*
|
||||
* 1- Normal Cloning
|
||||
* 2- Mixed Cloning
|
||||
* 3- Monochrome Transfer
|
||||
* 4- Color Change
|
||||
* 5- Illumination change
|
||||
* 6- Texture Flattening
|
||||
|
||||
* The program takes as input a source and a destination image (for 1-3 methods)
|
||||
* and ouputs the cloned image.
|
||||
|
||||
* Step 1:
|
||||
* -> In the source image, select the region of interest by left click mouse button. A Polygon ROI will be created by left clicking mouse button.
|
||||
* -> To set the Polygon ROI, click the right mouse button or 'd' key.
|
||||
* -> To reset the region selected, click the middle mouse button or 'r' key.
|
||||
|
||||
* Step 2:
|
||||
* -> In the destination image, select the point where you want to place the ROI in the image by left clicking mouse button.
|
||||
* -> To get the cloned result, click the right mouse button or 'c' key.
|
||||
* -> To quit the program, use 'q' key.
|
||||
*
|
||||
* Result: The cloned image will be displayed.
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
Mat img0, img1, img2, res, res1, final, final1, blend;
|
||||
|
||||
Point point;
|
||||
int drag = 0;
|
||||
int destx, desty;
|
||||
|
||||
int numpts = 100;
|
||||
Point* pts = new Point[100];
|
||||
Point* pts2 = new Point[100];
|
||||
Point* pts_diff = new Point[100];
|
||||
|
||||
int var = 0;
|
||||
int flag = 0, flag1 = 0, flag4 = 0;
|
||||
|
||||
int minx, miny, maxx, maxy, lenx, leny;
|
||||
int minxd, minyd, maxxd, maxyd, lenxd, lenyd;
|
||||
|
||||
int channel, num, kernel_size;
|
||||
|
||||
float alpha,beta;
|
||||
|
||||
float red, green, blue;
|
||||
|
||||
double low_t, high_t;
|
||||
|
||||
void source(int, int, int, int, void*);
|
||||
void destination(int, int, int, int, void*);
|
||||
void checkfile(char*);
|
||||
|
||||
void source(int event, int x, int y, int, void*)
|
||||
{
|
||||
|
||||
if (event == EVENT_LBUTTONDOWN && !drag)
|
||||
{
|
||||
if(flag1 == 0)
|
||||
{
|
||||
if(var==0)
|
||||
img1 = img0.clone();
|
||||
point = Point(x, y);
|
||||
circle(img1,point,2,Scalar(0, 0, 255),-1, 8, 0);
|
||||
pts[var] = point;
|
||||
var++;
|
||||
drag = 1;
|
||||
if(var>1)
|
||||
line(img1,pts[var-2], point, Scalar(0, 0, 255), 2, 8, 0);
|
||||
|
||||
imshow("Source", img1);
|
||||
}
|
||||
}
|
||||
|
||||
if (event == EVENT_LBUTTONUP && drag)
|
||||
{
|
||||
imshow("Source", img1);
|
||||
|
||||
drag = 0;
|
||||
}
|
||||
if (event == EVENT_RBUTTONDOWN)
|
||||
{
|
||||
flag1 = 1;
|
||||
img1 = img0.clone();
|
||||
for(int i = var; i < numpts ; i++)
|
||||
pts[i] = point;
|
||||
|
||||
if(var!=0)
|
||||
{
|
||||
const Point* pts3[1] = {&pts[0]};
|
||||
polylines( img1, pts3, &numpts,1, 1, Scalar(0,0,0), 2, 8, 0);
|
||||
}
|
||||
|
||||
for(int i=0;i<var;i++)
|
||||
{
|
||||
minx = min(minx,pts[i].x);
|
||||
maxx = max(maxx,pts[i].x);
|
||||
miny = min(miny,pts[i].y);
|
||||
maxy = max(maxy,pts[i].y);
|
||||
}
|
||||
lenx = maxx - minx;
|
||||
leny = maxy - miny;
|
||||
|
||||
int mid_pointx = minx + lenx/2;
|
||||
int mid_pointy = miny + leny/2;
|
||||
|
||||
for(int i=0;i<var;i++)
|
||||
{
|
||||
pts_diff[i].x = pts[i].x - mid_pointx;
|
||||
pts_diff[i].y = pts[i].y - mid_pointy;
|
||||
}
|
||||
|
||||
imshow("Source", img1);
|
||||
}
|
||||
|
||||
if (event == EVENT_RBUTTONUP)
|
||||
{
|
||||
flag = var;
|
||||
|
||||
final = Mat::zeros(img0.size(),CV_8UC3);
|
||||
res1 = Mat::zeros(img0.size(),CV_8UC1);
|
||||
const Point* pts4[1] = {&pts[0]};
|
||||
|
||||
fillPoly(res1, pts4,&numpts, 1, Scalar(255, 255, 255), 8, 0);
|
||||
bitwise_and(img0, img0, final,res1);
|
||||
|
||||
imshow("Source", img1);
|
||||
|
||||
if(num == 4)
|
||||
{
|
||||
colorChange(img0,res1,blend,red,green,blue);
|
||||
imshow("Color Change Image", blend);
|
||||
waitKey(0);
|
||||
|
||||
}
|
||||
else if(num == 5)
|
||||
{
|
||||
illuminationChange(img0,res1,blend,alpha,beta);
|
||||
imshow("Illum Change Image", blend);
|
||||
waitKey(0);
|
||||
}
|
||||
else if(num == 6)
|
||||
{
|
||||
textureFlattening(img0,res1,blend,low_t,high_t,kernel_size);
|
||||
imshow("Texture Flattened", blend);
|
||||
waitKey(0);
|
||||
}
|
||||
|
||||
}
|
||||
if (event == EVENT_MBUTTONDOWN)
|
||||
{
|
||||
for(int i = 0; i < numpts ; i++)
|
||||
{
|
||||
pts[i].x=0;
|
||||
pts[i].y=0;
|
||||
}
|
||||
var = 0;
|
||||
flag1 = 0;
|
||||
minx = INT_MAX; miny = INT_MAX; maxx = INT_MIN; maxy = INT_MIN;
|
||||
imshow("Source", img0);
|
||||
if(num == 1 || num == 2 || num == 3)
|
||||
imshow("Destination",img2);
|
||||
drag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void destination(int event, int x, int y, int, void*)
|
||||
{
|
||||
|
||||
Mat im1;
|
||||
minxd = INT_MAX; minyd = INT_MAX; maxxd = INT_MIN; maxyd = INT_MIN;
|
||||
im1 = img2.clone();
|
||||
if (event == EVENT_LBUTTONDOWN)
|
||||
{
|
||||
flag4 = 1;
|
||||
if(flag1 == 1)
|
||||
{
|
||||
point = Point(x, y);
|
||||
|
||||
for(int i=0;i<var;i++)
|
||||
{
|
||||
pts2[i].x = point.x + pts_diff[i].x;
|
||||
pts2[i].y = point.y + pts_diff[i].y;
|
||||
}
|
||||
|
||||
for(int i=var;i<numpts;i++)
|
||||
{
|
||||
pts2[i].x = point.x + pts_diff[0].x;
|
||||
pts2[i].y = point.y + pts_diff[0].y;
|
||||
}
|
||||
|
||||
const Point* pts5[1] = {&pts2[0]};
|
||||
polylines( im1, pts5, &numpts,1, 1, Scalar(0,0,255), 2, 8, 0);
|
||||
|
||||
destx = x;
|
||||
desty = y;
|
||||
|
||||
imshow("Destination", im1);
|
||||
}
|
||||
}
|
||||
if (event == EVENT_RBUTTONUP)
|
||||
{
|
||||
for(int i=0;i<flag;i++)
|
||||
{
|
||||
minxd = min(minxd,pts2[i].x);
|
||||
maxxd = max(maxxd,pts2[i].x);
|
||||
minyd = min(minyd,pts2[i].y);
|
||||
maxyd = max(maxyd,pts2[i].y);
|
||||
}
|
||||
|
||||
if(maxxd > im1.size().width || maxyd > im1.size().height || minxd < 0 || minyd < 0)
|
||||
{
|
||||
cout << "Index out of range" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
final1 = Mat::zeros(img2.size(),CV_8UC3);
|
||||
res = Mat::zeros(img2.size(),CV_8UC1);
|
||||
for(int i=miny, k=minyd;i<(miny+leny);i++,k++)
|
||||
for(int j=minx,l=minxd ;j<(minx+lenx);j++,l++)
|
||||
{
|
||||
for(int c=0;c<channel;c++)
|
||||
{
|
||||
final1.at<uchar>(k,l*channel+c) = final.at<uchar>(i,j*channel+c);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const Point* pts6[1] = {&pts2[0]};
|
||||
fillPoly(res, pts6, &numpts, 1, Scalar(255, 255, 255), 8, 0);
|
||||
|
||||
if(num == 1 || num == 2 || num == 3)
|
||||
{
|
||||
seamlessClone(img0,img2,res1,point,blend,num);
|
||||
imshow("Cloned Image", blend);
|
||||
imwrite("cloned.png",blend);
|
||||
waitKey(0);
|
||||
}
|
||||
|
||||
for(int i = 0; i < flag ; i++)
|
||||
{
|
||||
pts2[i].x=0;
|
||||
pts2[i].y=0;
|
||||
}
|
||||
|
||||
minxd = INT_MAX; minyd = INT_MAX; maxxd = INT_MIN; maxyd = INT_MIN;
|
||||
}
|
||||
|
||||
im1.release();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << endl;
|
||||
cout << "Cloning Module" << endl;
|
||||
cout << "---------------" << endl;
|
||||
cout << "Step 1:" << endl;
|
||||
cout << " -> In the source image, select the region of interest by left click mouse button. A Polygon ROI will be created by left clicking mouse button." << endl;
|
||||
cout << " -> To set the Polygon ROI, click the right mouse button or use 'd' key" << endl;
|
||||
cout << " -> To reset the region selected, click the middle mouse button or use 'r' key." << endl;
|
||||
|
||||
cout << "Step 2:" << endl;
|
||||
cout << " -> In the destination image, select the point where you want to place the ROI in the image by left clicking mouse button." << endl;
|
||||
cout << " -> To get the cloned result, click the right mouse button or use 'c' key." << endl;
|
||||
cout << " -> To quit the program, use 'q' key." << endl;
|
||||
cout << endl;
|
||||
cout << "Options: " << endl;
|
||||
cout << endl;
|
||||
cout << "1) Normal Cloning " << endl;
|
||||
cout << "2) Mixed Cloning " << endl;
|
||||
cout << "3) Monochrome Transfer " << endl;
|
||||
cout << "4) Local Color Change " << endl;
|
||||
cout << "5) Local Illumination Change " << endl;
|
||||
cout << "6) Texture Flattening " << endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
cout << "Press number 1-6 to choose from above techniques: ";
|
||||
cin >> num;
|
||||
cout << endl;
|
||||
|
||||
minx = INT_MAX; miny = INT_MAX; maxx = INT_MIN; maxy = INT_MIN;
|
||||
|
||||
minxd = INT_MAX; minyd = INT_MAX; maxxd = INT_MIN; maxyd = INT_MIN;
|
||||
|
||||
int flag3 = 0;
|
||||
|
||||
if(num == 1 || num == 2 || num == 3)
|
||||
{
|
||||
|
||||
string src,dest;
|
||||
cout << "Enter Source Image: ";
|
||||
cin >> src;
|
||||
|
||||
cout << "Enter Destination Image: ";
|
||||
cin >> dest;
|
||||
|
||||
img0 = imread(src);
|
||||
|
||||
img2 = imread(dest);
|
||||
|
||||
if(!img0.data)
|
||||
{
|
||||
cout << "Source Image does not exist" << endl;
|
||||
exit(0);
|
||||
}
|
||||
if(!img2.data)
|
||||
{
|
||||
cout << "Destination Image does not exist" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
channel = img0.channels();
|
||||
|
||||
res = Mat::zeros(img2.size(),CV_8UC1);
|
||||
res1 = Mat::zeros(img0.size(),CV_8UC1);
|
||||
final = Mat::zeros(img0.size(),CV_8UC3);
|
||||
final1 = Mat::zeros(img2.size(),CV_8UC3);
|
||||
//////////// source image ///////////////////
|
||||
|
||||
namedWindow("Source", 1);
|
||||
setMouseCallback("Source", source, NULL);
|
||||
imshow("Source", img0);
|
||||
|
||||
/////////// destination image ///////////////
|
||||
|
||||
namedWindow("Destination", 1);
|
||||
setMouseCallback("Destination", destination, NULL);
|
||||
imshow("Destination",img2);
|
||||
|
||||
}
|
||||
else if(num == 4)
|
||||
{
|
||||
string src;
|
||||
cout << "Enter Source Image: ";
|
||||
cin >> src;
|
||||
|
||||
cout << "Enter RGB values: " << endl;
|
||||
cout << "Red: ";
|
||||
cin >> red;
|
||||
|
||||
cout << "Green: ";
|
||||
cin >> green;
|
||||
|
||||
cout << "Blue: ";
|
||||
cin >> blue;
|
||||
|
||||
img0 = imread(src);
|
||||
|
||||
if(!img0.data)
|
||||
{
|
||||
cout << "Source Image does not exist" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
res1 = Mat::zeros(img0.size(),CV_8UC1);
|
||||
final = Mat::zeros(img0.size(),CV_8UC3);
|
||||
|
||||
//////////// source image ///////////////////
|
||||
|
||||
namedWindow("Source", 1);
|
||||
setMouseCallback("Source", source, NULL);
|
||||
imshow("Source", img0);
|
||||
|
||||
}
|
||||
else if(num == 5)
|
||||
{
|
||||
string src;
|
||||
cout << "Enter Source Image: ";
|
||||
cin >> src;
|
||||
|
||||
cout << "alpha: ";
|
||||
cin >> alpha;
|
||||
|
||||
cout << "beta: ";
|
||||
cin >> beta;
|
||||
|
||||
img0 = imread(src);
|
||||
|
||||
if(!img0.data)
|
||||
{
|
||||
cout << "Source Image does not exist" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
res1 = Mat::zeros(img0.size(),CV_8UC1);
|
||||
final = Mat::zeros(img0.size(),CV_8UC3);
|
||||
|
||||
//////////// source image ///////////////////
|
||||
|
||||
namedWindow("Source", 1);
|
||||
setMouseCallback("Source", source, NULL);
|
||||
imshow("Source", img0);
|
||||
|
||||
}
|
||||
else if(num == 6)
|
||||
{
|
||||
string src;
|
||||
cout << "Enter Source Image: ";
|
||||
cin >> src;
|
||||
|
||||
cout << "low_threshold: ";
|
||||
cin >> low_t;
|
||||
|
||||
cout << "high_threshold: ";
|
||||
cin >> high_t;
|
||||
|
||||
cout << "kernel_size: ";
|
||||
cin >> kernel_size;
|
||||
|
||||
img0 = imread(src);
|
||||
|
||||
if(!img0.data)
|
||||
{
|
||||
cout << "Source Image does not exist" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
res1 = Mat::zeros(img0.size(),CV_8UC1);
|
||||
final = Mat::zeros(img0.size(),CV_8UC3);
|
||||
|
||||
//////////// source image ///////////////////
|
||||
|
||||
namedWindow("Source", 1);
|
||||
setMouseCallback("Source", source, NULL);
|
||||
imshow("Source", img0);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Wrong Option Choosen" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
for(;;)
|
||||
{
|
||||
char key = (char) waitKey(0);
|
||||
|
||||
if(key == 'd' && flag3 == 0)
|
||||
{
|
||||
flag1 = 1;
|
||||
flag3 = 1;
|
||||
img1 = img0.clone();
|
||||
for(int i = var; i < numpts ; i++)
|
||||
pts[i] = point;
|
||||
|
||||
if(var!=0)
|
||||
{
|
||||
const Point* pts3[1] = {&pts[0]};
|
||||
polylines( img1, pts3, &numpts,1, 1, Scalar(0,0,0), 2, 8, 0);
|
||||
}
|
||||
|
||||
for(int i=0;i<var;i++)
|
||||
{
|
||||
minx = min(minx,pts[i].x);
|
||||
maxx = max(maxx,pts[i].x);
|
||||
miny = min(miny,pts[i].y);
|
||||
maxy = max(maxy,pts[i].y);
|
||||
}
|
||||
lenx = maxx - minx;
|
||||
leny = maxy - miny;
|
||||
|
||||
int mid_pointx = minx + lenx/2;
|
||||
int mid_pointy = miny + leny/2;
|
||||
|
||||
for(int i=0;i<var;i++)
|
||||
{
|
||||
pts_diff[i].x = pts[i].x - mid_pointx;
|
||||
pts_diff[i].y = pts[i].y - mid_pointy;
|
||||
}
|
||||
|
||||
flag = var;
|
||||
|
||||
final = Mat::zeros(img0.size(),CV_8UC3);
|
||||
res1 = Mat::zeros(img0.size(),CV_8UC1);
|
||||
const Point* pts4[1] = {&pts[0]};
|
||||
|
||||
fillPoly(res1, pts4,&numpts, 1, Scalar(255, 255, 255), 8, 0);
|
||||
bitwise_and(img0, img0, final,res1);
|
||||
|
||||
imshow("Source", img1);
|
||||
}
|
||||
else if(key == 'r')
|
||||
{
|
||||
for(int i = 0; i < numpts ; i++)
|
||||
{
|
||||
pts[i].x=0;
|
||||
pts[i].y=0;
|
||||
}
|
||||
var = 0;
|
||||
flag1 = 0;
|
||||
flag3 = 0;
|
||||
flag4 = 0;
|
||||
minx = INT_MAX; miny = INT_MAX; maxx = INT_MIN; maxy = INT_MIN;
|
||||
imshow("Source", img0);
|
||||
if(num == 1 || num == 2 || num == 3)
|
||||
imshow("Destination",img2);
|
||||
drag = 0;
|
||||
}
|
||||
else if ((num == 1 || num == 2 || num == 3) && key == 'c' && flag1 == 1 && flag4 == 1)
|
||||
{
|
||||
seamlessClone(img0,img2,res1,point,blend,num);
|
||||
imshow("Cloned Image", blend);
|
||||
imwrite("cloned.png",blend);
|
||||
}
|
||||
else if (num == 4 && key == 'c' && flag1 == 1)
|
||||
{
|
||||
colorChange(img0,res1,blend,red,green,blue);
|
||||
imshow("Color Change Image", blend);
|
||||
imwrite("cloned.png",blend);
|
||||
}
|
||||
else if (num == 5 && key == 'c' && flag1 == 1)
|
||||
{
|
||||
illuminationChange(img0,res1,blend,alpha,beta);
|
||||
imshow("Illum Change Image", blend);
|
||||
imwrite("cloned.png",blend);
|
||||
}
|
||||
else if (num == 6 && key == 'c' && flag1 == 1)
|
||||
{
|
||||
textureFlattening(img0,res1,blend,low_t,high_t,kernel_size);
|
||||
imshow("Texture Flattened", blend);
|
||||
imwrite("cloned.png",blend);
|
||||
}
|
||||
else if(key == 'q')
|
||||
exit(0);
|
||||
}
|
||||
waitKey(0);
|
||||
}
|
@@ -5,6 +5,8 @@
|
||||
*/
|
||||
|
||||
//opencv
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/videoio.hpp"
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/video/background_segm.hpp>
|
||||
//C
|
||||
|
Reference in New Issue
Block a user