resolved conflicts, updated retina class interface and optimized a heavy retinacolor process
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include <cv.h>
|
||||
#include <highgui.h>
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
@@ -24,7 +24,7 @@ Mat dst;
|
||||
* @function on_trackbar
|
||||
* @brief Callback for trackbar
|
||||
*/
|
||||
void on_trackbar( int, void* )
|
||||
static void on_trackbar( int, void* )
|
||||
{
|
||||
alpha = (double) alpha_slider/alpha_slider_max ;
|
||||
|
||||
@@ -40,7 +40,7 @@ void on_trackbar( int, void* )
|
||||
* @function main
|
||||
* @brief Main function
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( void )
|
||||
{
|
||||
/// Read image ( same size, same type )
|
||||
src1 = imread("../images/LinuxLogo.jpg");
|
||||
|
@@ -5,8 +5,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include <cv.h>
|
||||
#include <highgui.h>
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
@@ -18,13 +17,12 @@ int beta; /**< Simple brightness control*/
|
||||
|
||||
/** Matrices to store images */
|
||||
Mat image;
|
||||
Mat new_image;
|
||||
|
||||
/**
|
||||
* @function on_trackbar
|
||||
* @brief Called whenever any of alpha or beta changes
|
||||
*/
|
||||
void on_trackbar( int, void* )
|
||||
static void on_trackbar( int, void* )
|
||||
{
|
||||
Mat new_image = Mat::zeros( image.size(), image.type() );
|
||||
|
||||
@@ -44,7 +42,7 @@ void on_trackbar( int, void* )
|
||||
* @function main
|
||||
* @brief Main function
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Read image given by user
|
||||
image = imread( argv[1] );
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include <iostream> // for standard I/O
|
||||
#include <iostream> // for standard I/O
|
||||
#include <string> // for strings
|
||||
#include <iomanip> // for controlling float print precision
|
||||
#include <sstream> // string to number conversion
|
||||
|
||||
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
|
||||
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
|
||||
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
|
||||
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
|
||||
|
||||
using namespace std;
|
||||
@@ -13,55 +13,57 @@ using namespace cv;
|
||||
double getPSNR ( const Mat& I1, const Mat& I2);
|
||||
Scalar getMSSIM( const Mat& I1, const Mat& I2);
|
||||
|
||||
void help()
|
||||
static void help()
|
||||
{
|
||||
cout
|
||||
<< "\n--------------------------------------------------------------------------" << endl
|
||||
<< "This program shows how to read a video file with OpenCV. In addition, it tests the"
|
||||
<< " similarity of two input videos first with PSNR, and for the frames below a PSNR " << endl
|
||||
<< "trigger value, also with MSSIM."<< endl
|
||||
<< "Usage:" << endl
|
||||
<< "------------------------------------------------------------------------------" << endl
|
||||
<< "This program shows how to read a video file with OpenCV. In addition, it "
|
||||
<< "tests the similarity of two input videos first with PSNR, and for the frames "
|
||||
<< "below a PSNR trigger value, also with MSSIM." << endl
|
||||
<< "Usage:" << endl
|
||||
<< "./video-source referenceVideo useCaseTestVideo PSNR_Trigger_Value Wait_Between_Frames " << endl
|
||||
<< "--------------------------------------------------------------------------" << endl
|
||||
<< "--------------------------------------------------------------------------" << endl
|
||||
<< endl;
|
||||
}
|
||||
int main(int argc, char *argv[], char *window_name)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
help();
|
||||
|
||||
if (argc != 5)
|
||||
{
|
||||
cout << "Not enough parameters" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
stringstream conv;
|
||||
|
||||
const string sourceReference = argv[1],sourceCompareWith = argv[2];
|
||||
const string sourceReference = argv[1], sourceCompareWith = argv[2];
|
||||
int psnrTriggerValue, delay;
|
||||
conv << argv[3] << endl << argv[4]; // put in the strings
|
||||
conv >> psnrTriggerValue >> delay;// take out the numbers
|
||||
conv << argv[3] << endl << argv[4]; // put in the strings
|
||||
conv >> psnrTriggerValue >> delay; // take out the numbers
|
||||
|
||||
char c;
|
||||
int frameNum = -1; // Frame counter
|
||||
int frameNum = -1; // Frame counter
|
||||
|
||||
VideoCapture captRefrnc(sourceReference),
|
||||
captUndTst(sourceCompareWith);
|
||||
VideoCapture captRefrnc(sourceReference), captUndTst(sourceCompareWith);
|
||||
|
||||
if ( !captRefrnc.isOpened())
|
||||
if (!captRefrnc.isOpened())
|
||||
{
|
||||
cout << "Could not open reference " << sourceReference << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( !captUndTst.isOpened())
|
||||
if (!captUndTst.isOpened())
|
||||
{
|
||||
cout << "Could not open case test " << sourceCompareWith << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Size refS = Size((int) captRefrnc.get(CV_CAP_PROP_FRAME_WIDTH),
|
||||
(int) captRefrnc.get(CV_CAP_PROP_FRAME_HEIGHT)),
|
||||
uTSi = Size((int) captUndTst.get(CV_CAP_PROP_FRAME_WIDTH),
|
||||
(int) captUndTst.get(CV_CAP_PROP_FRAME_HEIGHT));
|
||||
Size refS = Size((int) captRefrnc.get(CAP_PROP_FRAME_WIDTH),
|
||||
(int) captRefrnc.get(CAP_PROP_FRAME_HEIGHT)),
|
||||
uTSi = Size((int) captUndTst.get(CAP_PROP_FRAME_WIDTH),
|
||||
(int) captUndTst.get(CAP_PROP_FRAME_HEIGHT));
|
||||
|
||||
if (refS != uTSi)
|
||||
{
|
||||
@@ -73,43 +75,43 @@ int main(int argc, char *argv[], char *window_name)
|
||||
const char* WIN_RF = "Reference";
|
||||
|
||||
// Windows
|
||||
namedWindow(WIN_RF, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow(WIN_UT, CV_WINDOW_AUTOSIZE );
|
||||
cvMoveWindow(WIN_RF, 400 , 0); //750, 2 (bernat =0)
|
||||
cvMoveWindow(WIN_UT, refS.width, 0); //1500, 2
|
||||
namedWindow(WIN_RF, WINDOW_AUTOSIZE);
|
||||
namedWindow(WIN_UT, WINDOW_AUTOSIZE);
|
||||
moveWindow(WIN_RF, 400 , 0); //750, 2 (bernat =0)
|
||||
moveWindow(WIN_UT, refS.width, 0); //1500, 2
|
||||
|
||||
cout << "Reference frame resolution: Width=" << refS.width << " Height=" << refS.height
|
||||
<< " of nr#: " << captRefrnc.get(CV_CAP_PROP_FRAME_COUNT) << endl;
|
||||
<< " of nr#: " << captRefrnc.get(CAP_PROP_FRAME_COUNT) << endl;
|
||||
|
||||
cout << "PSNR trigger value " <<
|
||||
setiosflags(ios::fixed) << setprecision(3) << psnrTriggerValue << endl;
|
||||
cout << "PSNR trigger value " << setiosflags(ios::fixed) << setprecision(3)
|
||||
<< psnrTriggerValue << endl;
|
||||
|
||||
Mat frameReference, frameUnderTest;
|
||||
double psnrV;
|
||||
Scalar mssimV;
|
||||
|
||||
while( true) //Show the image captured in the window and repeat
|
||||
for(;;) //Show the image captured in the window and repeat
|
||||
{
|
||||
captRefrnc >> frameReference;
|
||||
captUndTst >> frameUnderTest;
|
||||
|
||||
if( frameReference.empty() || frameUnderTest.empty())
|
||||
if (frameReference.empty() || frameUnderTest.empty())
|
||||
{
|
||||
cout << " < < < Game over! > > > ";
|
||||
break;
|
||||
}
|
||||
|
||||
++frameNum;
|
||||
cout <<"Frame:" << frameNum <<"# ";
|
||||
cout << "Frame: " << frameNum << "# ";
|
||||
|
||||
///////////////////////////////// PSNR ////////////////////////////////////////////////////
|
||||
psnrV = getPSNR(frameReference,frameUnderTest); //get PSNR
|
||||
psnrV = getPSNR(frameReference,frameUnderTest);
|
||||
cout << setiosflags(ios::fixed) << setprecision(3) << psnrV << "dB";
|
||||
|
||||
//////////////////////////////////// MSSIM /////////////////////////////////////////////////
|
||||
if (psnrV < psnrTriggerValue && psnrV)
|
||||
{
|
||||
mssimV = getMSSIM(frameReference,frameUnderTest);
|
||||
mssimV = getMSSIM(frameReference, frameUnderTest);
|
||||
|
||||
cout << " MSSIM: "
|
||||
<< " R " << setiosflags(ios::fixed) << setprecision(2) << mssimV.val[2] * 100 << "%"
|
||||
@@ -120,10 +122,10 @@ int main(int argc, char *argv[], char *window_name)
|
||||
cout << endl;
|
||||
|
||||
////////////////////////////////// Show Image /////////////////////////////////////////////
|
||||
imshow( WIN_RF, frameReference);
|
||||
imshow( WIN_UT, frameUnderTest);
|
||||
imshow(WIN_RF, frameReference);
|
||||
imshow(WIN_UT, frameUnderTest);
|
||||
|
||||
c = cvWaitKey(delay);
|
||||
c = (char)waitKey(delay);
|
||||
if (c == 27) break;
|
||||
}
|
||||
|
||||
@@ -137,7 +139,7 @@ double getPSNR(const Mat& I1, const Mat& I2)
|
||||
s1.convertTo(s1, CV_32F); // cannot make a square on 8 bits
|
||||
s1 = s1.mul(s1); // |I1 - I2|^2
|
||||
|
||||
Scalar s = sum(s1); // sum elements per channel
|
||||
Scalar s = sum(s1); // sum elements per channel
|
||||
|
||||
double sse = s.val[0] + s.val[1] + s.val[2]; // sum channels
|
||||
|
||||
@@ -145,8 +147,8 @@ double getPSNR(const Mat& I1, const Mat& I2)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
double mse =sse /(double)(I1.channels() * I1.total());
|
||||
double psnr = 10.0*log10((255*255)/mse);
|
||||
double mse = sse / (double)(I1.channels() * I1.total());
|
||||
double psnr = 10.0 * log10((255 * 255) / mse);
|
||||
return psnr;
|
||||
}
|
||||
}
|
||||
@@ -155,10 +157,10 @@ Scalar getMSSIM( const Mat& i1, const Mat& i2)
|
||||
{
|
||||
const double C1 = 6.5025, C2 = 58.5225;
|
||||
/***************************** INITS **********************************/
|
||||
int d = CV_32F;
|
||||
int d = CV_32F;
|
||||
|
||||
Mat I1, I2;
|
||||
i1.convertTo(I1, d); // cannot calculate on one byte large values
|
||||
i1.convertTo(I1, d); // cannot calculate on one byte large values
|
||||
i2.convertTo(I2, d);
|
||||
|
||||
Mat I2_2 = I2.mul(I2); // I2^2
|
||||
@@ -167,7 +169,7 @@ Scalar getMSSIM( const Mat& i1, const Mat& i2)
|
||||
|
||||
/*************************** END INITS **********************************/
|
||||
|
||||
Mat mu1, mu2; // PRELIMINARY COMPUTING
|
||||
Mat mu1, mu2; // PRELIMINARY COMPUTING
|
||||
GaussianBlur(I1, mu1, Size(11, 11), 1.5);
|
||||
GaussianBlur(I2, mu2, Size(11, 11), 1.5);
|
||||
|
||||
@@ -191,15 +193,15 @@ Scalar getMSSIM( const Mat& i1, const Mat& i2)
|
||||
|
||||
t1 = 2 * mu1_mu2 + C1;
|
||||
t2 = 2 * sigma12 + C2;
|
||||
t3 = t1.mul(t2); // t3 = ((2*mu1_mu2 + C1).*(2*sigma12 + C2))
|
||||
t3 = t1.mul(t2); // t3 = ((2*mu1_mu2 + C1).*(2*sigma12 + C2))
|
||||
|
||||
t1 = mu1_2 + mu2_2 + C1;
|
||||
t2 = sigma1_2 + sigma2_2 + C2;
|
||||
t1 = t1.mul(t2); // t1 =((mu1_2 + mu2_2 + C1).*(sigma1_2 + sigma2_2 + C2))
|
||||
t1 = t1.mul(t2); // t1 =((mu1_2 + mu2_2 + C1).*(sigma1_2 + sigma2_2 + C2))
|
||||
|
||||
Mat ssim_map;
|
||||
divide(t3, t1, ssim_map); // ssim_map = t3./t1;
|
||||
divide(t3, t1, ssim_map); // ssim_map = t3./t1;
|
||||
|
||||
Scalar mssim = mean( ssim_map ); // mssim = average of ssim map
|
||||
Scalar mssim = mean(ssim_map); // mssim = average of ssim map
|
||||
return mssim;
|
||||
}
|
||||
}
|
||||
|
@@ -7,51 +7,53 @@
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void help()
|
||||
static void help()
|
||||
{
|
||||
cout
|
||||
<< "\n--------------------------------------------------------------------------" << endl
|
||||
<< "This program shows how to write video files. You can extract the R or G or B color channel "
|
||||
<< " of the input video.write " << endl
|
||||
<< "Usage:" << endl
|
||||
<< "./video-write inputvideoName [ R | G | B] [Y | N]" << endl
|
||||
<< "--------------------------------------------------------------------------" << endl
|
||||
<< "------------------------------------------------------------------------------" << endl
|
||||
<< "This program shows how to write video files." << endl
|
||||
<< "You can extract the R or G or B color channel of the input video." << endl
|
||||
<< "Usage:" << endl
|
||||
<< "./video-write inputvideoName [ R | G | B] [Y | N]" << endl
|
||||
<< "------------------------------------------------------------------------------" << endl
|
||||
<< endl;
|
||||
}
|
||||
int main(int argc, char *argv[], char *window_name)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
help();
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
cout << "Not enough parameters" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const string source = argv[1]; // the source file name
|
||||
const string source = argv[1]; // the source file name
|
||||
const bool askOutputType = argv[3][0] =='Y'; // If false it will use the inputs codec type
|
||||
|
||||
VideoCapture inputVideo(source); // Open input
|
||||
if ( !inputVideo.isOpened())
|
||||
VideoCapture inputVideo(source); // Open input
|
||||
if (!inputVideo.isOpened())
|
||||
{
|
||||
cout << "Could not open the input video." << source << endl;
|
||||
cout << "Could not open the input video: " << source << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
string::size_type pAt = source.find_last_of('.'); // Find extension point
|
||||
string::size_type pAt = source.find_last_of('.'); // Find extension point
|
||||
const string NAME = source.substr(0, pAt) + argv[2][0] + ".avi"; // Form the new name with container
|
||||
int ex = static_cast<int>(inputVideo.get(CV_CAP_PROP_FOURCC)); // Get Codec Type- Int form
|
||||
int ex = static_cast<int>(inputVideo.get(CAP_PROP_FOURCC)); // Get Codec Type- Int form
|
||||
|
||||
// Transform from int to char via Bitwise operators
|
||||
char EXT[] = {ex & 0XFF , (ex & 0XFF00) >> 8,(ex & 0XFF0000) >> 16,(ex & 0XFF000000) >> 24, 0};
|
||||
char EXT[] = {(char)(ex & 0XFF) , (char)((ex & 0XFF00) >> 8),(char)((ex & 0XFF0000) >> 16),(char)((ex & 0XFF000000) >> 24), 0};
|
||||
|
||||
Size S = Size((int) inputVideo.get(CV_CAP_PROP_FRAME_WIDTH), //Acquire input size
|
||||
(int) inputVideo.get(CV_CAP_PROP_FRAME_HEIGHT));
|
||||
Size S = Size((int) inputVideo.get(CAP_PROP_FRAME_WIDTH), // Acquire input size
|
||||
(int) inputVideo.get(CAP_PROP_FRAME_HEIGHT));
|
||||
|
||||
VideoWriter outputVideo; // Open the output
|
||||
if (askOutputType)
|
||||
outputVideo.open(NAME , ex=-1, inputVideo.get(CV_CAP_PROP_FPS),S, true);
|
||||
outputVideo.open(NAME, ex=-1, inputVideo.get(CAP_PROP_FPS), S, true);
|
||||
else
|
||||
outputVideo.open(NAME , ex, inputVideo.get(CV_CAP_PROP_FPS),S, true);
|
||||
outputVideo.open(NAME, ex, inputVideo.get(CAP_PROP_FPS), S, true);
|
||||
|
||||
if (!outputVideo.isOpened())
|
||||
{
|
||||
@@ -59,33 +61,29 @@ int main(int argc, char *argv[], char *window_name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
union { int v; char c[5];} uEx ;
|
||||
uEx.v = ex; // From Int to char via union
|
||||
uEx.c[4]='\0';
|
||||
|
||||
cout << "Input frame resolution: Width=" << S.width << " Height=" << S.height
|
||||
<< " of nr#: " << inputVideo.get(CV_CAP_PROP_FRAME_COUNT) << endl;
|
||||
<< " of nr#: " << inputVideo.get(CAP_PROP_FRAME_COUNT) << endl;
|
||||
cout << "Input codec type: " << EXT << endl;
|
||||
|
||||
int channel = 2; // Select the channel to save
|
||||
int channel = 2; // Select the channel to save
|
||||
switch(argv[2][0])
|
||||
{
|
||||
case 'R' : {channel = 2; break;}
|
||||
case 'G' : {channel = 1; break;}
|
||||
case 'B' : {channel = 0; break;}
|
||||
case 'R' : channel = 2; break;
|
||||
case 'G' : channel = 1; break;
|
||||
case 'B' : channel = 0; break;
|
||||
}
|
||||
Mat src,res;
|
||||
Mat src, res;
|
||||
vector<Mat> spl;
|
||||
|
||||
while( true) //Show the image captured in the window and repeat
|
||||
for(;;) //Show the image captured in the window and repeat
|
||||
{
|
||||
inputVideo >> src; // read
|
||||
if( src.empty()) break; // check if at end
|
||||
if (src.empty()) break; // check if at end
|
||||
|
||||
split(src, spl); // process - extract only the correct channel
|
||||
for( int i =0; i < 3; ++i)
|
||||
if (i != channel)
|
||||
spl[i] = Mat::zeros(S, spl[0].type());
|
||||
split(src, spl); // process - extract only the correct channel
|
||||
for (int i =0; i < 3; ++i)
|
||||
if (i != channel)
|
||||
spl[i] = Mat::zeros(S, spl[0].type());
|
||||
merge(spl, res);
|
||||
|
||||
//outputVideo.write(res); //save or
|
||||
@@ -94,4 +92,4 @@ int main(int argc, char *argv[], char *window_name)
|
||||
|
||||
cout << "Finished writing" << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -15,12 +15,12 @@ using namespace std;
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
Mat src, dst;
|
||||
|
||||
char* source_window = "Source image";
|
||||
char* equalized_window = "Equalized Image";
|
||||
const char* source_window = "Source image";
|
||||
const char* equalized_window = "Equalized Image";
|
||||
|
||||
/// Load image
|
||||
src = imread( argv[1], 1 );
|
||||
@@ -31,14 +31,14 @@ int main( int argc, char** argv )
|
||||
}
|
||||
|
||||
/// Convert to grayscale
|
||||
cvtColor( src, src, CV_BGR2GRAY );
|
||||
cvtColor( src, src, COLOR_BGR2GRAY );
|
||||
|
||||
/// Apply Histogram Equalization
|
||||
equalizeHist( src, dst );
|
||||
|
||||
/// Display results
|
||||
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( equalized_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
namedWindow( equalized_window, WINDOW_AUTOSIZE );
|
||||
|
||||
imshow( source_window, src );
|
||||
imshow( equalized_window, dst );
|
||||
|
@@ -14,8 +14,8 @@ using namespace cv;
|
||||
|
||||
/// Global Variables
|
||||
Mat img; Mat templ; Mat result;
|
||||
char* image_window = "Source Image";
|
||||
char* result_window = "Result window";
|
||||
const char* image_window = "Source Image";
|
||||
const char* result_window = "Result window";
|
||||
|
||||
int match_method;
|
||||
int max_Trackbar = 5;
|
||||
@@ -26,18 +26,18 @@ void MatchingMethod( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load image and template
|
||||
img = imread( argv[1], 1 );
|
||||
templ = imread( argv[2], 1 );
|
||||
|
||||
/// Create windows
|
||||
namedWindow( image_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( result_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( image_window, WINDOW_AUTOSIZE );
|
||||
namedWindow( result_window, WINDOW_AUTOSIZE );
|
||||
|
||||
/// Create Trackbar
|
||||
char* trackbar_label = "Method: \n 0: SQDIFF \n 1: SQDIFF NORMED \n 2: TM CCORR \n 3: TM CCORR NORMED \n 4: TM COEFF \n 5: TM COEFF NORMED";
|
||||
const char* trackbar_label = "Method: \n 0: SQDIFF \n 1: SQDIFF NORMED \n 2: TM CCORR \n 3: TM CCORR NORMED \n 4: TM COEFF \n 5: TM COEFF NORMED";
|
||||
createTrackbar( trackbar_label, image_window, &match_method, max_Trackbar, MatchingMethod );
|
||||
|
||||
MatchingMethod( 0, 0 );
|
||||
@@ -74,7 +74,7 @@ void MatchingMethod( int, void* )
|
||||
|
||||
|
||||
/// For SQDIFF and SQDIFF_NORMED, the best matches are lower values. For all the other methods, the higher the better
|
||||
if( match_method == CV_TM_SQDIFF || match_method == CV_TM_SQDIFF_NORMED )
|
||||
if( match_method == TM_SQDIFF || match_method == TM_SQDIFF_NORMED )
|
||||
{ matchLoc = minLoc; }
|
||||
else
|
||||
{ matchLoc = maxLoc; }
|
||||
|
@@ -23,12 +23,12 @@ void Hist_and_Backproj(int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Read the image
|
||||
src = imread( argv[1], 1 );
|
||||
/// Transform it to HSV
|
||||
cvtColor( src, hsv, CV_BGR2HSV );
|
||||
cvtColor( src, hsv, COLOR_BGR2HSV );
|
||||
|
||||
/// Use only the Hue value
|
||||
hue.create( hsv.size(), hsv.depth() );
|
||||
@@ -36,8 +36,8 @@ int main( int argc, char** argv )
|
||||
mixChannels( &hsv, 1, &hue, 1, ch, 1 );
|
||||
|
||||
/// Create Trackbar to enter the number of bins
|
||||
char* window_image = "Source image";
|
||||
namedWindow( window_image, CV_WINDOW_AUTOSIZE );
|
||||
const char* window_image = "Source image";
|
||||
namedWindow( window_image, WINDOW_AUTOSIZE );
|
||||
createTrackbar("* Hue bins: ", window_image, &bins, 180, Hist_and_Backproj );
|
||||
Hist_and_Backproj(0, 0);
|
||||
|
||||
|
@@ -17,7 +17,7 @@ Mat src; Mat hsv;
|
||||
Mat mask;
|
||||
|
||||
int lo = 20; int up = 20;
|
||||
char* window_image = "Source image";
|
||||
const char* window_image = "Source image";
|
||||
|
||||
/// Function Headers
|
||||
void Hist_and_Backproj( );
|
||||
@@ -26,15 +26,15 @@ void pickPoint (int event, int x, int y, int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Read the image
|
||||
src = imread( argv[1], 1 );
|
||||
/// Transform it to HSV
|
||||
cvtColor( src, hsv, CV_BGR2HSV );
|
||||
cvtColor( src, hsv, COLOR_BGR2HSV );
|
||||
|
||||
/// Show the image
|
||||
namedWindow( window_image, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( window_image, WINDOW_AUTOSIZE );
|
||||
imshow( window_image, src );
|
||||
|
||||
/// Set Trackbars for floodfill thresholds
|
||||
@@ -52,7 +52,7 @@ int main( int argc, char** argv )
|
||||
*/
|
||||
void pickPoint (int event, int x, int y, int, void* )
|
||||
{
|
||||
if( event != CV_EVENT_LBUTTONDOWN )
|
||||
if( event != EVENT_LBUTTONDOWN )
|
||||
{ return; }
|
||||
|
||||
// Fill and get the mask
|
||||
|
@@ -15,7 +15,7 @@ using namespace cv;
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
Mat src, dst;
|
||||
|
||||
@@ -71,7 +71,7 @@ int main( int argc, char** argv )
|
||||
}
|
||||
|
||||
/// Display
|
||||
namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE );
|
||||
namedWindow("calcHist Demo", WINDOW_AUTOSIZE );
|
||||
imshow("calcHist Demo", histImage );
|
||||
|
||||
waitKey(0);
|
||||
|
@@ -33,9 +33,9 @@ int main( int argc, char** argv )
|
||||
src_test2 = imread( argv[3], 1 );
|
||||
|
||||
/// Convert to HSV
|
||||
cvtColor( src_base, hsv_base, CV_BGR2HSV );
|
||||
cvtColor( src_test1, hsv_test1, CV_BGR2HSV );
|
||||
cvtColor( src_test2, hsv_test2, CV_BGR2HSV );
|
||||
cvtColor( src_base, hsv_base, COLOR_BGR2HSV );
|
||||
cvtColor( src_test1, hsv_test1, COLOR_BGR2HSV );
|
||||
cvtColor( src_test2, hsv_test2, COLOR_BGR2HSV );
|
||||
|
||||
hsv_half_down = hsv_base( Range( hsv_base.rows/2, hsv_base.rows - 1 ), Range( 0, hsv_base.cols - 1 ) );
|
||||
|
||||
|
@@ -4,8 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include <cv.h>
|
||||
#include <highgui.h>
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
@@ -14,7 +13,7 @@ using namespace cv;
|
||||
* @function main
|
||||
* @brief Main function
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( void )
|
||||
{
|
||||
|
||||
double alpha = 0.5; double beta; double input;
|
||||
@@ -35,8 +34,8 @@ int main( int argc, char** argv )
|
||||
src1 = imread("../images/LinuxLogo.jpg");
|
||||
src2 = imread("../images/WindowsLogo.jpg");
|
||||
|
||||
if( !src1.data ) { printf("Error loading src1 \n"); return -1; }
|
||||
if( !src2.data ) { printf("Error loading src2 \n"); return -1; }
|
||||
if( !src1.data ) { std::cout<< "Error loading src1"<<std::endl; return -1; }
|
||||
if( !src2.data ) { std::cout<< "Error loading src2"<<std::endl; return -1; }
|
||||
|
||||
/// Create Windows
|
||||
namedWindow("Linear Blend", 1);
|
||||
|
@@ -4,8 +4,7 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include <cv.h>
|
||||
#include <highgui.h>
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
@@ -17,7 +16,7 @@ int beta; /**< Simple brightness control */
|
||||
* @function main
|
||||
* @brief Main function
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Read image given by user
|
||||
Mat image = imread( argv[1] );
|
||||
|
@@ -6,7 +6,6 @@
|
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "highgui.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -29,7 +28,7 @@ void Dilation( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load an image
|
||||
src = imread( argv[1] );
|
||||
@@ -38,9 +37,9 @@ int main( int argc, char** argv )
|
||||
{ return -1; }
|
||||
|
||||
/// Create windows
|
||||
namedWindow( "Erosion Demo", CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( "Dilation Demo", CV_WINDOW_AUTOSIZE );
|
||||
cvMoveWindow( "Dilation Demo", src.cols, 0 );
|
||||
namedWindow( "Erosion Demo", WINDOW_AUTOSIZE );
|
||||
namedWindow( "Dilation Demo", WINDOW_AUTOSIZE );
|
||||
moveWindow( "Dilation Demo", src.cols, 0 );
|
||||
|
||||
/// Create Erosion Trackbar
|
||||
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse", "Erosion Demo",
|
||||
@@ -73,7 +72,7 @@ int main( int argc, char** argv )
|
||||
*/
|
||||
void Erosion( int, void* )
|
||||
{
|
||||
int erosion_type;
|
||||
int erosion_type = 0;
|
||||
if( erosion_elem == 0 ){ erosion_type = MORPH_RECT; }
|
||||
else if( erosion_elem == 1 ){ erosion_type = MORPH_CROSS; }
|
||||
else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; }
|
||||
@@ -91,7 +90,7 @@ void Erosion( int, void* )
|
||||
*/
|
||||
void Dilation( int, void* )
|
||||
{
|
||||
int dilation_type;
|
||||
int dilation_type = 0;
|
||||
if( dilation_elem == 0 ){ dilation_type = MORPH_RECT; }
|
||||
else if( dilation_elem == 1 ){ dilation_type = MORPH_CROSS; }
|
||||
else if( dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; }
|
||||
|
@@ -21,7 +21,7 @@ int const max_operator = 4;
|
||||
int const max_elem = 2;
|
||||
int const max_kernel_size = 21;
|
||||
|
||||
char* window_name = "Morphology Transformations Demo";
|
||||
const char* window_name = "Morphology Transformations Demo";
|
||||
|
||||
|
||||
/** Function Headers */
|
||||
@@ -30,7 +30,7 @@ void Morphology_Operations( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load an image
|
||||
src = imread( argv[1] );
|
||||
@@ -39,7 +39,7 @@ int main( int argc, char** argv )
|
||||
{ return -1; }
|
||||
|
||||
/// Create window
|
||||
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( window_name, WINDOW_AUTOSIZE );
|
||||
|
||||
/// Create Trackbar to select Morphology operation
|
||||
createTrackbar("Operator:\n 0: Opening - 1: Closing \n 2: Gradient - 3: Top Hat \n 4: Black Hat", window_name, &morph_operator, max_operator, Morphology_Operations );
|
||||
|
@@ -15,13 +15,13 @@ using namespace cv;
|
||||
/// Global variables
|
||||
Mat src, dst, tmp;
|
||||
|
||||
char* window_name = "Pyramids Demo";
|
||||
const char* window_name = "Pyramids Demo";
|
||||
|
||||
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( void )
|
||||
{
|
||||
/// General instructions
|
||||
printf( "\n Zoom In-Out demo \n " );
|
||||
@@ -40,11 +40,11 @@ int main( int argc, char** argv )
|
||||
dst = tmp;
|
||||
|
||||
/// Create window
|
||||
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( window_name, WINDOW_AUTOSIZE );
|
||||
imshow( window_name, dst );
|
||||
|
||||
/// Loop
|
||||
while( true )
|
||||
for(;;)
|
||||
{
|
||||
int c;
|
||||
c = waitKey(10);
|
||||
|
@@ -22,16 +22,16 @@ Mat src; Mat dst;
|
||||
char window_name[] = "Smoothing Demo";
|
||||
|
||||
/// Function headers
|
||||
int display_caption( char* caption );
|
||||
int display_caption( const char* caption );
|
||||
int display_dst( int delay );
|
||||
|
||||
|
||||
/**
|
||||
* function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( void )
|
||||
{
|
||||
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( window_name, WINDOW_AUTOSIZE );
|
||||
|
||||
/// Load the source image
|
||||
src = imread( "../images/lena.png", 1 );
|
||||
@@ -84,12 +84,12 @@ int main( int argc, char** argv )
|
||||
/**
|
||||
* @function display_caption
|
||||
*/
|
||||
int display_caption( char* caption )
|
||||
int display_caption( const char* caption )
|
||||
{
|
||||
dst = Mat::zeros( src.size(), src.type() );
|
||||
putText( dst, caption,
|
||||
Point( src.cols/4, src.rows/2),
|
||||
CV_FONT_HERSHEY_COMPLEX, 1, Scalar(255, 255, 255) );
|
||||
FONT_HERSHEY_COMPLEX, 1, Scalar(255, 255, 255) );
|
||||
|
||||
imshow( window_name, dst );
|
||||
int c = waitKey( DELAY_CAPTION );
|
||||
|
@@ -20,10 +20,10 @@ int const max_type = 4;
|
||||
int const max_BINARY_value = 255;
|
||||
|
||||
Mat src, src_gray, dst;
|
||||
char* window_name = "Threshold Demo";
|
||||
const char* window_name = "Threshold Demo";
|
||||
|
||||
char* trackbar_type = "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted";
|
||||
char* trackbar_value = "Value";
|
||||
const char* trackbar_type = "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted";
|
||||
const char* trackbar_value = "Value";
|
||||
|
||||
/// Function headers
|
||||
void Threshold_Demo( int, void* );
|
||||
@@ -31,16 +31,16 @@ void Threshold_Demo( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load an image
|
||||
src = imread( argv[1], 1 );
|
||||
|
||||
/// Convert the image to Gray
|
||||
cvtColor( src, src_gray, CV_RGB2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_RGB2GRAY );
|
||||
|
||||
/// Create a window to display results
|
||||
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( window_name, WINDOW_AUTOSIZE );
|
||||
|
||||
/// Create Trackbar to choose type of Threshold
|
||||
createTrackbar( trackbar_type,
|
||||
@@ -55,7 +55,7 @@ int main( int argc, char** argv )
|
||||
Threshold_Demo( 0, 0 );
|
||||
|
||||
/// Wait until user finishes program
|
||||
while(true)
|
||||
for(;;)
|
||||
{
|
||||
int c;
|
||||
c = waitKey( 20 );
|
||||
|
@@ -21,13 +21,13 @@ int lowThreshold;
|
||||
int const max_lowThreshold = 100;
|
||||
int ratio = 3;
|
||||
int kernel_size = 3;
|
||||
char* window_name = "Edge Map";
|
||||
const char* window_name = "Edge Map";
|
||||
|
||||
/**
|
||||
* @function CannyThreshold
|
||||
* @brief Trackbar callback - Canny thresholds input with a ratio 1:3
|
||||
*/
|
||||
void CannyThreshold(int, void*)
|
||||
static void CannyThreshold(int, void*)
|
||||
{
|
||||
/// Reduce noise with a kernel 3x3
|
||||
blur( src_gray, detected_edges, Size(3,3) );
|
||||
@@ -46,7 +46,7 @@ void CannyThreshold(int, void*)
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load an image
|
||||
src = imread( argv[1] );
|
||||
@@ -58,10 +58,10 @@ int main( int argc, char** argv )
|
||||
dst.create( src.size(), src.type() );
|
||||
|
||||
/// Convert the image to grayscale
|
||||
cvtColor( src, src_gray, CV_BGR2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
|
||||
/// Create a window
|
||||
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( window_name, WINDOW_AUTOSIZE );
|
||||
|
||||
/// Create a Trackbar for user to enter threshold
|
||||
createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );
|
||||
|
@@ -13,14 +13,14 @@ using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
/// Global variables
|
||||
char* source_window = "Source image";
|
||||
char* warp_window = "Warp";
|
||||
char* warp_rotate_window = "Warp + Rotate";
|
||||
const char* source_window = "Source image";
|
||||
const char* warp_window = "Warp";
|
||||
const char* warp_rotate_window = "Warp + Rotate";
|
||||
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
Point2f srcTri[3];
|
||||
Point2f dstTri[3];
|
||||
@@ -37,12 +37,12 @@ int main( int argc, char** argv )
|
||||
|
||||
/// Set your 3 points to calculate the Affine Transform
|
||||
srcTri[0] = Point2f( 0,0 );
|
||||
srcTri[1] = Point2f( src.cols - 1, 0 );
|
||||
srcTri[2] = Point2f( 0, src.rows - 1 );
|
||||
srcTri[1] = Point2f( src.cols - 1.f, 0 );
|
||||
srcTri[2] = Point2f( 0, src.rows - 1.f );
|
||||
|
||||
dstTri[0] = Point2f( src.cols*0.0, src.rows*0.33 );
|
||||
dstTri[1] = Point2f( src.cols*0.85, src.rows*0.25 );
|
||||
dstTri[2] = Point2f( src.cols*0.15, src.rows*0.7 );
|
||||
dstTri[0] = Point2f( src.cols*0.0f, src.rows*0.33f );
|
||||
dstTri[1] = Point2f( src.cols*0.85f, src.rows*0.25f );
|
||||
dstTri[2] = Point2f( src.cols*0.15f, src.rows*0.7f );
|
||||
|
||||
/// Get the Affine Transform
|
||||
warp_mat = getAffineTransform( srcTri, dstTri );
|
||||
@@ -65,13 +65,13 @@ int main( int argc, char** argv )
|
||||
|
||||
|
||||
/// Show what you got
|
||||
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, src );
|
||||
|
||||
namedWindow( warp_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( warp_window, WINDOW_AUTOSIZE );
|
||||
imshow( warp_window, warp_dst );
|
||||
|
||||
namedWindow( warp_rotate_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( warp_rotate_window, WINDOW_AUTOSIZE );
|
||||
imshow( warp_rotate_window, warp_rotate_dst );
|
||||
|
||||
/// Wait until user exits the program
|
||||
|
@@ -9,12 +9,13 @@
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
int main(int, char** argv)
|
||||
{
|
||||
Mat src, src_gray;
|
||||
|
||||
@@ -25,7 +26,7 @@ int main(int argc, char** argv)
|
||||
{ return -1; }
|
||||
|
||||
/// Convert it to gray
|
||||
cvtColor( src, src_gray, CV_BGR2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
|
||||
/// Reduce the noise so we avoid false circle detection
|
||||
GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );
|
||||
@@ -33,7 +34,7 @@ int main(int argc, char** argv)
|
||||
vector<Vec3f> circles;
|
||||
|
||||
/// Apply the Hough Transform to find the circles
|
||||
HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 );
|
||||
HoughCircles( src_gray, circles, HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 );
|
||||
|
||||
/// Draw the circles detected
|
||||
for( size_t i = 0; i < circles.size(); i++ )
|
||||
@@ -47,7 +48,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
/// Show your results
|
||||
namedWindow( "Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( "Hough Circle Transform Demo", WINDOW_AUTOSIZE );
|
||||
imshow( "Hough Circle Transform Demo", src );
|
||||
|
||||
waitKey(0);
|
||||
|
@@ -21,8 +21,8 @@ Mat standard_hough, probabilistic_hough;
|
||||
int min_threshold = 50;
|
||||
int max_trackbar = 150;
|
||||
|
||||
char* standard_name = "Standard Hough Lines Demo";
|
||||
char* probabilistic_name = "Probabilistic Hough Lines Demo";
|
||||
const char* standard_name = "Standard Hough Lines Demo";
|
||||
const char* probabilistic_name = "Probabilistic Hough Lines Demo";
|
||||
|
||||
int s_trackbar = max_trackbar;
|
||||
int p_trackbar = max_trackbar;
|
||||
@@ -35,7 +35,7 @@ void Probabilistic_Hough( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Read the image
|
||||
src = imread( argv[1], 1 );
|
||||
@@ -46,7 +46,7 @@ int main( int argc, char** argv )
|
||||
}
|
||||
|
||||
/// Pass the image to gray
|
||||
cvtColor( src, src_gray, CV_RGB2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_RGB2GRAY );
|
||||
|
||||
/// Apply Canny edge detector
|
||||
Canny( src_gray, edges, 50, 200, 3 );
|
||||
@@ -55,10 +55,10 @@ int main( int argc, char** argv )
|
||||
char thresh_label[50];
|
||||
sprintf( thresh_label, "Thres: %d + input", min_threshold );
|
||||
|
||||
namedWindow( standard_name, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( standard_name, WINDOW_AUTOSIZE );
|
||||
createTrackbar( thresh_label, standard_name, &s_trackbar, max_trackbar, Standard_Hough);
|
||||
|
||||
namedWindow( probabilistic_name, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( probabilistic_name, WINDOW_AUTOSIZE );
|
||||
createTrackbar( thresh_label, probabilistic_name, &p_trackbar, max_trackbar, Probabilistic_Hough);
|
||||
|
||||
/// Initialize
|
||||
@@ -85,13 +85,13 @@ void help()
|
||||
void Standard_Hough( int, void* )
|
||||
{
|
||||
vector<Vec2f> s_lines;
|
||||
cvtColor( edges, standard_hough, CV_GRAY2BGR );
|
||||
cvtColor( edges, standard_hough, COLOR_GRAY2BGR );
|
||||
|
||||
/// 1. Use Standard Hough Transform
|
||||
HoughLines( edges, s_lines, 1, CV_PI/180, min_threshold + s_trackbar, 0, 0 );
|
||||
|
||||
/// Show the result
|
||||
for( int i = 0; i < s_lines.size(); i++ )
|
||||
for( size_t i = 0; i < s_lines.size(); i++ )
|
||||
{
|
||||
float r = s_lines[i][0], t = s_lines[i][1];
|
||||
double cos_t = cos(t), sin_t = sin(t);
|
||||
@@ -100,7 +100,7 @@ void Standard_Hough( int, void* )
|
||||
|
||||
Point pt1( cvRound(x0 + alpha*(-sin_t)), cvRound(y0 + alpha*cos_t) );
|
||||
Point pt2( cvRound(x0 - alpha*(-sin_t)), cvRound(y0 - alpha*cos_t) );
|
||||
line( standard_hough, pt1, pt2, Scalar(255,0,0), 3, CV_AA);
|
||||
line( standard_hough, pt1, pt2, Scalar(255,0,0), 3, LINE_AA);
|
||||
}
|
||||
|
||||
imshow( standard_name, standard_hough );
|
||||
@@ -112,7 +112,7 @@ void Standard_Hough( int, void* )
|
||||
void Probabilistic_Hough( int, void* )
|
||||
{
|
||||
vector<Vec4i> p_lines;
|
||||
cvtColor( edges, probabilistic_hough, CV_GRAY2BGR );
|
||||
cvtColor( edges, probabilistic_hough, COLOR_GRAY2BGR );
|
||||
|
||||
/// 2. Use Probabilistic Hough Transform
|
||||
HoughLinesP( edges, p_lines, 1, CV_PI/180, min_threshold + p_trackbar, 30, 10 );
|
||||
@@ -121,7 +121,7 @@ void Probabilistic_Hough( int, void* )
|
||||
for( size_t i = 0; i < p_lines.size(); i++ )
|
||||
{
|
||||
Vec4i l = p_lines[i];
|
||||
line( probabilistic_hough, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(255,0,0), 3, CV_AA);
|
||||
line( probabilistic_hough, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(255,0,0), 3, LINE_AA);
|
||||
}
|
||||
|
||||
imshow( probabilistic_name, probabilistic_hough );
|
||||
|
@@ -14,7 +14,7 @@ using namespace cv;
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
|
||||
Mat src, src_gray, dst;
|
||||
@@ -22,9 +22,7 @@ int main( int argc, char** argv )
|
||||
int scale = 1;
|
||||
int delta = 0;
|
||||
int ddepth = CV_16S;
|
||||
char* window_name = "Laplace Demo";
|
||||
|
||||
int c;
|
||||
const char* window_name = "Laplace Demo";
|
||||
|
||||
/// Load an image
|
||||
src = imread( argv[1] );
|
||||
@@ -36,10 +34,10 @@ int main( int argc, char** argv )
|
||||
GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT );
|
||||
|
||||
/// Convert the image to grayscale
|
||||
cvtColor( src, src_gray, CV_RGB2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_RGB2GRAY );
|
||||
|
||||
/// Create window
|
||||
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( window_name, WINDOW_AUTOSIZE );
|
||||
|
||||
/// Apply Laplace function
|
||||
Mat abs_dst;
|
||||
|
@@ -14,7 +14,7 @@ using namespace cv;
|
||||
/// Global variables
|
||||
Mat src, dst;
|
||||
Mat map_x, map_y;
|
||||
char* remap_window = "Remap demo";
|
||||
const char* remap_window = "Remap demo";
|
||||
int ind = 0;
|
||||
|
||||
/// Function Headers
|
||||
@@ -23,7 +23,7 @@ void update_map( void );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load the image
|
||||
src = imread( argv[1], 1 );
|
||||
@@ -34,10 +34,10 @@ int main( int argc, char** argv )
|
||||
map_y.create( src.size(), CV_32FC1 );
|
||||
|
||||
/// Create window
|
||||
namedWindow( remap_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( remap_window, WINDOW_AUTOSIZE );
|
||||
|
||||
/// Loop
|
||||
while( true )
|
||||
for(;;)
|
||||
{
|
||||
/// Each 1 sec. Press ESC to exit the program
|
||||
int c = waitKey( 1000 );
|
||||
@@ -47,7 +47,7 @@ int main( int argc, char** argv )
|
||||
|
||||
/// Update map_x & map_y. Then apply remap
|
||||
update_map();
|
||||
remap( src, dst, map_x, map_y, CV_INTER_LINEAR, BORDER_CONSTANT, Scalar(0, 0, 0) );
|
||||
remap( src, dst, map_x, map_y, INTER_LINEAR, BORDER_CONSTANT, Scalar(0, 0, 0) );
|
||||
|
||||
// Display results
|
||||
imshow( remap_window, dst );
|
||||
@@ -71,8 +71,8 @@ void update_map( void )
|
||||
case 0:
|
||||
if( i > src.cols*0.25 && i < src.cols*0.75 && j > src.rows*0.25 && j < src.rows*0.75 )
|
||||
{
|
||||
map_x.at<float>(j,i) = 2*( i - src.cols*0.25 ) + 0.5 ;
|
||||
map_y.at<float>(j,i) = 2*( j - src.rows*0.25 ) + 0.5 ;
|
||||
map_x.at<float>(j,i) = 2*( i - src.cols*0.25f ) + 0.5f ;
|
||||
map_y.at<float>(j,i) = 2*( j - src.rows*0.25f ) + 0.5f ;
|
||||
}
|
||||
else
|
||||
{ map_x.at<float>(j,i) = 0 ;
|
||||
@@ -80,16 +80,16 @@ void update_map( void )
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
map_x.at<float>(j,i) = i ;
|
||||
map_y.at<float>(j,i) = src.rows - j ;
|
||||
map_x.at<float>(j,i) = (float)i ;
|
||||
map_y.at<float>(j,i) = (float)(src.rows - j) ;
|
||||
break;
|
||||
case 2:
|
||||
map_x.at<float>(j,i) = src.cols - i ;
|
||||
map_y.at<float>(j,i) = j ;
|
||||
map_x.at<float>(j,i) = (float)(src.cols - i) ;
|
||||
map_y.at<float>(j,i) = (float)j ;
|
||||
break;
|
||||
case 3:
|
||||
map_x.at<float>(j,i) = src.cols - i ;
|
||||
map_y.at<float>(j,i) = src.rows - j ;
|
||||
map_x.at<float>(j,i) = (float)(src.cols - i) ;
|
||||
map_y.at<float>(j,i) = (float)(src.rows - j) ;
|
||||
break;
|
||||
} // end of switch
|
||||
}
|
||||
|
@@ -14,18 +14,16 @@ using namespace cv;
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
|
||||
Mat src, src_gray;
|
||||
Mat grad;
|
||||
char* window_name = "Sobel Demo - Simple Edge Detector";
|
||||
const char* window_name = "Sobel Demo - Simple Edge Detector";
|
||||
int scale = 1;
|
||||
int delta = 0;
|
||||
int ddepth = CV_16S;
|
||||
|
||||
int c;
|
||||
|
||||
/// Load an image
|
||||
src = imread( argv[1] );
|
||||
|
||||
@@ -35,10 +33,10 @@ int main( int argc, char** argv )
|
||||
GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT );
|
||||
|
||||
/// Convert it to gray
|
||||
cvtColor( src, src_gray, CV_RGB2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_RGB2GRAY );
|
||||
|
||||
/// Create window
|
||||
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( window_name, WINDOW_AUTOSIZE );
|
||||
|
||||
/// Generate grad_x and grad_y
|
||||
Mat grad_x, grad_y;
|
||||
|
@@ -16,13 +16,13 @@ Mat src, dst;
|
||||
int top, bottom, left, right;
|
||||
int borderType;
|
||||
Scalar value;
|
||||
char* window_name = "copyMakeBorder Demo";
|
||||
const char* window_name = "copyMakeBorder Demo";
|
||||
RNG rng(12345);
|
||||
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
|
||||
int c;
|
||||
@@ -31,8 +31,9 @@ int main( int argc, char** argv )
|
||||
src = imread( argv[1] );
|
||||
|
||||
if( !src.data )
|
||||
{ return -1;
|
||||
{
|
||||
printf(" No data entered, please enter the path to an image file \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Brief how-to for this program
|
||||
@@ -43,7 +44,7 @@ int main( int argc, char** argv )
|
||||
printf( " ** Press 'ESC' to exit the program \n");
|
||||
|
||||
/// Create window
|
||||
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( window_name, WINDOW_AUTOSIZE );
|
||||
|
||||
/// Initialize arguments for the filter
|
||||
top = (int) (0.05*src.rows); bottom = (int) (0.05*src.rows);
|
||||
@@ -52,7 +53,7 @@ int main( int argc, char** argv )
|
||||
|
||||
imshow( window_name, dst );
|
||||
|
||||
while( true )
|
||||
for(;;)
|
||||
{
|
||||
c = waitKey(500);
|
||||
|
||||
|
@@ -14,7 +14,7 @@ using namespace cv;
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main ( int argc, char** argv )
|
||||
int main ( int, char** argv )
|
||||
{
|
||||
/// Declare variables
|
||||
Mat src, dst;
|
||||
@@ -24,7 +24,7 @@ int main ( int argc, char** argv )
|
||||
double delta;
|
||||
int ddepth;
|
||||
int kernel_size;
|
||||
char* window_name = "filter2D Demo";
|
||||
const char* window_name = "filter2D Demo";
|
||||
|
||||
int c;
|
||||
|
||||
@@ -35,7 +35,7 @@ int main ( int argc, char** argv )
|
||||
{ return -1; }
|
||||
|
||||
/// Create window
|
||||
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( window_name, WINDOW_AUTOSIZE );
|
||||
|
||||
/// Initialize arguments for the filter
|
||||
anchor = Point( -1, -1 );
|
||||
@@ -44,7 +44,7 @@ int main ( int argc, char** argv )
|
||||
|
||||
/// Loop - Will filter the image with different kernel sizes each 0.5 seconds
|
||||
int ind = 0;
|
||||
while( true )
|
||||
for(;;)
|
||||
{
|
||||
c = waitKey(500);
|
||||
/// Press 'ESC' to exit the program
|
||||
|
@@ -24,18 +24,18 @@ void thresh_callback(int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], 1 );
|
||||
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, CV_BGR2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
|
||||
/// Create Window
|
||||
char* source_window = "Source";
|
||||
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, src );
|
||||
|
||||
createTrackbar( " Canny thresh:", "Source", &thresh, max_thresh, thresh_callback );
|
||||
@@ -57,17 +57,17 @@ void thresh_callback(int, void* )
|
||||
/// Detect edges using canny
|
||||
Canny( src_gray, canny_output, thresh, thresh*2, 3 );
|
||||
/// Find contours
|
||||
findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
findContours( canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
|
||||
/// Draw contours
|
||||
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
|
||||
for( int i = 0; i< contours.size(); i++ )
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
|
||||
drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
|
||||
drawContours( drawing, contours, (int)i, color, 2, 8, hierarchy, 0, Point() );
|
||||
}
|
||||
|
||||
/// Show in a window
|
||||
namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( "Contours", WINDOW_AUTOSIZE );
|
||||
imshow( "Contours", drawing );
|
||||
}
|
||||
|
@@ -24,18 +24,18 @@ void thresh_callback(int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], 1 );
|
||||
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, CV_BGR2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
|
||||
/// Create Window
|
||||
char* source_window = "Source";
|
||||
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, src );
|
||||
|
||||
createTrackbar( " Threshold:", "Source", &thresh, max_thresh, thresh_callback );
|
||||
@@ -57,7 +57,7 @@ void thresh_callback(int, void* )
|
||||
/// Detect edges using Threshold
|
||||
threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY );
|
||||
/// Find contours
|
||||
findContours( threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
findContours( threshold_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
|
||||
/// Approximate contours to polygons + get bounding rects and circles
|
||||
vector<vector<Point> > contours_poly( contours.size() );
|
||||
@@ -65,7 +65,7 @@ void thresh_callback(int, void* )
|
||||
vector<Point2f>center( contours.size() );
|
||||
vector<float>radius( contours.size() );
|
||||
|
||||
for( int i = 0; i < contours.size(); i++ )
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{ approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
|
||||
boundRect[i] = boundingRect( Mat(contours_poly[i]) );
|
||||
minEnclosingCircle( contours_poly[i], center[i], radius[i] );
|
||||
@@ -74,15 +74,15 @@ void thresh_callback(int, void* )
|
||||
|
||||
/// Draw polygonal contour + bonding rects + circles
|
||||
Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
|
||||
for( int i = 0; i< contours.size(); i++ )
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
|
||||
drawContours( drawing, contours_poly, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
|
||||
drawContours( drawing, contours_poly, (int)i, color, 1, 8, vector<Vec4i>(), 0, Point() );
|
||||
rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0 );
|
||||
circle( drawing, center[i], (int)radius[i], color, 2, 8, 0 );
|
||||
}
|
||||
|
||||
/// Show in a window
|
||||
namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( "Contours", WINDOW_AUTOSIZE );
|
||||
imshow( "Contours", drawing );
|
||||
}
|
||||
|
@@ -24,18 +24,18 @@ void thresh_callback(int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], 1 );
|
||||
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, CV_BGR2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
|
||||
/// Create Window
|
||||
char* source_window = "Source";
|
||||
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, src );
|
||||
|
||||
createTrackbar( " Threshold:", "Source", &thresh, max_thresh, thresh_callback );
|
||||
@@ -57,13 +57,13 @@ void thresh_callback(int, void* )
|
||||
/// Detect edges using Threshold
|
||||
threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY );
|
||||
/// Find contours
|
||||
findContours( threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
findContours( threshold_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
|
||||
/// Find the rotated rectangles and ellipses for each contour
|
||||
vector<RotatedRect> minRect( contours.size() );
|
||||
vector<RotatedRect> minEllipse( contours.size() );
|
||||
|
||||
for( int i = 0; i < contours.size(); i++ )
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{ minRect[i] = minAreaRect( Mat(contours[i]) );
|
||||
if( contours[i].size() > 5 )
|
||||
{ minEllipse[i] = fitEllipse( Mat(contours[i]) ); }
|
||||
@@ -71,11 +71,11 @@ void thresh_callback(int, void* )
|
||||
|
||||
/// Draw contours + rotated rects + ellipses
|
||||
Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
|
||||
for( int i = 0; i< contours.size(); i++ )
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
|
||||
// contour
|
||||
drawContours( drawing, contours, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
|
||||
drawContours( drawing, contours, (int)i, color, 1, 8, vector<Vec4i>(), 0, Point() );
|
||||
// ellipse
|
||||
ellipse( drawing, minEllipse[i], color, 2, 8 );
|
||||
// rotated rectangle
|
||||
@@ -85,6 +85,6 @@ void thresh_callback(int, void* )
|
||||
}
|
||||
|
||||
/// Show in a window
|
||||
namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( "Contours", WINDOW_AUTOSIZE );
|
||||
imshow( "Contours", drawing );
|
||||
}
|
||||
|
@@ -24,18 +24,18 @@ void thresh_callback(int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], 1 );
|
||||
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, CV_BGR2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
|
||||
/// Create Window
|
||||
char* source_window = "Source";
|
||||
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, src );
|
||||
|
||||
createTrackbar( " Threshold:", "Source", &thresh, max_thresh, thresh_callback );
|
||||
@@ -59,23 +59,23 @@ void thresh_callback(int, void* )
|
||||
threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY );
|
||||
|
||||
/// Find contours
|
||||
findContours( threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
findContours( threshold_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
|
||||
/// Find the convex hull object for each contour
|
||||
vector<vector<Point> >hull( contours.size() );
|
||||
for( int i = 0; i < contours.size(); i++ )
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{ convexHull( Mat(contours[i]), hull[i], false ); }
|
||||
|
||||
/// Draw contours + hull results
|
||||
Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
|
||||
for( int i = 0; i< contours.size(); i++ )
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
|
||||
drawContours( drawing, contours, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
|
||||
drawContours( drawing, hull, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
|
||||
drawContours( drawing, contours, (int)i, color, 1, 8, vector<Vec4i>(), 0, Point() );
|
||||
drawContours( drawing, hull, (int)i, color, 1, 8, vector<Vec4i>(), 0, Point() );
|
||||
}
|
||||
|
||||
/// Show in a window
|
||||
namedWindow( "Hull demo", CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( "Hull demo", WINDOW_AUTOSIZE );
|
||||
imshow( "Hull demo", drawing );
|
||||
}
|
||||
|
@@ -24,18 +24,18 @@ void thresh_callback(int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], 1 );
|
||||
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, CV_BGR2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
|
||||
/// Create Window
|
||||
char* source_window = "Source";
|
||||
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, src );
|
||||
|
||||
createTrackbar( " Canny thresh:", "Source", &thresh, max_thresh, thresh_callback );
|
||||
@@ -57,38 +57,38 @@ void thresh_callback(int, void* )
|
||||
/// Detect edges using canny
|
||||
Canny( src_gray, canny_output, thresh, thresh*2, 3 );
|
||||
/// Find contours
|
||||
findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
findContours( canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
|
||||
/// Get the moments
|
||||
vector<Moments> mu(contours.size() );
|
||||
for( int i = 0; i < contours.size(); i++ )
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{ mu[i] = moments( contours[i], false ); }
|
||||
|
||||
/// Get the mass centers:
|
||||
vector<Point2f> mc( contours.size() );
|
||||
for( int i = 0; i < contours.size(); i++ )
|
||||
{ mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 ); }
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{ mc[i] = Point2f( static_cast<float>(mu[i].m10/mu[i].m00) , static_cast<float>(mu[i].m01/mu[i].m00) ); }
|
||||
|
||||
/// Draw contours
|
||||
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
|
||||
for( int i = 0; i< contours.size(); i++ )
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
|
||||
drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
|
||||
drawContours( drawing, contours, (int)i, color, 2, 8, hierarchy, 0, Point() );
|
||||
circle( drawing, mc[i], 4, color, -1, 8, 0 );
|
||||
}
|
||||
|
||||
/// Show in a window
|
||||
namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( "Contours", WINDOW_AUTOSIZE );
|
||||
imshow( "Contours", drawing );
|
||||
|
||||
/// Calculate the area with the moments 00 and compare with the result of the OpenCV function
|
||||
printf("\t Info: Area and Contour Length \n");
|
||||
for( int i = 0; i< contours.size(); i++ )
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
printf(" * Contour[%d] - Area (M_00) = %.2f - Area OpenCV: %.2f - Length: %.2f \n", i, mu[i].m00, contourArea(contours[i]), arcLength( contours[i], true ) );
|
||||
printf(" * Contour[%d] - Area (M_00) = %.2f - Area OpenCV: %.2f - Length: %.2f \n", (int)i, mu[i].m00, contourArea(contours[i]), arcLength( contours[i], true ) );
|
||||
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
|
||||
drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
|
||||
drawContours( drawing, contours, (int)i, color, 2, 8, hierarchy, 0, Point() );
|
||||
circle( drawing, mc[i], 4, color, -1, 8, 0 );
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ using namespace std;
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( void )
|
||||
{
|
||||
/// Create an image
|
||||
const int r = 100;
|
||||
@@ -25,12 +25,12 @@ int main( int argc, char** argv )
|
||||
/// Create a sequence of points to make a contour:
|
||||
vector<Point2f> vert(6);
|
||||
|
||||
vert[0] = Point( 1.5*r, 1.34*r );
|
||||
vert[0] = Point( 3*r/2, static_cast<int>(1.34*r) );
|
||||
vert[1] = Point( 1*r, 2*r );
|
||||
vert[2] = Point( 1.5*r, 2.866*r );
|
||||
vert[3] = Point( 2.5*r, 2.866*r );
|
||||
vert[2] = Point( 3*r/2, static_cast<int>(2.866*r) );
|
||||
vert[3] = Point( 5*r/2, static_cast<int>(2.866*r) );
|
||||
vert[4] = Point( 3*r, 2*r );
|
||||
vert[5] = Point( 2.5*r, 1.34*r );
|
||||
vert[5] = Point( 5*r/2, static_cast<int>(1.34*r) );
|
||||
|
||||
/// Draw it in src
|
||||
for( int j = 0; j < 6; j++ )
|
||||
@@ -47,7 +47,7 @@ int main( int argc, char** argv )
|
||||
|
||||
for( int j = 0; j < src.rows; j++ )
|
||||
{ for( int i = 0; i < src.cols; i++ )
|
||||
{ raw_dist.at<float>(j,i) = pointPolygonTest( contours[0], Point2f(i,j), true ); }
|
||||
{ raw_dist.at<float>(j,i) = (float)pointPolygonTest( contours[0], Point2f((float)i,(float)j), true ); }
|
||||
}
|
||||
|
||||
double minVal; double maxVal;
|
||||
@@ -61,19 +61,19 @@ int main( int argc, char** argv )
|
||||
{ for( int i = 0; i < src.cols; i++ )
|
||||
{
|
||||
if( raw_dist.at<float>(j,i) < 0 )
|
||||
{ drawing.at<Vec3b>(j,i)[0] = 255 - (int) abs(raw_dist.at<float>(j,i))*255/minVal; }
|
||||
{ drawing.at<Vec3b>(j,i)[0] = (uchar)(255 - abs(raw_dist.at<float>(j,i))*255/minVal); }
|
||||
else if( raw_dist.at<float>(j,i) > 0 )
|
||||
{ drawing.at<Vec3b>(j,i)[2] = 255 - (int) raw_dist.at<float>(j,i)*255/maxVal; }
|
||||
{ drawing.at<Vec3b>(j,i)[2] = (uchar)(255 - raw_dist.at<float>(j,i)*255/maxVal); }
|
||||
else
|
||||
{ drawing.at<Vec3b>(j,i)[0] = 255; drawing.at<Vec3b>(j,i)[1] = 255; drawing.at<Vec3b>(j,i)[2] = 255; }
|
||||
}
|
||||
}
|
||||
|
||||
/// Create Window and show your results
|
||||
char* source_window = "Source";
|
||||
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, src );
|
||||
namedWindow( "Distance", CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( "Distance", WINDOW_AUTOSIZE );
|
||||
imshow( "Distance", drawing );
|
||||
|
||||
waitKey(0);
|
||||
|
@@ -26,8 +26,8 @@ double myShiTomasi_minVal; double myShiTomasi_maxVal;
|
||||
|
||||
RNG rng(12345);
|
||||
|
||||
char* myHarris_window = "My Harris corner detector";
|
||||
char* myShiTomasi_window = "My Shi Tomasi corner detector";
|
||||
const char* myHarris_window = "My Harris corner detector";
|
||||
const char* myShiTomasi_window = "My Shi Tomasi corner detector";
|
||||
|
||||
/// Function headers
|
||||
void myShiTomasi_function( int, void* );
|
||||
@@ -36,11 +36,11 @@ void myHarris_function( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], 1 );
|
||||
cvtColor( src, src_gray, CV_BGR2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
|
||||
/// Set some parameters
|
||||
int blockSize = 3; int apertureSize = 3;
|
||||
@@ -57,14 +57,14 @@ int main( int argc, char** argv )
|
||||
{
|
||||
float lambda_1 = myHarris_dst.at<Vec6f>(j, i)[0];
|
||||
float lambda_2 = myHarris_dst.at<Vec6f>(j, i)[1];
|
||||
Mc.at<float>(j,i) = lambda_1*lambda_2 - 0.04*pow( ( lambda_1 + lambda_2 ), 2 );
|
||||
Mc.at<float>(j,i) = lambda_1*lambda_2 - 0.04f*pow( ( lambda_1 + lambda_2 ), 2 );
|
||||
}
|
||||
}
|
||||
|
||||
minMaxLoc( Mc, &myHarris_minVal, &myHarris_maxVal, 0, 0, Mat() );
|
||||
|
||||
/* Create Window and Trackbar */
|
||||
namedWindow( myHarris_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( myHarris_window, WINDOW_AUTOSIZE );
|
||||
createTrackbar( " Quality Level:", myHarris_window, &myHarris_qualityLevel, max_qualityLevel, myHarris_function );
|
||||
myHarris_function( 0, 0 );
|
||||
|
||||
@@ -75,7 +75,7 @@ int main( int argc, char** argv )
|
||||
minMaxLoc( myShiTomasi_dst, &myShiTomasi_minVal, &myShiTomasi_maxVal, 0, 0, Mat() );
|
||||
|
||||
/* Create Window and Trackbar */
|
||||
namedWindow( myShiTomasi_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( myShiTomasi_window, WINDOW_AUTOSIZE );
|
||||
createTrackbar( " Quality Level:", myShiTomasi_window, &myShiTomasi_qualityLevel, max_qualityLevel, myShiTomasi_function );
|
||||
myShiTomasi_function( 0, 0 );
|
||||
|
||||
|
@@ -18,8 +18,8 @@ Mat src, src_gray;
|
||||
int thresh = 200;
|
||||
int max_thresh = 255;
|
||||
|
||||
char* source_window = "Source image";
|
||||
char* corners_window = "Corners detected";
|
||||
const char* source_window = "Source image";
|
||||
const char* corners_window = "Corners detected";
|
||||
|
||||
/// Function header
|
||||
void cornerHarris_demo( int, void* );
|
||||
@@ -27,14 +27,14 @@ void cornerHarris_demo( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], 1 );
|
||||
cvtColor( src, src_gray, CV_BGR2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
|
||||
/// Create a window and a trackbar
|
||||
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
createTrackbar( "Threshold: ", source_window, &thresh, max_thresh, cornerHarris_demo );
|
||||
imshow( source_window, src );
|
||||
|
||||
@@ -77,6 +77,6 @@ void cornerHarris_demo( int, void* )
|
||||
}
|
||||
}
|
||||
/// Showing the result
|
||||
namedWindow( corners_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( corners_window, WINDOW_AUTOSIZE );
|
||||
imshow( corners_window, dst_norm_scaled );
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ int maxCorners = 10;
|
||||
int maxTrackbar = 25;
|
||||
|
||||
RNG rng(12345);
|
||||
char* source_window = "Image";
|
||||
const char* source_window = "Image";
|
||||
|
||||
/// Function header
|
||||
void goodFeaturesToTrack_Demo( int, void* );
|
||||
@@ -28,14 +28,14 @@ void goodFeaturesToTrack_Demo( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], 1 );
|
||||
cvtColor( src, src_gray, CV_BGR2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
|
||||
/// Create Window
|
||||
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
|
||||
/// Create Trackbar to set the number of corners
|
||||
createTrackbar( "Max corners:", source_window, &maxCorners, maxTrackbar, goodFeaturesToTrack_Demo );
|
||||
@@ -83,23 +83,23 @@ void goodFeaturesToTrack_Demo( int, void* )
|
||||
/// Draw corners detected
|
||||
cout<<"** Number of corners detected: "<<corners.size()<<endl;
|
||||
int r = 4;
|
||||
for( int i = 0; i < corners.size(); i++ )
|
||||
for( size_t i = 0; i < corners.size(); i++ )
|
||||
{ circle( copy, corners[i], r, Scalar(rng.uniform(0,255), rng.uniform(0,255), rng.uniform(0,255)), -1, 8, 0 ); }
|
||||
|
||||
/// Show what you got
|
||||
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, copy );
|
||||
|
||||
/// Set the neeed parameters to find the refined corners
|
||||
Size winSize = Size( 5, 5 );
|
||||
Size zeroZone = Size( -1, -1 );
|
||||
TermCriteria criteria = TermCriteria( CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 40, 0.001 );
|
||||
TermCriteria criteria = TermCriteria( TermCriteria::EPS + TermCriteria::COUNT, 40, 0.001 );
|
||||
|
||||
/// Calculate the refined corner locations
|
||||
cornerSubPix( src_gray, corners, winSize, zeroZone, criteria );
|
||||
|
||||
/// Write them down
|
||||
for( int i = 0; i < corners.size(); i++ )
|
||||
for( size_t i = 0; i < corners.size(); i++ )
|
||||
{ cout<<" -- Refined Corner ["<<i<<"] ("<<corners[i].x<<","<<corners[i].y<<")"<<endl; }
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,7 @@ int maxCorners = 23;
|
||||
int maxTrackbar = 100;
|
||||
|
||||
RNG rng(12345);
|
||||
char* source_window = "Image";
|
||||
const char* source_window = "Image";
|
||||
|
||||
/// Function header
|
||||
void goodFeaturesToTrack_Demo( int, void* );
|
||||
@@ -28,14 +28,14 @@ void goodFeaturesToTrack_Demo( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( int, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], 1 );
|
||||
cvtColor( src, src_gray, CV_BGR2GRAY );
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
|
||||
/// Create Window
|
||||
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
|
||||
/// Create Trackbar to set the number of corners
|
||||
createTrackbar( "Max corners:", source_window, &maxCorners, maxTrackbar, goodFeaturesToTrack_Demo );
|
||||
@@ -83,11 +83,11 @@ void goodFeaturesToTrack_Demo( int, void* )
|
||||
/// Draw corners detected
|
||||
cout<<"** Number of corners detected: "<<corners.size()<<endl;
|
||||
int r = 4;
|
||||
for( int i = 0; i < corners.size(); i++ )
|
||||
for( size_t i = 0; i < corners.size(); i++ )
|
||||
{ circle( copy, corners[i], r, Scalar(rng.uniform(0,255), rng.uniform(0,255), rng.uniform(0,255)), -1, 8, 0 ); }
|
||||
|
||||
/// Show what you got
|
||||
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, copy );
|
||||
}
|
||||
|
||||
|
@@ -1,16 +1,18 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <opencv2/calib3d/calib3d.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/calib3d.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
void help()
|
||||
static void help()
|
||||
{
|
||||
cout << "This is a camera calibration sample." << endl
|
||||
<< "Usage: calibration configurationFile" << endl
|
||||
@@ -22,7 +24,7 @@ class Settings
|
||||
public:
|
||||
Settings() : goodInput(false) {}
|
||||
enum Pattern { NOT_EXISTING, CHESSBOARD, CIRCLES_GRID, ASYMMETRIC_CIRCLES_GRID };
|
||||
enum InputType {INVALID, CAMERA, VIDEO_FILE, IMAGE_LIST};
|
||||
enum InputType { INVALID, CAMERA, VIDEO_FILE, IMAGE_LIST };
|
||||
|
||||
void write(FileStorage& fs) const //Write serialization for this class
|
||||
{
|
||||
@@ -99,7 +101,7 @@ public:
|
||||
if (readStringList(input, imageList))
|
||||
{
|
||||
inputType = IMAGE_LIST;
|
||||
nrFrames = (nrFrames < imageList.size()) ? nrFrames : imageList.size();
|
||||
nrFrames = (nrFrames < (int)imageList.size()) ? nrFrames : (int)imageList.size();
|
||||
}
|
||||
else
|
||||
inputType = VIDEO_FILE;
|
||||
@@ -118,9 +120,9 @@ public:
|
||||
}
|
||||
|
||||
flag = 0;
|
||||
if(calibFixPrincipalPoint) flag |= CV_CALIB_FIX_PRINCIPAL_POINT;
|
||||
if(calibZeroTangentDist) flag |= CV_CALIB_ZERO_TANGENT_DIST;
|
||||
if(aspectRatio) flag |= CV_CALIB_FIX_ASPECT_RATIO;
|
||||
if(calibFixPrincipalPoint) flag |= CALIB_FIX_PRINCIPAL_POINT;
|
||||
if(calibZeroTangentDist) flag |= CALIB_ZERO_TANGENT_DIST;
|
||||
if(aspectRatio) flag |= CALIB_FIX_ASPECT_RATIO;
|
||||
|
||||
|
||||
calibrationPattern = NOT_EXISTING;
|
||||
@@ -145,7 +147,7 @@ public:
|
||||
view0.copyTo(result);
|
||||
}
|
||||
else if( atImageList < (int)imageList.size() )
|
||||
result = imread(imageList[atImageList++], CV_LOAD_IMAGE_COLOR);
|
||||
result = imread(imageList[atImageList++], IMREAD_COLOR);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -196,11 +198,7 @@ private:
|
||||
|
||||
};
|
||||
|
||||
void write(FileStorage& fs, const std::string&, const Settings& x)
|
||||
{
|
||||
x.write(fs);
|
||||
}
|
||||
void read(const FileNode& node, Settings& x, const Settings& default_value = Settings())
|
||||
static void read(const FileNode& node, Settings& x, const Settings& default_value = Settings())
|
||||
{
|
||||
if(node.empty())
|
||||
x = default_value;
|
||||
@@ -274,7 +272,7 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
case Settings::CHESSBOARD:
|
||||
found = findChessboardCorners( view, s.boardSize, pointBuf,
|
||||
CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FAST_CHECK | CV_CALIB_CB_NORMALIZE_IMAGE);
|
||||
CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_FAST_CHECK | CALIB_CB_NORMALIZE_IMAGE);
|
||||
break;
|
||||
case Settings::CIRCLES_GRID:
|
||||
found = findCirclesGrid( view, s.boardSize, pointBuf );
|
||||
@@ -282,6 +280,9 @@ int main(int argc, char* argv[])
|
||||
case Settings::ASYMMETRIC_CIRCLES_GRID:
|
||||
found = findCirclesGrid( view, s.boardSize, pointBuf, CALIB_CB_ASYMMETRIC_GRID );
|
||||
break;
|
||||
default:
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( found) // If done with success,
|
||||
@@ -290,9 +291,9 @@ int main(int argc, char* argv[])
|
||||
if( s.calibrationPattern == Settings::CHESSBOARD)
|
||||
{
|
||||
Mat viewGray;
|
||||
cvtColor(view, viewGray, CV_BGR2GRAY);
|
||||
cvtColor(view, viewGray, COLOR_BGR2GRAY);
|
||||
cornerSubPix( viewGray, pointBuf, Size(11,11),
|
||||
Size(-1,-1), TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 ));
|
||||
Size(-1,-1), TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 30, 0.1 ));
|
||||
}
|
||||
|
||||
if( mode == CAPTURING && // For camera only take new samples after delay time
|
||||
@@ -336,7 +337,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
//------------------------------ Show image and check for input commands -------------------
|
||||
imshow("Image View", view);
|
||||
char key = waitKey(s.inputCapture.isOpened() ? 50 : s.delay);
|
||||
char key = (char)waitKey(s.inputCapture.isOpened() ? 50 : s.delay);
|
||||
|
||||
if( key == ESC_KEY )
|
||||
break;
|
||||
@@ -366,7 +367,7 @@ int main(int argc, char* argv[])
|
||||
continue;
|
||||
remap(view, rview, map1, map2, INTER_LINEAR);
|
||||
imshow("Image View", rview);
|
||||
char c = waitKey();
|
||||
char c = (char)waitKey();
|
||||
if( c == ESC_KEY || c == 'q' || c == 'Q' )
|
||||
break;
|
||||
}
|
||||
@@ -376,11 +377,11 @@ int main(int argc, char* argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
double computeReprojectionErrors( const vector<vector<Point3f> >& objectPoints,
|
||||
const vector<vector<Point2f> >& imagePoints,
|
||||
const vector<Mat>& rvecs, const vector<Mat>& tvecs,
|
||||
const Mat& cameraMatrix , const Mat& distCoeffs,
|
||||
vector<float>& perViewErrors)
|
||||
static double computeReprojectionErrors( const vector<vector<Point3f> >& objectPoints,
|
||||
const vector<vector<Point2f> >& imagePoints,
|
||||
const vector<Mat>& rvecs, const vector<Mat>& tvecs,
|
||||
const Mat& cameraMatrix , const Mat& distCoeffs,
|
||||
vector<float>& perViewErrors)
|
||||
{
|
||||
vector<Point2f> imagePoints2;
|
||||
int i, totalPoints = 0;
|
||||
@@ -391,7 +392,7 @@ double computeReprojectionErrors( const vector<vector<Point3f> >& objectPoints,
|
||||
{
|
||||
projectPoints( Mat(objectPoints[i]), rvecs[i], tvecs[i], cameraMatrix,
|
||||
distCoeffs, imagePoints2);
|
||||
err = norm(Mat(imagePoints[i]), Mat(imagePoints2), CV_L2);
|
||||
err = norm(Mat(imagePoints[i]), Mat(imagePoints2), NORM_L2);
|
||||
|
||||
int n = (int)objectPoints[i].size();
|
||||
perViewErrors[i] = (float) std::sqrt(err*err/n);
|
||||
@@ -402,8 +403,8 @@ double computeReprojectionErrors( const vector<vector<Point3f> >& objectPoints,
|
||||
return std::sqrt(totalErr/totalPoints);
|
||||
}
|
||||
|
||||
void calcBoardCornerPositions(Size boardSize, float squareSize, vector<Point3f>& corners,
|
||||
Settings::Pattern patternType /*= Settings::CHESSBOARD*/)
|
||||
static void calcBoardCornerPositions(Size boardSize, float squareSize, vector<Point3f>& corners,
|
||||
Settings::Pattern patternType /*= Settings::CHESSBOARD*/)
|
||||
{
|
||||
corners.clear();
|
||||
|
||||
@@ -421,16 +422,18 @@ void calcBoardCornerPositions(Size boardSize, float squareSize, vector<Point3f>&
|
||||
for( int j = 0; j < boardSize.width; j++ )
|
||||
corners.push_back(Point3f(float((2*j + i % 2)*squareSize), float(i*squareSize), 0));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool runCalibration( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat& distCoeffs,
|
||||
vector<vector<Point2f> > imagePoints, vector<Mat>& rvecs, vector<Mat>& tvecs,
|
||||
vector<float>& reprojErrs, double& totalAvgErr)
|
||||
static bool runCalibration( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat& distCoeffs,
|
||||
vector<vector<Point2f> > imagePoints, vector<Mat>& rvecs, vector<Mat>& tvecs,
|
||||
vector<float>& reprojErrs, double& totalAvgErr)
|
||||
{
|
||||
|
||||
cameraMatrix = Mat::eye(3, 3, CV_64F);
|
||||
if( s.flag & CV_CALIB_FIX_ASPECT_RATIO )
|
||||
if( s.flag & CALIB_FIX_ASPECT_RATIO )
|
||||
cameraMatrix.at<double>(0,0) = 1.0;
|
||||
|
||||
distCoeffs = Mat::zeros(8, 1, CV_64F);
|
||||
@@ -442,7 +445,7 @@ bool runCalibration( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat& distC
|
||||
|
||||
//Find intrinsic and extrinsic camera parameters
|
||||
double rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix,
|
||||
distCoeffs, rvecs, tvecs, s.flag|CV_CALIB_FIX_K4|CV_CALIB_FIX_K5);
|
||||
distCoeffs, rvecs, tvecs, s.flag|CALIB_FIX_K4|CALIB_FIX_K5);
|
||||
|
||||
cout << "Re-projection error reported by calibrateCamera: "<< rms << endl;
|
||||
|
||||
@@ -455,16 +458,16 @@ bool runCalibration( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat& distC
|
||||
}
|
||||
|
||||
// Print camera parameters to the output file
|
||||
void saveCameraParams( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat& distCoeffs,
|
||||
const vector<Mat>& rvecs, const vector<Mat>& tvecs,
|
||||
const vector<float>& reprojErrs, const vector<vector<Point2f> >& imagePoints,
|
||||
double totalAvgErr )
|
||||
static void saveCameraParams( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat& distCoeffs,
|
||||
const vector<Mat>& rvecs, const vector<Mat>& tvecs,
|
||||
const vector<float>& reprojErrs, const vector<vector<Point2f> >& imagePoints,
|
||||
double totalAvgErr )
|
||||
{
|
||||
FileStorage fs( s.outputFileName, FileStorage::WRITE );
|
||||
|
||||
time_t t;
|
||||
time( &t );
|
||||
struct tm *t2 = localtime( &t );
|
||||
time_t tm;
|
||||
time( &tm );
|
||||
struct tm *t2 = localtime( &tm );
|
||||
char buf[1024];
|
||||
strftime( buf, sizeof(buf)-1, "%c", t2 );
|
||||
|
||||
@@ -478,17 +481,17 @@ void saveCameraParams( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat& dis
|
||||
fs << "board_Height" << s.boardSize.height;
|
||||
fs << "square_Size" << s.squareSize;
|
||||
|
||||
if( s.flag & CV_CALIB_FIX_ASPECT_RATIO )
|
||||
if( s.flag & CALIB_FIX_ASPECT_RATIO )
|
||||
fs << "FixAspectRatio" << s.aspectRatio;
|
||||
|
||||
if( s.flag )
|
||||
{
|
||||
sprintf( buf, "flags: %s%s%s%s",
|
||||
s.flag & CV_CALIB_USE_INTRINSIC_GUESS ? " +use_intrinsic_guess" : "",
|
||||
s.flag & CV_CALIB_FIX_ASPECT_RATIO ? " +fix_aspectRatio" : "",
|
||||
s.flag & CV_CALIB_FIX_PRINCIPAL_POINT ? " +fix_principal_point" : "",
|
||||
s.flag & CV_CALIB_ZERO_TANGENT_DIST ? " +zero_tangent_dist" : "" );
|
||||
cvWriteComment( *fs, buf, 0 );
|
||||
s.flag & CALIB_USE_INTRINSIC_GUESS ? " +use_intrinsic_guess" : "",
|
||||
s.flag & CALIB_FIX_ASPECT_RATIO ? " +fix_aspectRatio" : "",
|
||||
s.flag & CALIB_FIX_PRINCIPAL_POINT ? " +fix_principal_point" : "",
|
||||
s.flag & CALIB_ZERO_TANGENT_DIST ? " +zero_tangent_dist" : "" );
|
||||
//cvWriteComment( *fs, buf, 0 );
|
||||
|
||||
}
|
||||
|
||||
@@ -516,13 +519,13 @@ void saveCameraParams( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat& dis
|
||||
r = rvecs[i].t();
|
||||
t = tvecs[i].t();
|
||||
}
|
||||
cvWriteComment( *fs, "a set of 6-tuples (rotation vector + translation vector) for each view", 0 );
|
||||
//cvWriteComment( *fs, "a set of 6-tuples (rotation vector + translation vector) for each view", 0 );
|
||||
fs << "Extrinsic_Parameters" << bigmat;
|
||||
}
|
||||
|
||||
if( !imagePoints.empty() )
|
||||
{
|
||||
Mat imagePtMat((int)imagePoints.size(), imagePoints[0].size(), CV_32FC2);
|
||||
Mat imagePtMat((int)imagePoints.size(), (int)imagePoints[0].size(), CV_32FC2);
|
||||
for( int i = 0; i < (int)imagePoints.size(); i++ )
|
||||
{
|
||||
Mat r = imagePtMat.row(i).reshape(2, imagePtMat.cols);
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
using namespace cv;
|
||||
|
||||
char *windowDisparity = "Disparity";
|
||||
const char *windowDisparity = "Disparity";
|
||||
|
||||
void readme();
|
||||
|
||||
@@ -26,8 +26,8 @@ int main( int argc, char** argv )
|
||||
{ readme(); return -1; }
|
||||
|
||||
//-- 1. Read the images
|
||||
Mat imgLeft = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
|
||||
Mat imgRight = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
|
||||
Mat imgLeft = imread( argv[1], IMREAD_GRAYSCALE );
|
||||
Mat imgRight = imread( argv[2], IMREAD_GRAYSCALE );
|
||||
//-- And create the image in which we will save our disparities
|
||||
Mat imgDisparity16S = Mat( imgLeft.rows, imgLeft.cols, CV_16S );
|
||||
Mat imgDisparity8U = Mat( imgLeft.rows, imgLeft.cols, CV_8UC1 );
|
||||
@@ -39,12 +39,10 @@ int main( int argc, char** argv )
|
||||
int ndisparities = 16*5; /**< Range of disparity */
|
||||
int SADWindowSize = 21; /**< Size of the block window. Must be odd */
|
||||
|
||||
StereoBM sbm( StereoBM::BASIC_PRESET,
|
||||
ndisparities,
|
||||
SADWindowSize );
|
||||
Ptr<StereoBM> sbm = createStereoBM( ndisparities, SADWindowSize );
|
||||
|
||||
//-- 3. Calculate the disparity image
|
||||
sbm( imgLeft, imgRight, imgDisparity16S, CV_16S );
|
||||
sbm->compute( imgLeft, imgRight, imgDisparity16S );
|
||||
|
||||
//-- Check its extreme values
|
||||
double minVal; double maxVal;
|
||||
@@ -56,7 +54,7 @@ int main( int argc, char** argv )
|
||||
//-- 4. Display it as a CV_8UC1 image
|
||||
imgDisparity16S.convertTo( imgDisparity8U, CV_8UC1, 255/(maxVal - minVal));
|
||||
|
||||
namedWindow( windowDisparity, CV_WINDOW_NORMAL );
|
||||
namedWindow( windowDisparity, WINDOW_NORMAL );
|
||||
imshow( windowDisparity, imgDisparity8U );
|
||||
|
||||
//-- 5. Save the image
|
||||
|
@@ -9,7 +9,8 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "opencv2/contrib.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
static void help(std::string errorMessage)
|
||||
{
|
||||
@@ -99,10 +100,12 @@ int main(int argc, char* argv[]) {
|
||||
// if the last parameter is 'log', then activate log sampling (favour foveal vision and subsamples peripheral vision)
|
||||
if (useLogSampling)
|
||||
{
|
||||
myRetina = cv::createRetina(inputFrame.size(), true, cv::RETINA_COLOR_BAYER, true, 2.0, 10.0);
|
||||
myRetina = cv::createRetina(inputFrame.size(), true, cv::RETINA_COLOR_BAYER, true, 2.0, 10.0);
|
||||
}
|
||||
else// -> else allocate "classical" retina :
|
||||
{
|
||||
myRetina = cv::createRetina(inputFrame.size());
|
||||
}
|
||||
|
||||
// save default retina parameters file in order to let you see this and maybe modify it and reload using method "setup"
|
||||
myRetina->write("RetinaDefaultParameters.xml");
|
||||
@@ -110,7 +113,7 @@ int main(int argc, char* argv[]) {
|
||||
// load parameters if file exists
|
||||
myRetina->setup("RetinaSpecificParameters.xml");
|
||||
|
||||
// reset all retina buffers (imagine you close your eyes for a long time)
|
||||
// reset all retina buffers (imagine you close your eyes for a long time)
|
||||
myRetina->clearBuffers();
|
||||
|
||||
// declare retina output buffers
|
||||
@@ -118,7 +121,7 @@ int main(int argc, char* argv[]) {
|
||||
cv::Mat retinaOutput_magno;
|
||||
|
||||
// processing loop with no stop condition
|
||||
while(true)
|
||||
for(;;)
|
||||
{
|
||||
// if using video stream, then, grabbing a new frame, else, input remains the same
|
||||
if (videoCapture.isOpened())
|
||||
|
@@ -20,7 +20,7 @@ void MyLine( Mat img, Point start, Point end );
|
||||
* @function main
|
||||
* @brief Main function
|
||||
*/
|
||||
int main( int argc, char **argv ){
|
||||
int main( void ){
|
||||
|
||||
/// Windows names
|
||||
char atom_window[] = "Drawing 1: Atom";
|
||||
@@ -40,7 +40,7 @@ int main( int argc, char **argv ){
|
||||
MyEllipse( atom_image, -45 );
|
||||
|
||||
/// 1.b. Creating circles
|
||||
MyFilledCircle( atom_image, Point( w/2.0, w/2.0) );
|
||||
MyFilledCircle( atom_image, Point( w/2, w/2) );
|
||||
|
||||
/// 2. Draw a rook
|
||||
/// ------------------
|
||||
@@ -50,7 +50,7 @@ int main( int argc, char **argv ){
|
||||
|
||||
/// 2.b. Creating rectangles
|
||||
rectangle( rook_image,
|
||||
Point( 0, 7*w/8.0 ),
|
||||
Point( 0, 7*w/8 ),
|
||||
Point( w, w),
|
||||
Scalar( 0, 255, 255 ),
|
||||
-1,
|
||||
@@ -64,9 +64,9 @@ int main( int argc, char **argv ){
|
||||
|
||||
/// 3. Display your stuff!
|
||||
imshow( atom_window, atom_image );
|
||||
cvMoveWindow( atom_window, 0, 200 );
|
||||
moveWindow( atom_window, 0, 200 );
|
||||
imshow( rook_window, rook_image );
|
||||
cvMoveWindow( rook_window, w, 200 );
|
||||
moveWindow( rook_window, w, 200 );
|
||||
|
||||
waitKey( 0 );
|
||||
return(0);
|
||||
@@ -84,8 +84,8 @@ void MyEllipse( Mat img, double angle )
|
||||
int lineType = 8;
|
||||
|
||||
ellipse( img,
|
||||
Point( w/2.0, w/2.0 ),
|
||||
Size( w/4.0, w/16.0 ),
|
||||
Point( w/2, w/2 ),
|
||||
Size( w/4, w/16 ),
|
||||
angle,
|
||||
0,
|
||||
360,
|
||||
@@ -105,7 +105,7 @@ void MyFilledCircle( Mat img, Point center )
|
||||
|
||||
circle( img,
|
||||
center,
|
||||
w/32.0,
|
||||
w/32,
|
||||
Scalar( 0, 0, 255 ),
|
||||
thickness,
|
||||
lineType );
|
||||
@@ -121,26 +121,26 @@ void MyPolygon( Mat img )
|
||||
|
||||
/** Create some points */
|
||||
Point rook_points[1][20];
|
||||
rook_points[0][0] = Point( w/4.0, 7*w/8.0 );
|
||||
rook_points[0][1] = Point( 3*w/4.0, 7*w/8.0 );
|
||||
rook_points[0][2] = Point( 3*w/4.0, 13*w/16.0 );
|
||||
rook_points[0][3] = Point( 11*w/16.0, 13*w/16.0 );
|
||||
rook_points[0][4] = Point( 19*w/32.0, 3*w/8.0 );
|
||||
rook_points[0][5] = Point( 3*w/4.0, 3*w/8.0 );
|
||||
rook_points[0][6] = Point( 3*w/4.0, w/8.0 );
|
||||
rook_points[0][7] = Point( 26*w/40.0, w/8.0 );
|
||||
rook_points[0][8] = Point( 26*w/40.0, w/4.0 );
|
||||
rook_points[0][9] = Point( 22*w/40.0, w/4.0 );
|
||||
rook_points[0][10] = Point( 22*w/40.0, w/8.0 );
|
||||
rook_points[0][11] = Point( 18*w/40.0, w/8.0 );
|
||||
rook_points[0][12] = Point( 18*w/40.0, w/4.0 );
|
||||
rook_points[0][13] = Point( 14*w/40.0, w/4.0 );
|
||||
rook_points[0][14] = Point( 14*w/40.0, w/8.0 );
|
||||
rook_points[0][15] = Point( w/4.0, w/8.0 );
|
||||
rook_points[0][16] = Point( w/4.0, 3*w/8.0 );
|
||||
rook_points[0][17] = Point( 13*w/32.0, 3*w/8.0 );
|
||||
rook_points[0][18] = Point( 5*w/16.0, 13*w/16.0 );
|
||||
rook_points[0][19] = Point( w/4.0, 13*w/16.0) ;
|
||||
rook_points[0][0] = Point( w/4, 7*w/8 );
|
||||
rook_points[0][1] = Point( 3*w/4, 7*w/8 );
|
||||
rook_points[0][2] = Point( 3*w/4, 13*w/16 );
|
||||
rook_points[0][3] = Point( 11*w/16, 13*w/16 );
|
||||
rook_points[0][4] = Point( 19*w/32, 3*w/8 );
|
||||
rook_points[0][5] = Point( 3*w/4, 3*w/8 );
|
||||
rook_points[0][6] = Point( 3*w/4, w/8 );
|
||||
rook_points[0][7] = Point( 26*w/40, w/8 );
|
||||
rook_points[0][8] = Point( 26*w/40, w/4 );
|
||||
rook_points[0][9] = Point( 22*w/40, w/4 );
|
||||
rook_points[0][10] = Point( 22*w/40, w/8 );
|
||||
rook_points[0][11] = Point( 18*w/40, w/8 );
|
||||
rook_points[0][12] = Point( 18*w/40, w/4 );
|
||||
rook_points[0][13] = Point( 14*w/40, w/4 );
|
||||
rook_points[0][14] = Point( 14*w/40, w/8 );
|
||||
rook_points[0][15] = Point( w/4, w/8 );
|
||||
rook_points[0][16] = Point( w/4, 3*w/8 );
|
||||
rook_points[0][17] = Point( 13*w/32, 3*w/8 );
|
||||
rook_points[0][18] = Point( 5*w/16, 13*w/16 );
|
||||
rook_points[0][19] = Point( w/4, 13*w/16 );
|
||||
|
||||
const Point* ppt[1] = { rook_points[0] };
|
||||
int npt[] = { 20 };
|
||||
|
@@ -36,7 +36,7 @@ int Displaying_Big_End( Mat image, char* window_name, RNG rng );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
int main( void )
|
||||
{
|
||||
int c;
|
||||
|
||||
@@ -106,7 +106,6 @@ static Scalar randomColor( RNG& rng )
|
||||
*/
|
||||
int Drawing_Random_Lines( Mat image, char* window_name, RNG rng )
|
||||
{
|
||||
int lineType = 8;
|
||||
Point pt1, pt2;
|
||||
|
||||
for( int i = 0; i < NUMBER; i++ )
|
||||
@@ -303,9 +302,9 @@ int Displaying_Random_Text( Mat image, char* window_name, RNG rng )
|
||||
/**
|
||||
* @function Displaying_Big_End
|
||||
*/
|
||||
int Displaying_Big_End( Mat image, char* window_name, RNG rng )
|
||||
int Displaying_Big_End( Mat image, char* window_name, RNG )
|
||||
{
|
||||
Size textsize = getTextSize("OpenCV forever!", CV_FONT_HERSHEY_COMPLEX, 3, 5, 0);
|
||||
Size textsize = getTextSize("OpenCV forever!", FONT_HERSHEY_COMPLEX, 3, 5, 0);
|
||||
Point org((window_width - textsize.width)/2, (window_height - textsize.height)/2);
|
||||
int lineType = 8;
|
||||
|
||||
@@ -314,7 +313,7 @@ int Displaying_Big_End( Mat image, char* window_name, RNG rng )
|
||||
for( int i = 0; i < 255; i += 2 )
|
||||
{
|
||||
image2 = image - Scalar::all(i);
|
||||
putText( image2, "OpenCV forever!", org, CV_FONT_HERSHEY_COMPLEX, 3,
|
||||
putText( image2, "OpenCV forever!", org, FONT_HERSHEY_COMPLEX, 3,
|
||||
Scalar(i, i, 255), 5, lineType );
|
||||
|
||||
imshow( window_name, image2 );
|
||||
|
@@ -7,7 +7,7 @@
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
void help(char* progName)
|
||||
static void help(char* progName)
|
||||
{
|
||||
cout << endl
|
||||
<< "This program demonstrated the use of the discrete Fourier transform (DFT). " << endl
|
||||
@@ -22,7 +22,7 @@ int main(int argc, char ** argv)
|
||||
|
||||
const char* filename = argc >=2 ? argv[1] : "lena.jpg";
|
||||
|
||||
Mat I = imread(filename, CV_LOAD_IMAGE_GRAYSCALE);
|
||||
Mat I = imread(filename, IMREAD_GRAYSCALE);
|
||||
if( I.empty())
|
||||
return -1;
|
||||
|
||||
@@ -67,7 +67,7 @@ int main(int argc, char ** argv)
|
||||
q2.copyTo(q1);
|
||||
tmp.copyTo(q2);
|
||||
|
||||
normalize(magI, magI, 0, 1, CV_MINMAX); // Transform the matrix with float values into a
|
||||
normalize(magI, magI, 0, 1, NORM_MINMAX); // Transform the matrix with float values into a
|
||||
// viewable image form (float between values 0 and 1).
|
||||
|
||||
imshow("Input Image" , I ); // Show the result
|
||||
|
@@ -5,7 +5,7 @@
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
void help(char** av)
|
||||
static void help(char** av)
|
||||
{
|
||||
cout << endl
|
||||
<< av[0] << " shows the usage of the OpenCV serialization functionality." << endl
|
||||
@@ -42,11 +42,11 @@ public: // Data Members
|
||||
};
|
||||
|
||||
//These write and read functions must be defined for the serialization in FileStorage to work
|
||||
void write(FileStorage& fs, const std::string&, const MyData& x)
|
||||
static void write(FileStorage& fs, const std::string&, const MyData& x)
|
||||
{
|
||||
x.write(fs);
|
||||
}
|
||||
void read(const FileNode& node, MyData& x, const MyData& default_value = MyData()){
|
||||
static void read(const FileNode& node, MyData& x, const MyData& default_value = MyData()){
|
||||
if(node.empty())
|
||||
x = default_value;
|
||||
else
|
||||
@@ -54,7 +54,7 @@ void read(const FileNode& node, MyData& x, const MyData& default_value = MyData(
|
||||
}
|
||||
|
||||
// This function will print our custom class to the console
|
||||
ostream& operator<<(ostream& out, const MyData& m)
|
||||
static ostream& operator<<(ostream& out, const MyData& m)
|
||||
{
|
||||
out << "{ id = " << m.id << ", ";
|
||||
out << "X = " << m.X << ", ";
|
||||
|
@@ -1,12 +1,13 @@
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void help()
|
||||
static void help()
|
||||
{
|
||||
cout
|
||||
<< "\n--------------------------------------------------------------------------" << endl
|
||||
@@ -35,9 +36,9 @@ int main( int argc, char* argv[])
|
||||
|
||||
Mat I, J;
|
||||
if( argc == 4 && !strcmp(argv[3],"G") )
|
||||
I = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
|
||||
I = imread(argv[1], IMREAD_GRAYSCALE);
|
||||
else
|
||||
I = imread(argv[1], CV_LOAD_IMAGE_COLOR);
|
||||
I = imread(argv[1], IMREAD_COLOR);
|
||||
|
||||
if (!I.data)
|
||||
{
|
||||
@@ -45,11 +46,11 @@ int main( int argc, char* argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
int divideWith; // convert our input string to number - C++ style
|
||||
int divideWith = 0; // convert our input string to number - C++ style
|
||||
stringstream s;
|
||||
s << argv[2];
|
||||
s >> divideWith;
|
||||
if (!s)
|
||||
if (!s || !divideWith)
|
||||
{
|
||||
cout << "Invalid number entered for dividing. " << endl;
|
||||
return -1;
|
||||
@@ -57,7 +58,7 @@ int main( int argc, char* argv[])
|
||||
|
||||
uchar table[256];
|
||||
for (int i = 0; i < 256; ++i)
|
||||
table[i] = divideWith* (i/divideWith);
|
||||
table[i] = (uchar)(divideWith * (i/divideWith));
|
||||
|
||||
const int times = 100;
|
||||
double t;
|
||||
|
@@ -4,11 +4,12 @@
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
|
||||
using namespace cv; // The new C++ interface API is inside this namespace. Import it.
|
||||
using namespace std;
|
||||
|
||||
void help( char* progName)
|
||||
static void help( char* progName)
|
||||
{
|
||||
cout << endl << progName
|
||||
<< " shows how to use cv::Mat and IplImages together (converting back and forth)." << endl
|
||||
@@ -21,6 +22,10 @@ void help( char* progName)
|
||||
// comment out the define to use only the latest C++ API
|
||||
#define DEMO_MIXED_API_USE
|
||||
|
||||
#ifdef DEMO_MIXED_API_USE
|
||||
# include <opencv2/highgui/highgui_c.h>
|
||||
#endif
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
help(argv[0]);
|
||||
@@ -33,7 +38,7 @@ int main( int argc, char** argv )
|
||||
cerr << "Can not load image " << imagename << endl;
|
||||
return -1;
|
||||
}
|
||||
Mat I(IplI); // Convert to the new style container. Only header created. Image not copied.
|
||||
Mat I = cv::cvarrToMat(IplI); // Convert to the new style container. Only header created. Image not copied.
|
||||
#else
|
||||
Mat I = imread(imagename); // the newer cvLoadImage alternative, MATLAB-style function
|
||||
if( I.empty() ) // same as if( !I.data )
|
||||
@@ -45,7 +50,7 @@ int main( int argc, char** argv )
|
||||
|
||||
// convert image to YUV color space. The output image will be created automatically.
|
||||
Mat I_YUV;
|
||||
cvtColor(I, I_YUV, CV_BGR2YCrCb);
|
||||
cvtColor(I, I_YUV, COLOR_BGR2YCrCb);
|
||||
|
||||
vector<Mat> planes; // Use the STL's vector structure to store multiple Mat objects
|
||||
split(I_YUV, planes); // split the image into separate color planes (Y U V)
|
||||
@@ -114,10 +119,10 @@ int main( int argc, char** argv )
|
||||
|
||||
|
||||
merge(planes, I_YUV); // now merge the results back
|
||||
cvtColor(I_YUV, I, CV_YCrCb2BGR); // and produce the output RGB image
|
||||
cvtColor(I_YUV, I, COLOR_YCrCb2BGR); // and produce the output RGB image
|
||||
|
||||
|
||||
namedWindow("image with grain", CV_WINDOW_AUTOSIZE); // use this to create images
|
||||
namedWindow("image with grain", WINDOW_AUTOSIZE); // use this to create images
|
||||
|
||||
#ifdef DEMO_MIXED_API_USE
|
||||
// this is to demonstrate that I and IplI really share the data - the result of the above
|
||||
|
@@ -1,12 +1,13 @@
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void help(char* progName)
|
||||
static void help(char* progName)
|
||||
{
|
||||
cout << endl
|
||||
<< "This program shows how to filter images with mask: the write it yourself and the"
|
||||
@@ -26,12 +27,12 @@ int main( int argc, char* argv[])
|
||||
Mat I, J, K;
|
||||
|
||||
if (argc >= 3 && !strcmp("G", argv[2]))
|
||||
I = imread( filename, CV_LOAD_IMAGE_GRAYSCALE);
|
||||
I = imread( filename, IMREAD_GRAYSCALE);
|
||||
else
|
||||
I = imread( filename, CV_LOAD_IMAGE_COLOR);
|
||||
I = imread( filename, IMREAD_COLOR);
|
||||
|
||||
namedWindow("Input", CV_WINDOW_AUTOSIZE);
|
||||
namedWindow("Output", CV_WINDOW_AUTOSIZE);
|
||||
namedWindow("Input", WINDOW_AUTOSIZE);
|
||||
namedWindow("Output", WINDOW_AUTOSIZE);
|
||||
|
||||
imshow("Input", I);
|
||||
double t = (double)getTickCount();
|
||||
@@ -42,7 +43,7 @@ int main( int argc, char* argv[])
|
||||
cout << "Hand written function times passed in seconds: " << t << endl;
|
||||
|
||||
imshow("Output", J);
|
||||
cvWaitKey(0);
|
||||
waitKey();
|
||||
|
||||
Mat kern = (Mat_<char>(3,3) << 0, -1, 0,
|
||||
-1, 5, -1,
|
||||
@@ -54,7 +55,7 @@ int main( int argc, char* argv[])
|
||||
|
||||
imshow("Output", K);
|
||||
|
||||
cvWaitKey(0);
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
void Sharpen(const Mat& myImage,Mat& Result)
|
||||
|
@@ -6,7 +6,7 @@
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void help()
|
||||
static void help()
|
||||
{
|
||||
cout
|
||||
<< "\n--------------------------------------------------------------------------" << endl
|
||||
@@ -59,10 +59,10 @@ int main(int,char**)
|
||||
|
||||
// Demonstrate the output formating options
|
||||
cout << "R (default) = " << endl << R << endl << endl;
|
||||
cout << "R (python) = " << endl << format(R,"python") << endl << endl;
|
||||
cout << "R (numpy) = " << endl << format(R,"numpy" ) << endl << endl;
|
||||
cout << "R (csv) = " << endl << format(R,"csv" ) << endl << endl;
|
||||
cout << "R (c) = " << endl << format(R,"C" ) << endl << endl;
|
||||
cout << "R (python) = " << endl << format(R, Formatter::FMT_PYTHON) << endl << endl;
|
||||
cout << "R (numpy) = " << endl << format(R, Formatter::FMT_NUMPY ) << endl << endl;
|
||||
cout << "R (csv) = " << endl << format(R, Formatter::FMT_CSV ) << endl << endl;
|
||||
cout << "R (c) = " << endl << format(R, Formatter::FMT_C ) << endl << endl;
|
||||
|
||||
Point2f P(5, 1);
|
||||
cout << "Point (2D) = " << P << endl << endl;
|
||||
@@ -77,8 +77,8 @@ int main(int,char**)
|
||||
cout << "Vector of floats via Mat = " << Mat(v) << endl << endl;
|
||||
|
||||
vector<Point2f> vPoints(20);
|
||||
for (size_t E = 0; E < vPoints.size(); ++E)
|
||||
vPoints[E] = Point2f((float)(E * 5), (float)(E % 7));
|
||||
for (size_t i = 0; i < vPoints.size(); ++i)
|
||||
vPoints[i] = Point2f((float)(i * 5), (float)(i % 7));
|
||||
|
||||
cout << "A vector of 2D Points = " << vPoints << endl << endl;
|
||||
return 0;
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/nonfree/features2d.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void readme();
|
||||
@@ -24,8 +25,8 @@ int main( int argc, char** argv )
|
||||
if( argc != 3 )
|
||||
{ readme(); return -1; }
|
||||
|
||||
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
|
||||
Mat img_2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
|
||||
Mat img_1 = imread( argv[1], IMREAD_GRAYSCALE );
|
||||
Mat img_2 = imread( argv[2], IMREAD_GRAYSCALE );
|
||||
|
||||
if( !img_1.data || !img_2.data )
|
||||
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
|
||||
@@ -83,7 +84,7 @@ int main( int argc, char** argv )
|
||||
//-- Show detected matches
|
||||
imshow( "Good Matches", img_matches );
|
||||
|
||||
for( int i = 0; i < good_matches.size(); i++ )
|
||||
for( int i = 0; i < (int)good_matches.size(); i++ )
|
||||
{ printf( "-- Good Match [%d] Keypoint 1: %d -- Keypoint 2: %d \n", i, good_matches[i].queryIdx, good_matches[i].trainIdx ); }
|
||||
|
||||
waitKey(0);
|
||||
|
@@ -10,8 +10,9 @@
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/calib3d/calib3d.hpp"
|
||||
#include "opencv2/nonfree/features2d.cpp"
|
||||
#include "opencv2/nonfree/features2d.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void readme();
|
||||
@@ -25,8 +26,8 @@ int main( int argc, char** argv )
|
||||
if( argc != 3 )
|
||||
{ readme(); return -1; }
|
||||
|
||||
Mat img_object = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
|
||||
Mat img_scene = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
|
||||
Mat img_object = imread( argv[1], IMREAD_GRAYSCALE );
|
||||
Mat img_scene = imread( argv[2], IMREAD_GRAYSCALE );
|
||||
|
||||
if( !img_object.data || !img_scene.data )
|
||||
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
|
||||
@@ -84,29 +85,30 @@ int main( int argc, char** argv )
|
||||
std::vector<Point2f> obj;
|
||||
std::vector<Point2f> scene;
|
||||
|
||||
for( int i = 0; i < good_matches.size(); i++ )
|
||||
for( size_t i = 0; i < good_matches.size(); i++ )
|
||||
{
|
||||
//-- Get the keypoints from the good matches
|
||||
obj.push_back( keypoints_object[ good_matches[i].queryIdx ].pt );
|
||||
scene.push_back( keypoints_scene[ good_matches[i].trainIdx ].pt );
|
||||
}
|
||||
|
||||
Mat H = findHomography( obj, scene, CV_RANSAC );
|
||||
Mat H = findHomography( obj, scene, RANSAC );
|
||||
|
||||
//-- Get the corners from the image_1 ( the object to be "detected" )
|
||||
std::vector<Point2f> obj_corners(4);
|
||||
obj_corners[0] = cvPoint(0,0); obj_corners[1] = cvPoint( img_object.cols, 0 );
|
||||
obj_corners[2] = cvPoint( img_object.cols, img_object.rows ); obj_corners[3] = cvPoint( 0, img_object.rows );
|
||||
obj_corners[0] = Point(0,0); obj_corners[1] = Point( img_object.cols, 0 );
|
||||
obj_corners[2] = Point( img_object.cols, img_object.rows ); obj_corners[3] = Point( 0, img_object.rows );
|
||||
std::vector<Point2f> scene_corners(4);
|
||||
|
||||
perspectiveTransform( obj_corners, scene_corners, H);
|
||||
|
||||
|
||||
//-- Draw lines between the corners (the mapped object in the scene - image_2 )
|
||||
line( img_matches, scene_corners[0] + Point2f( img_object.cols, 0), scene_corners[1] + Point2f( img_object.cols, 0), Scalar(0, 255, 0), 4 );
|
||||
line( img_matches, scene_corners[1] + Point2f( img_object.cols, 0), scene_corners[2] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
|
||||
line( img_matches, scene_corners[2] + Point2f( img_object.cols, 0), scene_corners[3] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
|
||||
line( img_matches, scene_corners[3] + Point2f( img_object.cols, 0), scene_corners[0] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
|
||||
Point2f offset( (float)img_object.cols, 0);
|
||||
line( img_matches, scene_corners[0] + offset, scene_corners[1] + offset, Scalar(0, 255, 0), 4 );
|
||||
line( img_matches, scene_corners[1] + offset, scene_corners[2] + offset, Scalar( 0, 255, 0), 4 );
|
||||
line( img_matches, scene_corners[2] + offset, scene_corners[3] + offset, Scalar( 0, 255, 0), 4 );
|
||||
line( img_matches, scene_corners[3] + offset, scene_corners[0] + offset, Scalar( 0, 255, 0), 4 );
|
||||
|
||||
//-- Show detected matches
|
||||
imshow( "Good Matches & Object detection", img_matches );
|
||||
|
@@ -9,7 +9,7 @@
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/nonfree/features2d.cpp"
|
||||
#include "opencv2/nonfree/features2d.hpp"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
@@ -24,8 +24,8 @@ int main( int argc, char** argv )
|
||||
if( argc != 3 )
|
||||
{ return -1; }
|
||||
|
||||
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
|
||||
Mat img_2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
|
||||
Mat img_1 = imread( argv[1], IMREAD_GRAYSCALE );
|
||||
Mat img_2 = imread( argv[2], IMREAD_GRAYSCALE );
|
||||
|
||||
if( !img_1.data || !img_2.data )
|
||||
{ return -1; }
|
||||
@@ -49,7 +49,7 @@ int main( int argc, char** argv )
|
||||
extractor.compute( img_2, keypoints_2, descriptors_2 );
|
||||
|
||||
//-- Step 3: Matching descriptor vectors with a brute force matcher
|
||||
BruteForceMatcher< L2<float> > matcher;
|
||||
BFMatcher matcher(NORM_L2);
|
||||
std::vector< DMatch > matches;
|
||||
matcher.match( descriptors_1, descriptors_2, matches );
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/nonfree/features2d.cpp"
|
||||
#include "opencv2/nonfree/features2d.hpp"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
@@ -24,8 +24,8 @@ int main( int argc, char** argv )
|
||||
if( argc != 3 )
|
||||
{ readme(); return -1; }
|
||||
|
||||
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
|
||||
Mat img_2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
|
||||
Mat img_1 = imread( argv[1], IMREAD_GRAYSCALE );
|
||||
Mat img_2 = imread( argv[2], IMREAD_GRAYSCALE );
|
||||
|
||||
if( !img_1.data || !img_2.data )
|
||||
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
|
||||
|
@@ -1,10 +1,11 @@
|
||||
#include <iostream> // Console I/O
|
||||
#include <sstream> // String to number conversion
|
||||
|
||||
#include <opencv2/core/core.hpp> // Basic OpenCV structures
|
||||
#include <opencv2/imgproc/imgproc.hpp>// Image processing methods for the CPU
|
||||
#include <opencv2/highgui/highgui.hpp>// Read images
|
||||
#include <opencv2/gpu/gpu.hpp> // GPU structures and methods
|
||||
#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/gpu.hpp> // GPU structures and methods
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
@@ -42,7 +43,7 @@ struct BufferMSSIM // Optimized GPU versions
|
||||
};
|
||||
Scalar getMSSIM_GPU_optimized( const Mat& i1, const Mat& i2, BufferMSSIM& b);
|
||||
|
||||
void help()
|
||||
static void help()
|
||||
{
|
||||
cout
|
||||
<< "\n--------------------------------------------------------------------------" << endl
|
||||
@@ -54,7 +55,7 @@ void help()
|
||||
<< endl;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int, char *argv[])
|
||||
{
|
||||
help();
|
||||
Mat I1 = imread(argv[1]); // Read the two images
|
||||
@@ -72,7 +73,7 @@ int main(int argc, char *argv[])
|
||||
int TIMES;
|
||||
stringstream sstr(argv[3]);
|
||||
sstr >> TIMES;
|
||||
double time, result;
|
||||
double time, result = 0;
|
||||
|
||||
//------------------------------- PSNR CPU ----------------------------------------------------
|
||||
time = (double)getTickCount();
|
||||
@@ -84,7 +85,7 @@ int main(int argc, char *argv[])
|
||||
time /= TIMES;
|
||||
|
||||
cout << "Time of PSNR CPU (averaged for " << TIMES << " runs): " << time << " milliseconds."
|
||||
<< " With result of: " << result << endl;
|
||||
<< " With result of: " << result << endl;
|
||||
|
||||
//------------------------------- PSNR GPU ----------------------------------------------------
|
||||
time = (double)getTickCount();
|
||||
@@ -291,17 +292,17 @@ Scalar getMSSIM_GPU( const Mat& i1, const Mat& i2)
|
||||
{
|
||||
const float C1 = 6.5025f, C2 = 58.5225f;
|
||||
/***************************** INITS **********************************/
|
||||
gpu::GpuMat gI1, gI2, gs1, t1,t2;
|
||||
gpu::GpuMat gI1, gI2, gs1, tmp1,tmp2;
|
||||
|
||||
gI1.upload(i1);
|
||||
gI2.upload(i2);
|
||||
|
||||
gI1.convertTo(t1, CV_MAKE_TYPE(CV_32F, gI1.channels()));
|
||||
gI2.convertTo(t2, CV_MAKE_TYPE(CV_32F, gI2.channels()));
|
||||
gI1.convertTo(tmp1, CV_MAKE_TYPE(CV_32F, gI1.channels()));
|
||||
gI2.convertTo(tmp2, CV_MAKE_TYPE(CV_32F, gI2.channels()));
|
||||
|
||||
vector<gpu::GpuMat> vI1, vI2;
|
||||
gpu::split(t1, vI1);
|
||||
gpu::split(t2, vI2);
|
||||
gpu::split(tmp1, vI1);
|
||||
gpu::split(tmp2, vI2);
|
||||
Scalar mssim;
|
||||
|
||||
for( int i = 0; i < gI1.channels(); ++i )
|
||||
@@ -356,8 +357,6 @@ Scalar getMSSIM_GPU( const Mat& i1, const Mat& i2)
|
||||
|
||||
Scalar getMSSIM_GPU_optimized( const Mat& i1, const Mat& i2, BufferMSSIM& b)
|
||||
{
|
||||
int cn = i1.channels();
|
||||
|
||||
const float C1 = 6.5025f, C2 = 58.5225f;
|
||||
/***************************** INITS **********************************/
|
||||
|
||||
|
@@ -14,17 +14,17 @@ int main( int argc, char** argv )
|
||||
}
|
||||
|
||||
Mat image;
|
||||
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
|
||||
image = imread(argv[1], IMREAD_COLOR); // Read the file
|
||||
|
||||
if(! image.data ) // Check for invalid input
|
||||
if(! image.data ) // Check for invalid input
|
||||
{
|
||||
cout << "Could not open or find the image" << std::endl ;
|
||||
return -1;
|
||||
}
|
||||
|
||||
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
|
||||
imshow( "Display window", image ); // Show our image inside it.
|
||||
namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
|
||||
imshow( "Display window", image ); // Show our image inside it.
|
||||
|
||||
waitKey(0); // Wait for a keystroke in the window
|
||||
waitKey(0); // Wait for a keystroke in the window
|
||||
return 0;
|
||||
}
|
@@ -14,7 +14,7 @@ using namespace cv;
|
||||
double getPSNR ( const Mat& I1, const Mat& I2);
|
||||
Scalar getMSSIM( const Mat& I1, const Mat& I2);
|
||||
|
||||
void help()
|
||||
static void help()
|
||||
{
|
||||
cout
|
||||
<< "\n--------------------------------------------------------------------------" << endl
|
||||
@@ -26,7 +26,7 @@ void help()
|
||||
<< "--------------------------------------------------------------------------" << endl
|
||||
<< endl;
|
||||
}
|
||||
int main(int argc, char *argv[], char *window_name)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
help();
|
||||
if (argc != 5)
|
||||
@@ -59,10 +59,10 @@ int main(int argc, char *argv[], char *window_name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
Size refS = Size((int) captRefrnc.get(CV_CAP_PROP_FRAME_WIDTH),
|
||||
(int) captRefrnc.get(CV_CAP_PROP_FRAME_HEIGHT)),
|
||||
uTSi = Size((int) captUndTst.get(CV_CAP_PROP_FRAME_WIDTH),
|
||||
(int) captUndTst.get(CV_CAP_PROP_FRAME_HEIGHT));
|
||||
Size refS = Size((int) captRefrnc.get(CAP_PROP_FRAME_WIDTH),
|
||||
(int) captRefrnc.get(CAP_PROP_FRAME_HEIGHT)),
|
||||
uTSi = Size((int) captUndTst.get(CAP_PROP_FRAME_WIDTH),
|
||||
(int) captUndTst.get(CAP_PROP_FRAME_HEIGHT));
|
||||
|
||||
if (refS != uTSi)
|
||||
{
|
||||
@@ -74,13 +74,13 @@ int main(int argc, char *argv[], char *window_name)
|
||||
const char* WIN_RF = "Reference";
|
||||
|
||||
// Windows
|
||||
namedWindow(WIN_RF, CV_WINDOW_AUTOSIZE );
|
||||
namedWindow(WIN_UT, CV_WINDOW_AUTOSIZE );
|
||||
cvMoveWindow(WIN_RF, 400 , 0); //750, 2 (bernat =0)
|
||||
cvMoveWindow(WIN_UT, refS.width, 0); //1500, 2
|
||||
namedWindow(WIN_RF, WINDOW_AUTOSIZE );
|
||||
namedWindow(WIN_UT, WINDOW_AUTOSIZE );
|
||||
moveWindow(WIN_RF, 400 , 0); //750, 2 (bernat =0)
|
||||
moveWindow(WIN_UT, refS.width, 0); //1500, 2
|
||||
|
||||
cout << "Frame resolution: Width=" << refS.width << " Height=" << refS.height
|
||||
<< " of nr#: " << captRefrnc.get(CV_CAP_PROP_FRAME_COUNT) << endl;
|
||||
<< " of nr#: " << captRefrnc.get(CAP_PROP_FRAME_COUNT) << endl;
|
||||
|
||||
cout << "PSNR trigger value " <<
|
||||
setiosflags(ios::fixed) << setprecision(3) << psnrTriggerValue << endl;
|
||||
@@ -89,7 +89,7 @@ int main(int argc, char *argv[], char *window_name)
|
||||
double psnrV;
|
||||
Scalar mssimV;
|
||||
|
||||
while( true) //Show the image captured in the window and repeat
|
||||
for(;;) //Show the image captured in the window and repeat
|
||||
{
|
||||
captRefrnc >> frameReference;
|
||||
captUndTst >> frameUnderTest;
|
||||
@@ -124,7 +124,7 @@ int main(int argc, char *argv[], char *window_name)
|
||||
imshow( WIN_RF, frameReference);
|
||||
imshow( WIN_UT, frameUnderTest);
|
||||
|
||||
c = cvWaitKey(delay);
|
||||
c = (char)waitKey(delay);
|
||||
if (c == 27) break;
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
void help()
|
||||
static void help()
|
||||
{
|
||||
cout<< "\n--------------------------------------------------------------------------" << endl
|
||||
<< "This program shows Support Vector Machines for Non-Linearly Separable Data. " << endl
|
||||
|
@@ -6,6 +6,9 @@
|
||||
#include "opencv2/objdetect/objdetect.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/core/utility.hpp"
|
||||
|
||||
#include "opencv2/highgui/highgui_c.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
@@ -18,8 +21,8 @@ void detectAndDisplay( Mat frame );
|
||||
|
||||
/** Global variables */
|
||||
//-- Note, either copy these two files from opencv/data/haarscascades to your current folder, or change these locations
|
||||
String face_cascade_name = "haarcascade_frontalface_alt.xml";
|
||||
String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
|
||||
string face_cascade_name = "haarcascade_frontalface_alt.xml";
|
||||
string eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
|
||||
CascadeClassifier face_cascade;
|
||||
CascadeClassifier eyes_cascade;
|
||||
string window_name = "Capture - Face detection";
|
||||
@@ -28,7 +31,7 @@ RNG rng(12345);
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, const char** argv )
|
||||
int main( void )
|
||||
{
|
||||
CvCapture* capture;
|
||||
Mat frame;
|
||||
@@ -41,9 +44,9 @@ int main( int argc, const char** argv )
|
||||
capture = cvCaptureFromCAM( -1 );
|
||||
if( capture )
|
||||
{
|
||||
while( true )
|
||||
for(;;)
|
||||
{
|
||||
frame = cvQueryFrame( capture );
|
||||
frame = cv::cvarrToMat(cvQueryFrame( capture ));
|
||||
|
||||
//-- 3. Apply the classifier to the frame
|
||||
if( !frame.empty() )
|
||||
@@ -67,27 +70,27 @@ void detectAndDisplay( Mat frame )
|
||||
std::vector<Rect> faces;
|
||||
Mat frame_gray;
|
||||
|
||||
cvtColor( frame, frame_gray, CV_BGR2GRAY );
|
||||
cvtColor( frame, frame_gray, COLOR_BGR2GRAY );
|
||||
equalizeHist( frame_gray, frame_gray );
|
||||
//-- Detect faces
|
||||
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
|
||||
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CASCADE_SCALE_IMAGE, Size(30, 30) );
|
||||
|
||||
for( int i = 0; i < faces.size(); i++ )
|
||||
for( size_t i = 0; i < faces.size(); i++ )
|
||||
{
|
||||
Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
|
||||
ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 2, 8, 0 );
|
||||
Point center( faces[i].x + faces[i].width/2, faces[i].y + faces[i].height/2 );
|
||||
ellipse( frame, center, Size( faces[i].width/2, faces[i].height/2), 0, 0, 360, Scalar( 255, 0, 255 ), 2, 8, 0 );
|
||||
|
||||
Mat faceROI = frame_gray( faces[i] );
|
||||
std::vector<Rect> eyes;
|
||||
|
||||
//-- In each face, detect eyes
|
||||
eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
|
||||
eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CASCADE_SCALE_IMAGE, Size(30, 30) );
|
||||
|
||||
for( int j = 0; j < eyes.size(); j++ )
|
||||
for( size_t j = 0; j < eyes.size(); j++ )
|
||||
{
|
||||
Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
|
||||
Point eye_center( faces[i].x + eyes[j].x + eyes[j].width/2, faces[i].y + eyes[j].y + eyes[j].height/2 );
|
||||
int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
|
||||
circle( frame, center, radius, Scalar( 255, 0, 0 ), 3, 8, 0 );
|
||||
circle( frame, eye_center, radius, Scalar( 255, 0, 0 ), 3, 8, 0 );
|
||||
}
|
||||
}
|
||||
//-- Show what you got
|
||||
|
@@ -6,6 +6,9 @@
|
||||
#include "opencv2/objdetect/objdetect.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/core/utility.hpp"
|
||||
|
||||
#include "opencv2/highgui/highgui_c.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
@@ -17,8 +20,8 @@ using namespace cv;
|
||||
void detectAndDisplay( Mat frame );
|
||||
|
||||
/** Global variables */
|
||||
String face_cascade_name = "lbpcascade_frontalface.xml";
|
||||
String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
|
||||
string face_cascade_name = "lbpcascade_frontalface.xml";
|
||||
string eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
|
||||
CascadeClassifier face_cascade;
|
||||
CascadeClassifier eyes_cascade;
|
||||
string window_name = "Capture - Face detection";
|
||||
@@ -28,7 +31,7 @@ RNG rng(12345);
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int argc, const char** argv )
|
||||
int main( void )
|
||||
{
|
||||
CvCapture* capture;
|
||||
Mat frame;
|
||||
@@ -41,9 +44,9 @@ int main( int argc, const char** argv )
|
||||
capture = cvCaptureFromCAM( -1 );
|
||||
if( capture )
|
||||
{
|
||||
while( true )
|
||||
for(;;)
|
||||
{
|
||||
frame = cvQueryFrame( capture );
|
||||
frame = cv::cvarrToMat(cvQueryFrame( capture ));
|
||||
|
||||
//-- 3. Apply the classifier to the frame
|
||||
if( !frame.empty() )
|
||||
@@ -67,30 +70,30 @@ void detectAndDisplay( Mat frame )
|
||||
std::vector<Rect> faces;
|
||||
Mat frame_gray;
|
||||
|
||||
cvtColor( frame, frame_gray, CV_BGR2GRAY );
|
||||
cvtColor( frame, frame_gray, COLOR_BGR2GRAY );
|
||||
equalizeHist( frame_gray, frame_gray );
|
||||
|
||||
//-- Detect faces
|
||||
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0, Size(80, 80) );
|
||||
|
||||
for( int i = 0; i < faces.size(); i++ )
|
||||
for( size_t i = 0; i < faces.size(); i++ )
|
||||
{
|
||||
Mat faceROI = frame_gray( faces[i] );
|
||||
std::vector<Rect> eyes;
|
||||
|
||||
//-- In each face, detect eyes
|
||||
eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
|
||||
eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CASCADE_SCALE_IMAGE, Size(30, 30) );
|
||||
if( eyes.size() == 2)
|
||||
{
|
||||
//-- Draw the face
|
||||
Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
|
||||
ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 0 ), 2, 8, 0 );
|
||||
Point center( faces[i].x + faces[i].width/2, faces[i].y + faces[i].height/2 );
|
||||
ellipse( frame, center, Size( faces[i].width/2, faces[i].height/2), 0, 0, 360, Scalar( 255, 0, 0 ), 2, 8, 0 );
|
||||
|
||||
for( int j = 0; j < eyes.size(); j++ )
|
||||
for( size_t j = 0; j < eyes.size(); j++ )
|
||||
{ //-- Draw the eyes
|
||||
Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
|
||||
Point eye_center( faces[i].x + eyes[j].x + eyes[j].width/2, faces[i].y + eyes[j].y + eyes[j].height/2 );
|
||||
int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
|
||||
circle( frame, center, radius, Scalar( 255, 0, 255 ), 3, 8, 0 );
|
||||
circle( frame, eye_center, radius, Scalar( 255, 0, 255 ), 3, 8, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user