Subversion Repositories OpenCV2-Cookbook

Compare Revisions

Last modification

Ignore whitespace Rev 2 → Rev 3

/trunk/Chapter 09/CameraCalibrator.h
0,0 → 1,62
/*------------------------------------------------------------------------------------------*\
This file contains material supporting chapter 9 of the cookbook:
Computer Vision Programming using the OpenCV Library.
by Robert Laganiere, Packt Publishing, 2011.
 
This program is free software; permission is hereby granted to use, copy, modify,
and distribute this source code, or portions thereof, for any purpose, without fee,
subject to the restriction that the copyright notice may not be removed
or altered from any source or altered source distribution.
The software is released on an as-is basis and without any warranties of any kind.
In particular, the software is not guaranteed to be fault-tolerant or free from failure.
The author disclaims all warranties with regard to this software, any use,
and any consequent failure, is purely the responsibility of the user.
Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
\*------------------------------------------------------------------------------------------*/
 
#ifndef CAMERACALIBRATOR_H
#define CAMERACALIBRATOR_H
 
#include <vector>
#include <iostream>
 
#include <opencv2/core/core.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <opencv2/highgui/highgui.hpp>
 
class CameraCalibrator {
 
// input points
std::vector<std::vector<cv::Point3f>> objectPoints;
std::vector<std::vector<cv::Point2f>> imagePoints;
// output Matrices
cv::Mat cameraMatrix;
cv::Mat distCoeffs;
// flag to specify how calibration is done
int flag;
// used in image undistortion
cv::Mat map1,map2;
bool mustInitUndistort;
 
public:
CameraCalibrator() : flag(0), mustInitUndistort(true) {};
 
// Open the chessboard images and extract corner points
int addChessboardPoints(const std::vector<std::string>& filelist, cv::Size & boardSize);
// Add scene points and corresponding image points
void addPoints(const std::vector<cv::Point2f>& imageCorners, const std::vector<cv::Point3f>& objectCorners);
// Calibrate the camera
double calibrate(cv::Size &imageSize);
// Set the calibration flag
void setCalibrationFlag(bool radial8CoeffEnabled=false, bool tangentialParamEnabled=false);
// Remove distortion in an image (after calibration)
cv::Mat CameraCalibrator::remap(const cv::Mat &image);
 
// Getters
cv::Mat getCameraMatrix() { return cameraMatrix; }
cv::Mat getDistCoeffs() { return distCoeffs; }
};
 
#endif // CAMERACALIBRATOR_H
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 09/estimateF.cpp
===================================================================
--- Chapter 09/estimateF.cpp (nonexistent)
+++ Chapter 09/estimateF.cpp (revision 3)
@@ -0,0 +1,331 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 9 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <vector>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/features2d/features2d.hpp>
+#include <opencv2/calib3d/calib3d.hpp>
+
+int main()
+{
+ // Read input images
+ cv::Mat image1= cv::imread("../church01.jpg",0);
+ cv::Mat image2= cv::imread("../church03.jpg",0);
+ if (!image1.data || !image2.data)
+ return 0;
+
+ // Display the images
+ cv::namedWindow("Right Image");
+ cv::imshow("Right Image",image1);
+ cv::namedWindow("Left Image");
+ cv::imshow("Left Image",image2);
+
+ // vector of keypoints
+ std::vector<cv::KeyPoint> keypoints1;
+ std::vector<cv::KeyPoint> keypoints2;
+
+ // Construction of the SURF feature detector
+ cv::SurfFeatureDetector surf(3000);
+
+ // Detection of the SURF features
+ surf.detect(image1,keypoints1);
+ surf.detect(image2,keypoints2);
+
+ std::cout << "Number of SURF points (1): " << keypoints1.size() << std::endl;
+ std::cout << "Number of SURF points (2): " << keypoints2.size() << std::endl;
+
+ // Draw the kepoints
+ cv::Mat imageKP;
+ cv::drawKeypoints(image1,keypoints1,imageKP,cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
+ cv::namedWindow("Right SURF Features");
+ cv::imshow("Right SURF Features",imageKP);
+ cv::drawKeypoints(image2,keypoints2,imageKP,cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
+ cv::namedWindow("Left SURF Features");
+ cv::imshow("Left SURF Features",imageKP);
+
+ // Construction of the SURF descriptor extractor
+ cv::SurfDescriptorExtractor surfDesc;
+
+ // Extraction of the SURF descriptors
+ cv::Mat descriptors1, descriptors2;
+ surfDesc.compute(image1,keypoints1,descriptors1);
+ surfDesc.compute(image2,keypoints2,descriptors2);
+
+ std::cout << "descriptor matrix size: " << descriptors1.rows << " by " << descriptors1.cols << std::endl;
+
+ // Construction of the matcher
+ cv::BruteForceMatcher<cv::L2<float>> matcher;
+
+ // Match the two image descriptors
+ std::vector<cv::DMatch> matches;
+ matcher.match(descriptors1,descriptors2, matches);
+
+ std::cout << "Number of matched points: " << matches.size() << std::endl;
+
+ // Select few Matches
+ std::vector<cv::DMatch> selMatches;
+ /*
+ keypoints1.push_back(cv::KeyPoint(342.,615.,2));
+ keypoints2.push_back(cv::KeyPoint(410.,600.,2));
+ selMatches.push_back(cv::DMatch(keypoints1.size()-1,keypoints2.size()-1,0)); // street light bulb
+ selMatches.push_back(matches[6]); // right tower
+ selMatches.push_back(matches[60]); // left bottom window
+ selMatches.push_back(matches[139]);
+ selMatches.push_back(matches[141]); // middle window
+ selMatches.push_back(matches[213]);
+ selMatches.push_back(matches[273]);
+
+ int kk=0;
+ while (kk<matches.size()) {
+ std::cout<<kk<<std::endl;
+ selMatches.push_back(matches[kk++]);
+ selMatches.pop_back();
+ cv::waitKey();
+ }
+ */
+
+ /* between church01 and church03 */
+ selMatches.push_back(matches[14]);
+ selMatches.push_back(matches[16]);
+ selMatches.push_back(matches[141]);
+ selMatches.push_back(matches[146]);
+ selMatches.push_back(matches[235]);
+ selMatches.push_back(matches[238]);
+ selMatches.push_back(matches[274]);
+
+ // Draw the selected matches
+ cv::Mat imageMatches;
+ cv::drawMatches(image1,keypoints1, // 1st image and its keypoints
+ image2,keypoints2, // 2nd image and its keypoints
+// selMatches, // the matches
+ matches, // the matches
+ imageMatches, // the image produced
+ cv::Scalar(255,255,255)); // color of the lines
+ cv::namedWindow("Matches");
+ cv::imshow("Matches",imageMatches);
+
+ // Convert 1 vector of keypoints into
+ // 2 vectors of Point2f
+ std::vector<int> pointIndexes1;
+ std::vector<int> pointIndexes2;
+ for (std::vector<cv::DMatch>::const_iterator it= selMatches.begin();
+ it!= selMatches.end(); ++it) {
+
+ // Get the indexes of the selected matched keypoints
+ pointIndexes1.push_back(it->queryIdx);
+ pointIndexes2.push_back(it->trainIdx);
+ }
+
+ // Convert keypoints into Point2f
+ std::vector<cv::Point2f> selPoints1, selPoints2;
+ cv::KeyPoint::convert(keypoints1,selPoints1,pointIndexes1);
+ cv::KeyPoint::convert(keypoints2,selPoints2,pointIndexes2);
+
+ // check by drawing the points
+ std::vector<cv::Point2f>::const_iterator it= selPoints1.begin();
+ while (it!=selPoints1.end()) {
+
+ // draw a circle at each corner location
+ cv::circle(image1,*it,3,cv::Scalar(255,255,255),2);
+ ++it;
+ }
+
+ it= selPoints2.begin();
+ while (it!=selPoints2.end()) {
+
+ // draw a circle at each corner location
+ cv::circle(image2,*it,3,cv::Scalar(255,255,255),2);
+ ++it;
+ }
+
+ // Compute F matrix from 7 matches
+ cv::Mat fundemental= cv::findFundamentalMat(
+ cv::Mat(selPoints1), // points in first image
+ cv::Mat(selPoints2), // points in second image
+ CV_FM_7POINT); // 7-point method
+
+ std::cout << "F-Matrix size= " << fundemental.rows << "," << fundemental.cols << std::endl;
+
+ // draw the left points corresponding epipolar lines in right image
+ std::vector<cv::Vec3f> lines1;
+ cv::computeCorrespondEpilines(
+ cv::Mat(selPoints1), // image points
+ 1, // in image 1 (can also be 2)
+ fundemental, // F matrix
+ lines1); // vector of epipolar lines
+
+ // for all epipolar lines
+ for (vector<cv::Vec3f>::const_iterator it= lines1.begin();
+ it!=lines1.end(); ++it) {
+
+ // draw the epipolar line between first and last column
+ cv::line(image2,cv::Point(0,-(*it)[2]/(*it)[1]),
+ cv::Point(image2.cols,-((*it)[2]+(*it)[0]*image2.cols)/(*it)[1]),
+ cv::Scalar(255,255,255));
+ }
+
+ // draw the left points corresponding epipolar lines in left image
+ std::vector<cv::Vec3f> lines2;
+ cv::computeCorrespondEpilines(cv::Mat(selPoints2),2,fundemental,lines2);
+ for (vector<cv::Vec3f>::const_iterator it= lines2.begin();
+ it!=lines2.end(); ++it) {
+
+ // draw the epipolar line between first and last column
+ cv::line(image1,cv::Point(0,-(*it)[2]/(*it)[1]),
+ cv::Point(image1.cols,-((*it)[2]+(*it)[0]*image1.cols)/(*it)[1]),
+ cv::Scalar(255,255,255));
+ }
+
+ // Display the images with points and epipolar lines
+ cv::namedWindow("Right Image Epilines");
+ cv::imshow("Right Image Epilines",image1);
+ cv::namedWindow("Left Image Epilines");
+ cv::imshow("Left Image Epilines",image2);
+
+ /*
+ std::nth_element(matches.begin(), // initial position
+ matches.begin()+matches.size()/2, // 50%
+ matches.end()); // end position
+ // remove all elements after the
+ matches.erase(matches.begin()+matches.size()/2, matches.end());
+*/
+ // Convert keypoints into Point2f
+ std::vector<cv::Point2f> points1, points2;
+ for (std::vector<cv::DMatch>::const_iterator it= matches.begin();
+ it!= matches.end(); ++it) {
+
+ // Get the position of left keypoints
+ float x= keypoints1[it->queryIdx].pt.x;
+ float y= keypoints1[it->queryIdx].pt.y;
+ points1.push_back(cv::Point2f(x,y));
+ // Get the position of right keypoints
+ x= keypoints2[it->trainIdx].pt.x;
+ y= keypoints2[it->trainIdx].pt.y;
+ points2.push_back(cv::Point2f(x,y));
+ }
+
+ std::cout << points1.size() << " " << points2.size() << std::endl;
+
+ // Compute F matrix using RANSAC
+ std::vector<uchar> inliers(points1.size(),0);
+ fundemental= cv::findFundamentalMat(
+ cv::Mat(points1),cv::Mat(points2), // matching points
+ inliers, // match status (inlier ou outlier)
+ CV_FM_RANSAC, // RANSAC method
+ 1, // distance to epipolar line
+ 0.98); // confidence probability
+
+ // Read input images
+ image1= cv::imread("../church01.jpg",0);
+ image2= cv::imread("../church03.jpg",0);
+
+ // Draw the epipolar line of few points
+ cv::computeCorrespondEpilines(cv::Mat(selPoints1),1,fundemental,lines1);
+ for (vector<cv::Vec3f>::const_iterator it= lines1.begin();
+ it!=lines1.end(); ++it) {
+
+ cv::line(image2,cv::Point(0,-(*it)[2]/(*it)[1]),
+ cv::Point(image2.cols,-((*it)[2]+(*it)[0]*image2.cols)/(*it)[1]),
+ cv::Scalar(255,255,255));
+ }
+
+ cv::computeCorrespondEpilines(cv::Mat(selPoints2),2,fundemental,lines2);
+ for (vector<cv::Vec3f>::const_iterator it= lines2.begin();
+ it!=lines2.end(); ++it) {
+
+ cv::line(image1,cv::Point(0,-(*it)[2]/(*it)[1]),
+ cv::Point(image1.cols,-((*it)[2]+(*it)[0]*image1.cols)/(*it)[1]),
+ cv::Scalar(255,255,255));
+ }
+
+ // Draw the inlier points
+ std::vector<cv::Point2f> points1In, points2In;
+ std::vector<cv::Point2f>::const_iterator itPts= points1.begin();
+ std::vector<uchar>::const_iterator itIn= inliers.begin();
+ while (itPts!=points1.end()) {
+
+ // draw a circle at each inlier location
+ if (*itIn) {
+ cv::circle(image1,*itPts,3,cv::Scalar(255,255,255),2);
+ points1In.push_back(*itPts);
+ }
+ ++itPts;
+ ++itIn;
+ }
+
+ itPts= points2.begin();
+ itIn= inliers.begin();
+ while (itPts!=points2.end()) {
+
+ // draw a circle at each inlier location
+ if (*itIn) {
+ cv::circle(image2,*itPts,3,cv::Scalar(255,255,255),2);
+ points2In.push_back(*itPts);
+ }
+ ++itPts;
+ ++itIn;
+ }
+
+ // Display the images with points
+ cv::namedWindow("Right Image Epilines (RANSAC)");
+ cv::imshow("Right Image Epilines (RANSAC)",image1);
+ cv::namedWindow("Left Image Epilines (RANSAC)");
+ cv::imshow("Left Image Epilines (RANSAC)",image2);
+
+ cv::findHomography(cv::Mat(points1In),cv::Mat(points2In),inliers,CV_RANSAC,1.);
+
+ // Read input images
+ image1= cv::imread("../church01.jpg",0);
+ image2= cv::imread("../church03.jpg",0);
+
+ // Draw the inlier points
+ itPts= points1In.begin();
+ itIn= inliers.begin();
+ while (itPts!=points1In.end()) {
+
+ // draw a circle at each inlier location
+ if (*itIn)
+ cv::circle(image1,*itPts,3,cv::Scalar(255,255,255),2);
+
+ ++itPts;
+ ++itIn;
+ }
+
+ itPts= points2In.begin();
+ itIn= inliers.begin();
+ while (itPts!=points2In.end()) {
+
+ // draw a circle at each inlier location
+ if (*itIn)
+ cv::circle(image2,*itPts,3,cv::Scalar(255,255,255),2);
+
+ ++itPts;
+ ++itIn;
+ }
+
+ // Display the images with points
+ cv::namedWindow("Right Image Homography (RANSAC)");
+ cv::imshow("Right Image Homography (RANSAC)",image1);
+ cv::namedWindow("Left Image Homography (RANSAC)");
+ cv::imshow("Left Image Homography (RANSAC)",image2);
+
+ cv::waitKey();
+ return 0;
+ }
\ No newline at end of file
/Chapter 09/estimateF.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 09/estimateH.cpp
===================================================================
--- Chapter 09/estimateH.cpp (nonexistent)
+++ Chapter 09/estimateH.cpp (revision 3)
@@ -0,0 +1,137 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 9 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <vector>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/features2d/features2d.hpp>
+#include <opencv2/calib3d/calib3d.hpp>
+#include "matcher.h"
+
+int main()
+{
+ // Read input images
+ cv::Mat image1= cv::imread("../parliament1.bmp",0);
+ cv::Mat image2= cv::imread("../parliament2.bmp",0);
+ if (!image1.data || !image2.data)
+ return 0;
+
+ // Display the images
+ cv::namedWindow("Image 1");
+ cv::imshow("Image 1",image1);
+ cv::namedWindow("Image 2");
+ cv::imshow("Image 2",image2);
+
+ // Prepare the matcher
+ RobustMatcher rmatcher;
+ rmatcher.setConfidenceLevel(0.98);
+ rmatcher.setMinDistanceToEpipolar(1.0);
+ rmatcher.setRatio(0.65f);
+ cv::Ptr<cv::FeatureDetector> pfd= new cv::SurfFeatureDetector(10);
+ rmatcher.setFeatureDetector(pfd);
+
+ // Match the two images
+ std::vector<cv::DMatch> matches;
+ std::vector<cv::KeyPoint> keypoints1, keypoints2;
+ cv::Mat fundemental= rmatcher.match(image1,image2,matches, keypoints1, keypoints2);
+
+ // draw the matches
+ cv::Mat imageMatches;
+ cv::drawMatches(image1,keypoints1, // 1st image and its keypoints
+ image2,keypoints2, // 2nd image and its keypoints
+ matches, // the matches
+ imageMatches, // the image produced
+ cv::Scalar(255,255,255)); // color of the lines
+ cv::namedWindow("Matches");
+ cv::imshow("Matches",imageMatches);
+
+ // Convert keypoints into Point2f
+ std::vector<cv::Point2f> points1, points2;
+ for (std::vector<cv::DMatch>::const_iterator it= matches.begin();
+ it!= matches.end(); ++it) {
+
+ // Get the position of left keypoints
+ float x= keypoints1[it->queryIdx].pt.x;
+ float y= keypoints1[it->queryIdx].pt.y;
+ points1.push_back(cv::Point2f(x,y));
+ // Get the position of right keypoints
+ x= keypoints2[it->trainIdx].pt.x;
+ y= keypoints2[it->trainIdx].pt.y;
+ points2.push_back(cv::Point2f(x,y));
+ }
+
+ std::cout << points1.size() << " " << points2.size() << std::endl;
+
+ // Find the homography between image 1 and image 2
+ std::vector<uchar> inliers(points1.size(),0);
+ cv::Mat homography= cv::findHomography(
+ cv::Mat(points1),cv::Mat(points2), // corresponding points
+ inliers, // outputed inliers matches
+ CV_RANSAC, // RANSAC method
+ 1.); // max distance to reprojection point
+
+ // Draw the inlier points
+ std::vector<cv::Point2f>::const_iterator itPts= points1.begin();
+ std::vector<uchar>::const_iterator itIn= inliers.begin();
+ while (itPts!=points1.end()) {
+
+ // draw a circle at each inlier location
+ if (*itIn)
+ cv::circle(image1,*itPts,3,cv::Scalar(255,255,255),2);
+
+ ++itPts;
+ ++itIn;
+ }
+
+ itPts= points2.begin();
+ itIn= inliers.begin();
+ while (itPts!=points2.end()) {
+
+ // draw a circle at each inlier location
+ if (*itIn)
+ cv::circle(image2,*itPts,3,cv::Scalar(255,255,255),2);
+
+ ++itPts;
+ ++itIn;
+ }
+
+ // Display the images with points
+ cv::namedWindow("Image 1 Homography Points");
+ cv::imshow("Image 1 Homography Points",image1);
+ cv::namedWindow("Image 2 Homography Points");
+ cv::imshow("Image 2 Homography Points",image2);
+
+ // Warp image 1 to image 2
+ cv::Mat result;
+ cv::warpPerspective(image1, // input image
+ result, // output image
+ homography, // homography
+ cv::Size(2*image1.cols,image1.rows)); // size of output image
+
+ // Copy image 1 on the first half of full image
+ cv::Mat half(result,cv::Rect(0,0,image2.cols,image2.rows));
+ image2.copyTo(half);
+
+ // Display the warp image
+ cv::namedWindow("After warping");
+ cv::imshow("After warping",result);
+
+ cv::waitKey();
+ return 0;
+}
\ No newline at end of file
/Chapter 09/estimateH.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 09/calibrate.cpp
===================================================================
--- Chapter 09/calibrate.cpp (nonexistent)
+++ Chapter 09/calibrate.cpp (revision 3)
@@ -0,0 +1,76 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 9 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <iomanip>
+#include <vector>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/features2d/features2d.hpp>
+
+#include "CameraCalibrator.h"
+
+int main()
+{
+
+ cv::namedWindow("Image");
+ cv::Mat image;
+ std::vector<std::string> filelist;
+
+ // generate list of chessboard image filename
+ for (int i=1; i<=20; i++) {
+
+ std::stringstream str;
+ str << "../chessboards/chessboard" << std::setw(2) << std::setfill('0') << i << ".jpg";
+ std::cout << str.str() << std::endl;
+
+ filelist.push_back(str.str());
+ image= cv::imread(str.str(),0);
+ cv::imshow("Image",image);
+
+ cv::waitKey(100);
+ }
+
+ // Create calibrator object
+ CameraCalibrator cameraCalibrator;
+ // add the corners from the chessboard
+ cv::Size boardSize(6,4);
+ cameraCalibrator.addChessboardPoints(
+ filelist, // filenames of chessboard image
+ boardSize); // size of chessboard
+ // calibrate the camera
+ // cameraCalibrator.setCalibrationFlag(true,true);
+ cameraCalibrator.calibrate(image.size());
+
+ // Image Undistortion
+ image = cv::imread(filelist[6]);
+ cv::Mat uImage= cameraCalibrator.remap(image);
+
+ // display camera matrix
+ cv::Mat cameraMatrix= cameraCalibrator.getCameraMatrix();
+ std::cout << " Camera intrinsic: " << cameraMatrix.rows << "x" << cameraMatrix.cols << std::endl;
+ std::cout << cameraMatrix.at<double>(0,0) << " " << cameraMatrix.at<double>(0,1) << " " << cameraMatrix.at<double>(0,2) << std::endl;
+ std::cout << cameraMatrix.at<double>(1,0) << " " << cameraMatrix.at<double>(1,1) << " " << cameraMatrix.at<double>(1,2) << std::endl;
+ std::cout << cameraMatrix.at<double>(2,0) << " " << cameraMatrix.at<double>(2,1) << " " << cameraMatrix.at<double>(2,2) << std::endl;
+
+ imshow("Original Image", image);
+ imshow("Undistorted Image", uImage);
+
+ cv::waitKey();
+ return 0;
+}
\ No newline at end of file
/Chapter 09/calibrate.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 09/matcher.h
===================================================================
--- Chapter 09/matcher.h (nonexistent)
+++ Chapter 09/matcher.h (revision 3)
@@ -0,0 +1,288 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 9 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined MATCHER
+#define MATCHER
+
+#include <vector>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/features2d/features2d.hpp>
+
+class RobustMatcher {
+
+ private:
+
+ // pointer to the feature point detector object
+ cv::Ptr<cv::FeatureDetector> detector;
+ // pointer to the feature descriptor extractor object
+ cv::Ptr<cv::DescriptorExtractor> extractor;
+ float ratio; // max ratio between 1st and 2nd NN
+ bool refineF; // if true will refine the F matrix
+ double distance; // min distance to epipolar
+ double confidence; // confidence level (probability)
+
+ public:
+
+ RobustMatcher() : ratio(0.65f), refineF(true), confidence(0.99), distance(3.0) {
+
+ // SURF is the default feature
+ detector= new cv::SurfFeatureDetector();
+ extractor= new cv::SurfDescriptorExtractor();
+ }
+
+ // Set the feature detector
+ void setFeatureDetector(cv::Ptr<cv::FeatureDetector>& detect) {
+
+ detector= detect;
+ }
+
+ // Set descriptor extractor
+ void setDescriptorExtractor(cv::Ptr<cv::DescriptorExtractor>& desc) {
+
+ extractor= desc;
+ }
+
+ // Set the minimum distance to epipolar in RANSAC
+ void setMinDistanceToEpipolar(double d) {
+
+ distance= d;
+ }
+
+ // Set confidence level in RANSAC
+ void setConfidenceLevel(double c) {
+
+ confidence= c;
+ }
+
+ // Set the NN ratio
+ void setRatio(float r) {
+
+ ratio= r;
+ }
+
+ // if you want the F matrix to be recalculated
+ void refineFundamental(bool flag) {
+
+ refineF= flag;
+ }
+
+ // Clear matches for which NN ratio is > than threshold
+ // return the number of removed points
+ // (corresponding entries being cleared, i.e. size will be 0)
+ int ratioTest(std::vector<std::vector<cv::DMatch>>& matches) {
+
+ int removed=0;
+
+ // for all matches
+ for (std::vector<std::vector<cv::DMatch>>::iterator matchIterator= matches.begin();
+ matchIterator!= matches.end(); ++matchIterator) {
+
+ // if 2 NN has been identified
+ if (matchIterator->size() > 1) {
+
+ // check distance ratio
+ if ((*matchIterator)[0].distance/(*matchIterator)[1].distance > ratio) {
+
+ matchIterator->clear(); // remove match
+ removed++;
+ }
+
+ } else { // does not have 2 neighbours
+
+ matchIterator->clear(); // remove match
+ removed++;
+ }
+ }
+
+ return removed;
+ }
+
+ // Insert symmetrical matches in symMatches vector
+ void symmetryTest(const std::vector<std::vector<cv::DMatch>>& matches1,
+ const std::vector<std::vector<cv::DMatch>>& matches2,
+ std::vector<cv::DMatch>& symMatches) {
+
+ // for all matches image 1 -> image 2
+ for (std::vector<std::vector<cv::DMatch>>::const_iterator matchIterator1= matches1.begin();
+ matchIterator1!= matches1.end(); ++matchIterator1) {
+
+ if (matchIterator1->size() < 2) // ignore deleted matches
+ continue;
+
+ // for all matches image 2 -> image 1
+ for (std::vector<std::vector<cv::DMatch>>::const_iterator matchIterator2= matches2.begin();
+ matchIterator2!= matches2.end(); ++matchIterator2) {
+
+ if (matchIterator2->size() < 2) // ignore deleted matches
+ continue;
+
+ // Match symmetry test
+ if ((*matchIterator1)[0].queryIdx == (*matchIterator2)[0].trainIdx &&
+ (*matchIterator2)[0].queryIdx == (*matchIterator1)[0].trainIdx) {
+
+ // add symmetrical match
+ symMatches.push_back(cv::DMatch((*matchIterator1)[0].queryIdx,
+ (*matchIterator1)[0].trainIdx,
+ (*matchIterator1)[0].distance));
+ break; // next match in image 1 -> image 2
+ }
+ }
+ }
+ }
+
+ // Identify good matches using RANSAC
+ // Return fundemental matrix
+ cv::Mat ransacTest(const std::vector<cv::DMatch>& matches,
+ const std::vector<cv::KeyPoint>& keypoints1,
+ const std::vector<cv::KeyPoint>& keypoints2,
+ std::vector<cv::DMatch>& outMatches) {
+
+ // Convert keypoints into Point2f
+ std::vector<cv::Point2f> points1, points2;
+ for (std::vector<cv::DMatch>::const_iterator it= matches.begin();
+ it!= matches.end(); ++it) {
+
+ // Get the position of left keypoints
+ float x= keypoints1[it->queryIdx].pt.x;
+ float y= keypoints1[it->queryIdx].pt.y;
+ points1.push_back(cv::Point2f(x,y));
+ // Get the position of right keypoints
+ x= keypoints2[it->trainIdx].pt.x;
+ y= keypoints2[it->trainIdx].pt.y;
+ points2.push_back(cv::Point2f(x,y));
+ }
+
+ // Compute F matrix using RANSAC
+ std::vector<uchar> inliers(points1.size(),0);
+ cv::Mat fundemental= cv::findFundamentalMat(
+ cv::Mat(points1),cv::Mat(points2), // matching points
+ inliers, // match status (inlier ou outlier)
+ CV_FM_RANSAC, // RANSAC method
+ distance, // distance to epipolar line
+ confidence); // confidence probability
+
+ // extract the surviving (inliers) matches
+ std::vector<uchar>::const_iterator itIn= inliers.begin();
+ std::vector<cv::DMatch>::const_iterator itM= matches.begin();
+ // for all matches
+ for ( ;itIn!= inliers.end(); ++itIn, ++itM) {
+
+ if (*itIn) { // it is a valid match
+
+ outMatches.push_back(*itM);
+ }
+ }
+
+ std::cout << "Number of matched points (after cleaning): " << outMatches.size() << std::endl;
+
+ if (refineF) {
+ // The F matrix will be recomputed with all accepted matches
+
+ // Convert keypoints into Point2f for final F computation
+ points1.clear();
+ points2.clear();
+
+ for (std::vector<cv::DMatch>::const_iterator it= outMatches.begin();
+ it!= outMatches.end(); ++it) {
+
+ // Get the position of left keypoints
+ float x= keypoints1[it->queryIdx].pt.x;
+ float y= keypoints1[it->queryIdx].pt.y;
+ points1.push_back(cv::Point2f(x,y));
+ // Get the position of right keypoints
+ x= keypoints2[it->trainIdx].pt.x;
+ y= keypoints2[it->trainIdx].pt.y;
+ points2.push_back(cv::Point2f(x,y));
+ }
+
+ // Compute 8-point F from all accepted matches
+ fundemental= cv::findFundamentalMat(
+ cv::Mat(points1),cv::Mat(points2), // matching points
+ CV_FM_8POINT); // 8-point method
+ }
+
+ return fundemental;
+ }
+
+ // Match feature points using symmetry test and RANSAC
+ // returns fundemental matrix
+ cv::Mat match(cv::Mat& image1, cv::Mat& image2, // input images
+ std::vector<cv::DMatch>& matches, // output matches and keypoints
+ std::vector<cv::KeyPoint>& keypoints1, std::vector<cv::KeyPoint>& keypoints2) {
+
+ // 1a. Detection of the SURF features
+ detector->detect(image1,keypoints1);
+ detector->detect(image2,keypoints2);
+
+ std::cout << "Number of SURF points (1): " << keypoints1.size() << std::endl;
+ std::cout << "Number of SURF points (2): " << keypoints2.size() << std::endl;
+
+ // 1b. Extraction of the SURF descriptors
+ cv::Mat descriptors1, descriptors2;
+ extractor->compute(image1,keypoints1,descriptors1);
+ extractor->compute(image2,keypoints2,descriptors2);
+
+ std::cout << "descriptor matrix size: " << descriptors1.rows << " by " << descriptors1.cols << std::endl;
+
+ // 2. Match the two image descriptors
+
+ // Construction of the matcher
+ cv::BruteForceMatcher<cv::L2<float>> matcher;
+
+ // from image 1 to image 2
+ // based on k nearest neighbours (with k=2)
+ std::vector<std::vector<cv::DMatch>> matches1;
+ matcher.knnMatch(descriptors1,descriptors2,
+ matches1, // vector of matches (up to 2 per entry)
+ 2); // return 2 nearest neighbours
+
+ // from image 2 to image 1
+ // based on k nearest neighbours (with k=2)
+ std::vector<std::vector<cv::DMatch>> matches2;
+ matcher.knnMatch(descriptors2,descriptors1,
+ matches2, // vector of matches (up to 2 per entry)
+ 2); // return 2 nearest neighbours
+
+ std::cout << "Number of matched points 1->2: " << matches1.size() << std::endl;
+ std::cout << "Number of matched points 2->1: " << matches2.size() << std::endl;
+
+ // 3. Remove matches for which NN ratio is > than threshold
+
+ // clean image 1 -> image 2 matches
+ int removed= ratioTest(matches1);
+ std::cout << "Number of matched points 1->2 (ratio test) : " << matches1.size()-removed << std::endl;
+ // clean image 2 -> image 1 matches
+ removed= ratioTest(matches2);
+ std::cout << "Number of matched points 1->2 (ratio test) : " << matches2.size()-removed << std::endl;
+
+ // 4. Remove non-symmetrical matches
+ std::vector<cv::DMatch> symMatches;
+ symmetryTest(matches1,matches2,symMatches);
+
+ std::cout << "Number of matched points (symmetry test): " << symMatches.size() << std::endl;
+
+ // 5. Validate matches using RANSAC
+ cv::Mat fundemental= ransacTest(symMatches, keypoints1, keypoints2, matches);
+
+ // return the found fundemental matrix
+ return fundemental;
+ }
+};
+
+#endif
/Chapter 09/matcher.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 09/robustmatching.cpp
===================================================================
--- Chapter 09/robustmatching.cpp (nonexistent)
+++ Chapter 09/robustmatching.cpp (revision 3)
@@ -0,0 +1,113 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 9 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <vector>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/features2d/features2d.hpp>
+#include <opencv2/calib3d/calib3d.hpp>
+#include "matcher.h"
+
+int main()
+{
+ // Read input images
+ cv::Mat image1= cv::imread("../canal1.jpg",0);
+ cv::Mat image2= cv::imread("../canal2.jpg",0);
+ if (!image1.data || !image2.data)
+ return 0;
+
+ // Display the images
+ cv::namedWindow("Right Image");
+ cv::imshow("Right Image",image1);
+ cv::namedWindow("Left Image");
+ cv::imshow("Left Image",image2);
+
+ // Prepare the matcher
+ RobustMatcher rmatcher;
+ rmatcher.setConfidenceLevel(0.98);
+ rmatcher.setMinDistanceToEpipolar(1.0);
+ rmatcher.setRatio(0.65f);
+ cv::Ptr<cv::FeatureDetector> pfd= new cv::SurfFeatureDetector(10);
+ rmatcher.setFeatureDetector(pfd);
+
+ // Match the two images
+ std::vector<cv::DMatch> matches;
+ std::vector<cv::KeyPoint> keypoints1, keypoints2;
+ cv::Mat fundemental= rmatcher.match(image1,image2,matches, keypoints1, keypoints2);
+
+ // draw the matches
+ cv::Mat imageMatches;
+ cv::drawMatches(image1,keypoints1, // 1st image and its keypoints
+ image2,keypoints2, // 2nd image and its keypoints
+ matches, // the matches
+ imageMatches, // the image produced
+ cv::Scalar(255,255,255)); // color of the lines
+ cv::namedWindow("Matches");
+ cv::imshow("Matches",imageMatches);
+
+ // Convert keypoints into Point2f
+ std::vector<cv::Point2f> points1, points2;
+
+ for (std::vector<cv::DMatch>::const_iterator it= matches.begin();
+ it!= matches.end(); ++it) {
+
+ // Get the position of left keypoints
+ float x= keypoints1[it->queryIdx].pt.x;
+ float y= keypoints1[it->queryIdx].pt.y;
+ points1.push_back(cv::Point2f(x,y));
+ cv::circle(image1,cv::Point(x,y),3,cv::Scalar(255,255,255),3);
+ // Get the position of right keypoints
+ x= keypoints2[it->trainIdx].pt.x;
+ y= keypoints2[it->trainIdx].pt.y;
+ cv::circle(image2,cv::Point(x,y),3,cv::Scalar(255,255,255),3);
+ points2.push_back(cv::Point2f(x,y));
+ }
+
+ // Draw the epipolar lines
+ std::vector<cv::Vec3f> lines1;
+ cv::computeCorrespondEpilines(cv::Mat(points1),1,fundemental,lines1);
+
+ for (vector<cv::Vec3f>::const_iterator it= lines1.begin();
+ it!=lines1.end(); ++it) {
+
+ cv::line(image2,cv::Point(0,-(*it)[2]/(*it)[1]),
+ cv::Point(image2.cols,-((*it)[2]+(*it)[0]*image2.cols)/(*it)[1]),
+ cv::Scalar(255,255,255));
+ }
+
+ std::vector<cv::Vec3f> lines2;
+ cv::computeCorrespondEpilines(cv::Mat(points2),2,fundemental,lines2);
+
+ for (vector<cv::Vec3f>::const_iterator it= lines2.begin();
+ it!=lines2.end(); ++it) {
+
+ cv::line(image1,cv::Point(0,-(*it)[2]/(*it)[1]),
+ cv::Point(image1.cols,-((*it)[2]+(*it)[0]*image1.cols)/(*it)[1]),
+ cv::Scalar(255,255,255));
+ }
+
+ // Display the images with epipolar lines
+ cv::namedWindow("Right Image Epilines (RANSAC)");
+ cv::imshow("Right Image Epilines (RANSAC)",image1);
+ cv::namedWindow("Left Image Epilines (RANSAC)");
+ cv::imshow("Left Image Epilines (RANSAC)",image2);
+
+ cv::waitKey();
+ return 0;
+}
\ No newline at end of file
/Chapter 09/robustmatching.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 09/README.txt
===================================================================
--- Chapter 09/README.txt (nonexistent)
+++ Chapter 09/README.txt (revision 3)
@@ -0,0 +1,23 @@
+This directory contains material supporting chapter 9 of the cookbook:
+Computer Vision Programming using the OpenCV Library.
+by Robert Laganiere, Packt Publishing, 2011.
+
+Files:
+ CameraCalibrator.h
+ CameraCalibrator.cpp
+ calibrate.cpp
+correspond to Recipes:
+Calibrating a camera
+File:
+ estimateF.cpp
+correspond to Recipe:
+Computing the Fundamental Matrix of an Image Pair
+Files:
+ matcher.h
+ robustmatching.cpp
+correspond to Recipe:
+Matching Images using Random Sample Consensus
+File:
+ estimateH.cpp
+correspond to Recipe:
+Computing a homography between two images
/Chapter 09/README.txt
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 09/CameraCalibrator.cpp
===================================================================
--- Chapter 09/CameraCalibrator.cpp (nonexistent)
+++ Chapter 09/CameraCalibrator.cpp (revision 3)
@@ -0,0 +1,149 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 9 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include "CameraCalibrator.h"
+
+// Open chessboard images and extract corner points
+int CameraCalibrator::addChessboardPoints(
+ const std::vector<std::string>& filelist,
+ cv::Size & boardSize) {
+
+ // the points on the chessboard
+ std::vector<cv::Point2f> imageCorners;
+ std::vector<cv::Point3f> objectCorners;
+
+ // 3D Scene Points:
+ // Initialize the chessboard corners
+ // in the chessboard reference frame
+ // The corners are at 3D location (X,Y,Z)= (i,j,0)
+ for (int i=0; i<boardSize.height; i++) {
+ for (int j=0; j<boardSize.width; j++) {
+
+ objectCorners.push_back(cv::Point3f(i, j, 0.0f));
+ }
+ }
+
+ // 2D Image points:
+ cv::Mat image; // to contain chessboard image
+ int successes = 0;
+ // for all viewpoints
+ for (int i=0; i<filelist.size(); i++) {
+
+ // Open the image
+ image = cv::imread(filelist[i],0);
+
+ // Get the chessboard corners
+ bool found = cv::findChessboardCorners(
+ image, boardSize, imageCorners);
+
+ // Get subpixel accuracy on the corners
+ cv::cornerSubPix(image, imageCorners,
+ cv::Size(5,5),
+ cv::Size(-1,-1),
+ cv::TermCriteria(cv::TermCriteria::MAX_ITER +
+ cv::TermCriteria::EPS,
+ 30, // max number of iterations
+ 0.1)); // min accuracy
+
+ // If we have a good board, add it to our data
+ if (imageCorners.size() == boardSize.area()) {
+
+ // Add image and scene points from one view
+ addPoints(imageCorners, objectCorners);
+ successes++;
+ }
+
+ //Draw the corners
+ cv::drawChessboardCorners(image, boardSize, imageCorners, found);
+ cv::imshow("Corners on Chessboard", image);
+ cv::waitKey(100);
+ }
+
+ return successes;
+}
+
+// Add scene points and corresponding image points
+void CameraCalibrator::addPoints(const std::vector<cv::Point2f>& imageCorners, const std::vector<cv::Point3f>& objectCorners) {
+
+ // 2D image points from one view
+ imagePoints.push_back(imageCorners);
+ // corresponding 3D scene points
+ objectPoints.push_back(objectCorners);
+}
+
+// Calibrate the camera
+// returns the re-projection error
+double CameraCalibrator::calibrate(cv::Size &imageSize)
+{
+ // undistorter must be reinitialized
+ mustInitUndistort= true;
+
+ //Output rotations and translations
+ std::vector<cv::Mat> rvecs, tvecs;
+
+ // start calibration
+ return
+ calibrateCamera(objectPoints, // the 3D points
+ imagePoints, // the image points
+ imageSize, // image size
+ cameraMatrix, // output camera matrix
+ distCoeffs, // output distortion matrix
+ rvecs, tvecs, // Rs, Ts
+ flag); // set options
+// ,CV_CALIB_USE_INTRINSIC_GUESS);
+
+}
+
+// remove distortion in an image (after calibration)
+cv::Mat CameraCalibrator::remap(const cv::Mat &image) {
+
+ cv::Mat undistorted;
+
+ if (mustInitUndistort) { // called once per calibration
+
+ cv::initUndistortRectifyMap(
+ cameraMatrix, // computed camera matrix
+ distCoeffs, // computed distortion matrix
+ cv::Mat(), // optional rectification (none)
+ cv::Mat(), // camera matrix to generate undistorted
+ cv::Size(640,480),
+// image.size(), // size of undistorted
+ CV_32FC1, // type of output map
+ map1, map2); // the x and y mapping functions
+
+ mustInitUndistort= false;
+ }
+
+ // Apply mapping functions
+ cv::remap(image, undistorted, map1, map2,
+ cv::INTER_LINEAR); // interpolation type
+
+ return undistorted;
+}
+
+
+// Set the calibration options
+// 8radialCoeffEnabled should be true if 8 radial coefficients are required (5 is default)
+// tangentialParamEnabled should be true if tangeantial distortion is present
+void CameraCalibrator::setCalibrationFlag(bool radial8CoeffEnabled, bool tangentialParamEnabled) {
+
+ // Set the flag used in cv::calibrateCamera()
+ flag = 0;
+ if (!tangentialParamEnabled) flag += CV_CALIB_ZERO_TANGENT_DIST;
+ if (radial8CoeffEnabled) flag += CV_CALIB_RATIONAL_MODEL;
+}
+
/Chapter 09/CameraCalibrator.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: 3241OS_images/images/canal2.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/canal2.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/dog.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/dog.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/tiger.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/tiger.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/parliament1.bmp
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/parliament1.bmp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/parliament2.bmp
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/parliament2.bmp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/polar.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/polar.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/parliament3.bmp
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/parliament3.bmp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/baboon1.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/baboon1.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard10.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard10.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard11.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard11.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard30.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard30.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard12.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard12.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard31.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard31.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard13.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard13.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard32.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard32.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard14.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard14.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard15.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard15.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard33.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard33.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard16.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard16.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard34.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard34.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard17.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard17.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard35.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard35.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard18.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard18.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard36.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard36.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard37.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard37.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard19.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard19.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard38.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard38.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard39.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard39.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard01.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard01.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard02.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard02.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard20.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard20.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard03.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard03.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard21.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard21.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard40.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard40.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard04.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard04.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard22.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard22.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard41.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard41.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard05.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard05.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard23.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard23.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard24.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard24.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard06.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard06.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard42.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard42.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard25.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard25.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard07.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard07.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard43.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard43.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard26.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard26.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard08.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard08.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard27.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard27.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard09.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard09.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard28.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard28.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chessboards/chessboard29.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chessboards/chessboard29.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/moose.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/moose.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/baboon2.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/baboon2.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/binary.bmp
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/binary.bmp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/baboon3.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/baboon3.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/baboon4.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/baboon4.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/waves.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/waves.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/building.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/building.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/logo.bmp
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/logo.bmp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/binaryGroup.bmp
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/binaryGroup.bmp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/tower.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/tower.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/beach.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/beach.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/boldt.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/boldt.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/bike.avi
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/bike.avi
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/bear.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/bear.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/sagouine.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/sagouine.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/puppy.bmp
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/puppy.bmp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/lake.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/lake.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/marais.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/marais.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/church01.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/church01.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/church02.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/church02.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/church03.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/church03.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/monument1.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/monument1.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/monument2.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/monument2.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/fundy.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/fundy.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/road.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/road.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/chariot.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/chariot.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/rain.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/rain.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/group.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/group.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: 3241OS_images/images/canal1.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/3241OS_images/images/canal1.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: Chapter 01/myQtGUIApp/myQtGUIApp.pro
===================================================================
--- Chapter 01/myQtGUIApp/myQtGUIApp.pro (nonexistent)
+++ Chapter 01/myQtGUIApp/myQtGUIApp.pro (revision 3)
@@ -0,0 +1,25 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2010-06-28T13:41:33
+#
+#-------------------------------------------------
+
+TARGET = myQtGUIApp
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+ mainwindow.cpp
+
+HEADERS += mainwindow.h
+
+FORMS += mainwindow.ui
+
+INCLUDEPATH += C:\OpenCV2.2\include\
+
+LIBS += -LC:\OpenCV2.2\lib \
+ -lopencv_core220 \
+ -lopencv_highgui220 \
+ -lopencv_imgproc220 \
+ -lopencv_features2d220 \
+ -lopencv_calib3d220
Index: Chapter 01/myQtGUIApp/ui_mainwindow.h
===================================================================
--- Chapter 01/myQtGUIApp/ui_mainwindow.h (nonexistent)
+++ Chapter 01/myQtGUIApp/ui_mainwindow.h (revision 3)
@@ -0,0 +1,99 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 1 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+/********************************************************************************
+** Form generated from reading UI file 'mainwindow.ui'
+**
+** Created: Tue Jun 29 12:53:36 2010
+** by: Qt User Interface Compiler version 4.6.3
+**
+** WARNING! All changes made in this file will be lost when recompiling UI file!
+********************************************************************************/
+
+#ifndef UI_MAINWINDOW_H
+#define UI_MAINWINDOW_H
+
+#include <QtCore/QVariant>
+#include <QtGui/QAction>
+#include <QtGui/QApplication>
+#include <QtGui/QButtonGroup>
+#include <QtGui/QHeaderView>
+#include <QtGui/QMainWindow>
+#include <QtGui/QMenuBar>
+#include <QtGui/QPushButton>
+#include <QtGui/QStatusBar>
+#include <QtGui/QToolBar>
+#include <QtGui/QWidget>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_MainWindow
+{
+public:
+ QWidget *centralWidget;
+ QPushButton *pushButton;
+ QPushButton *pushButton_2;
+ QMenuBar *menuBar;
+ QToolBar *mainToolBar;
+ QStatusBar *statusBar;
+
+ void setupUi(QMainWindow *MainWindow)
+ {
+ if (MainWindow->objectName().isEmpty())
+ MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
+ MainWindow->resize(262, 214);
+ centralWidget = new QWidget(MainWindow);
+ centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
+ pushButton = new QPushButton(centralWidget);
+ pushButton->setObjectName(QString::fromUtf8("pushButton"));
+ pushButton->setGeometry(QRect(60, 20, 141, 51));
+ pushButton_2 = new QPushButton(centralWidget);
+ pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
+ pushButton_2->setGeometry(QRect(60, 90, 141, 51));
+ MainWindow->setCentralWidget(centralWidget);
+ menuBar = new QMenuBar(MainWindow);
+ menuBar->setObjectName(QString::fromUtf8("menuBar"));
+ menuBar->setGeometry(QRect(0, 0, 262, 25));
+ MainWindow->setMenuBar(menuBar);
+ mainToolBar = new QToolBar(MainWindow);
+ mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
+ MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
+ statusBar = new QStatusBar(MainWindow);
+ statusBar->setObjectName(QString::fromUtf8("statusBar"));
+ MainWindow->setStatusBar(statusBar);
+
+ retranslateUi(MainWindow);
+
+ QMetaObject::connectSlotsByName(MainWindow);
+ } // setupUi
+
+ void retranslateUi(QMainWindow *MainWindow)
+ {
+ MainWindow->setWindowTitle(QApplication::translate("MainWindow", "My Qt Application", 0, QApplication::UnicodeUTF8));
+ pushButton->setText(QApplication::translate("MainWindow", "Open Image", 0, QApplication::UnicodeUTF8));
+ pushButton_2->setText(QApplication::translate("MainWindow", "Process", 0, QApplication::UnicodeUTF8));
+ } // retranslateUi
+
+};
+
+namespace Ui {
+ class MainWindow: public Ui_MainWindow {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UI_MAINWINDOW_H
/Chapter 01/myQtGUIApp/ui_mainwindow.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 01/myQtGUIApp/Makefile.Debug
===================================================================
--- Chapter 01/myQtGUIApp/Makefile.Debug (nonexistent)
+++ Chapter 01/myQtGUIApp/Makefile.Debug (revision 3)
@@ -0,0 +1,176 @@
+#############################################################################
+# Makefile for building: myQtGUIApp
+# Generated by qmake (2.01a) (Qt 4.6.3) on: Mon Feb 28 15:14:16 2011
+# Project: myQtGUIApp.pro
+# Template: app
+#############################################################################
+
+####### Compiler, tools and options
+
+CC = cl
+CXX = cl
+DEFINES = -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT
+CFLAGS = -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -W3 $(DEFINES)
+CXXFLAGS = -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 $(DEFINES)
+INCPATH = -I"..\..\Qt\4.6.3\include\QtCore" -I"..\..\Qt\4.6.3\include\QtGui" -I"..\..\Qt\4.6.3\include" -I"..\..\OpenCV2.2\include" -I"..\..\Qt\4.6.3\include\ActiveQt" -I"debug" -I"." -I"..\..\Qt\4.6.3\mkspecs\win32-msvc2008"
+LINK = link
+LFLAGS = /LIBPATH:"c:\Qt\4.6.3\lib" /NOLOGO /DEBUG /MANIFEST /MANIFESTFILE:"debug\myQtGUIApp.intermediate.manifest" /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'"
+LIBS = c:\Qt\4.6.3\lib\qtmaind.lib /LIBPATH:C:\OpenCV2.2\lib C:\OpenCV2.2\lib\opencv_core220.lib C:\OpenCV2.2\lib\opencv_highgui220.lib C:\OpenCV2.2\lib\opencv_imgproc220.lib C:\OpenCV2.2\lib\opencv_features2d220.lib C:\OpenCV2.2\lib\opencv_calib3d220.lib c:\Qt\4.6.3\lib\QtGuid4.lib c:\Qt\4.6.3\lib\QtCored4.lib
+QMAKE = c:\Qt\4.6.3\bin\qmake.exe
+IDC = c:\Qt\4.6.3\bin\idc.exe
+IDL = midl
+ZIP = zip -r -9
+DEF_FILE =
+RES_FILE =
+COPY = copy /y
+COPY_FILE = $(COPY)
+COPY_DIR = xcopy /s /q /y /i
+DEL_FILE = del
+DEL_DIR = rmdir
+MOVE = move
+CHK_DIR_EXISTS= if not exist
+MKDIR = mkdir
+INSTALL_FILE = $(COPY_FILE)
+INSTALL_PROGRAM = $(COPY_FILE)
+INSTALL_DIR = $(COPY_DIR)
+
+####### Output directory
+
+OBJECTS_DIR = debug
+
+####### Files
+
+SOURCES = main.cpp \
+ mainwindow.cpp debug\moc_mainwindow.cpp
+OBJECTS = debug\main.obj \
+ debug\mainwindow.obj \
+ debug\moc_mainwindow.obj
+DIST =
+QMAKE_TARGET = myQtGUIApp
+DESTDIR = debug\ #avoid trailing-slash linebreak
+TARGET = myQtGUIApp.exe
+DESTDIR_TARGET = debug\myQtGUIApp.exe
+
+####### Implicit rules
+
+.SUFFIXES: .c .cpp .cc .cxx
+
+{.}.cpp{debug\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{.}.cc{debug\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{.}.cxx{debug\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{.}.c{debug\}.obj::
+ $(CC) -c $(CFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{debug}.cpp{debug\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{debug}.cc{debug\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{debug}.cxx{debug\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{debug}.c{debug\}.obj::
+ $(CC) -c $(CFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+####### Build rules
+
+first: all
+all: Makefile.Debug $(DESTDIR_TARGET)
+
+$(DESTDIR_TARGET): ui_mainwindow.h $(OBJECTS)
+ $(LINK) $(LFLAGS) /OUT:$(DESTDIR_TARGET) @<<
+ $(OBJECTS) $(LIBS)
+<<
+ mt.exe -nologo -manifest "debug\myQtGUIApp.intermediate.manifest" -outputresource:$(DESTDIR_TARGET);1
+
+
+
+qmake: FORCE
+ @$(QMAKE) -spec ..\..\Qt\4.6.3\mkspecs\win32-msvc2008 -win32 CONFIG+=release -o Makefile.Debug myQtGUIApp.pro
+
+dist:
+ $(ZIP) myQtGUIApp.zip $(SOURCES) $(DIST) myQtGUIApp.pro ..\..\Qt\4.6.3\mkspecs\qconfig.pri ..\..\Qt\4.6.3\mkspecs\features\qt_functions.prf ..\..\Qt\4.6.3\mkspecs\features\qt_config.prf ..\..\Qt\4.6.3\mkspecs\features\exclusive_builds.prf ..\..\Qt\4.6.3\mkspecs\features\default_pre.prf ..\..\Qt\4.6.3\mkspecs\features\win32\default_pre.prf ..\..\Qt\4.6.3\mkspecs\features\debug.prf ..\..\Qt\4.6.3\mkspecs\features\debug_and_release.prf ..\..\Qt\4.6.3\mkspecs\features\default_post.prf ..\..\Qt\4.6.3\mkspecs\features\win32\default_post.prf ..\..\Qt\4.6.3\mkspecs\features\build_pass.prf ..\..\Qt\4.6.3\mkspecs\features\win32\rtti.prf ..\..\Qt\4.6.3\mkspecs\features\win32\exceptions.prf ..\..\Qt\4.6.3\mkspecs\features\win32\stl.prf ..\..\Qt\4.6.3\mkspecs\features\shared.prf ..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_exe.prf ..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_dll.prf ..\..\Qt\4.6.3\mkspecs\features\warn_on.prf ..\..\Qt\4.6.3\mkspecs\features\qt.prf ..\..\Qt\4.6.3\mkspecs\features\win32\thread.prf ..\..\Qt\4.6.3\mkspecs\features\moc.prf ..\..\Qt\4.6.3\mkspecs\features\win32\windows.prf ..\..\Qt\4.6.3\mkspecs\features\resources.prf ..\..\Qt\4.6.3\mkspecs\features\uic.prf ..\..\Qt\4.6.3\mkspecs\features\yacc.prf ..\..\Qt\4.6.3\mkspecs\features\lex.prf ..\..\Qt\4.6.3\mkspecs\features\incredibuild_xge.prf ..\..\Qt\4.6.3\mkspecs\features\include_source_dir.prf c:\Qt\4.6.3\lib\qtmaind.prl HEADERS RESOURCES IMAGES SOURCES OBJECTIVE_SOURCES FORMS YACCSOURCES YACCSOURCES LEXSOURCES
+
+clean: compiler_clean
+ -$(DEL_FILE) debug\main.obj debug\mainwindow.obj debug\moc_mainwindow.obj
+ -$(DEL_FILE) debug\myQtGUIApp.intermediate.manifest debug\myQtGUIApp.exp debug\myQtGUIApp.pdb debug\myQtGUIApp.ilk vc*.pdb vc*.idb
+
+distclean: clean
+ -$(DEL_FILE) $(DESTDIR_TARGET)
+ -$(DEL_FILE) Makefile.Debug
+
+check: first
+
+mocclean: compiler_moc_header_clean compiler_moc_source_clean
+
+mocables: compiler_moc_header_make_all compiler_moc_source_make_all
+
+compiler_moc_header_make_all: debug\moc_mainwindow.cpp
+compiler_moc_header_clean:
+ -$(DEL_FILE) debug\moc_mainwindow.cpp
+debug\moc_mainwindow.cpp: mainwindow.h
+ C:\Qt\4.6.3\bin\moc.exe $(DEFINES) $(INCPATH) -D_MSC_VER=1500 -DWIN32 mainwindow.h -o debug\moc_mainwindow.cpp
+
+compiler_rcc_make_all:
+compiler_rcc_clean:
+compiler_image_collection_make_all: qmake_image_collection.cpp
+compiler_image_collection_clean:
+ -$(DEL_FILE) qmake_image_collection.cpp
+compiler_moc_source_make_all:
+compiler_moc_source_clean:
+compiler_uic_make_all: ui_mainwindow.h
+compiler_uic_clean:
+ -$(DEL_FILE) ui_mainwindow.h
+ui_mainwindow.h: mainwindow.ui
+ c:\Qt\4.6.3\bin\uic.exe mainwindow.ui -o ui_mainwindow.h
+
+compiler_yacc_decl_make_all:
+compiler_yacc_decl_clean:
+compiler_yacc_impl_make_all:
+compiler_yacc_impl_clean:
+compiler_lex_make_all:
+compiler_lex_clean:
+compiler_clean: compiler_moc_header_clean compiler_uic_clean
+
+
+
+####### Compile
+
+debug\main.obj: main.cpp mainwindow.h
+
+debug\mainwindow.obj: mainwindow.cpp mainwindow.h \
+ ui_mainwindow.h
+
+debug\moc_mainwindow.obj: debug\moc_mainwindow.cpp
+
+####### Install
+
+install: FORCE
+
+uninstall: FORCE
+
+FORCE:
+
Index: Chapter 01/myQtGUIApp/mainwindow.h
===================================================================
--- Chapter 01/myQtGUIApp/mainwindow.h (nonexistent)
+++ Chapter 01/myQtGUIApp/mainwindow.h (revision 3)
@@ -0,0 +1,50 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 1 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtGui/QMainWindow>
+#include <QFileDialog>
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+
+namespace Ui
+{
+ class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+private:
+ Ui::MainWindow *ui;
+ cv::Mat image; // the image variable
+
+private slots:
+ void on_pushButton_2_clicked();
+ void on_pushButton_clicked();
+};
+
+#endif // MAINWINDOW_H
/Chapter 01/myQtGUIApp/mainwindow.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 01/myQtGUIApp/main.cpp
===================================================================
--- Chapter 01/myQtGUIApp/main.cpp (nonexistent)
+++ Chapter 01/myQtGUIApp/main.cpp (revision 3)
@@ -0,0 +1,27 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 1 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+ return a.exec();
+}
/Chapter 01/myQtGUIApp/main.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 01/myQtGUIApp/mainwindow.ui
===================================================================
--- Chapter 01/myQtGUIApp/mainwindow.ui (nonexistent)
+++ Chapter 01/myQtGUIApp/mainwindow.ui (revision 3)
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>262</width>
+ <height>214</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>My Qt Application</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <widget class="QPushButton" name="pushButton">
+ <property name="geometry">
+ <rect>
+ <x>60</x>
+ <y>20</y>
+ <width>141</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Open Image</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="pushButton_2">
+ <property name="geometry">
+ <rect>
+ <x>60</x>
+ <y>90</y>
+ <width>141</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Process</string>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>262</width>
+ <height>25</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
Index: Chapter 01/myQtGUIApp/Makefile.Release
===================================================================
--- Chapter 01/myQtGUIApp/Makefile.Release (nonexistent)
+++ Chapter 01/myQtGUIApp/Makefile.Release (revision 3)
@@ -0,0 +1,176 @@
+#############################################################################
+# Makefile for building: myQtGUIApp
+# Generated by qmake (2.01a) (Qt 4.6.3) on: Mon Feb 28 15:14:16 2011
+# Project: myQtGUIApp.pro
+# Template: app
+#############################################################################
+
+####### Compiler, tools and options
+
+CC = cl
+CXX = cl
+DEFINES = -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT
+CFLAGS = -nologo -Zm200 -Zc:wchar_t- -O2 -MD -W3 $(DEFINES)
+CXXFLAGS = -nologo -Zm200 -Zc:wchar_t- -O2 -MD -GR -EHsc -W3 -w34100 -w34189 $(DEFINES)
+INCPATH = -I"..\..\Qt\4.6.3\include\QtCore" -I"..\..\Qt\4.6.3\include\QtGui" -I"..\..\Qt\4.6.3\include" -I"..\..\OpenCV2.2\include" -I"..\..\Qt\4.6.3\include\ActiveQt" -I"release" -I"." -I"..\..\Qt\4.6.3\mkspecs\win32-msvc2008"
+LINK = link
+LFLAGS = /LIBPATH:"c:\Qt\4.6.3\lib" /NOLOGO /INCREMENTAL:NO /MANIFEST /MANIFESTFILE:"release\myQtGUIApp.intermediate.manifest" /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'"
+LIBS = c:\Qt\4.6.3\lib\qtmain.lib /LIBPATH:C:\OpenCV2.2\lib C:\OpenCV2.2\lib\opencv_core220.lib C:\OpenCV2.2\lib\opencv_highgui220.lib C:\OpenCV2.2\lib\opencv_imgproc220.lib C:\OpenCV2.2\lib\opencv_features2d220.lib C:\OpenCV2.2\lib\opencv_calib3d220.lib c:\Qt\4.6.3\lib\QtGui4.lib c:\Qt\4.6.3\lib\QtCore4.lib
+QMAKE = c:\Qt\4.6.3\bin\qmake.exe
+IDC = c:\Qt\4.6.3\bin\idc.exe
+IDL = midl
+ZIP = zip -r -9
+DEF_FILE =
+RES_FILE =
+COPY = copy /y
+COPY_FILE = $(COPY)
+COPY_DIR = xcopy /s /q /y /i
+DEL_FILE = del
+DEL_DIR = rmdir
+MOVE = move
+CHK_DIR_EXISTS= if not exist
+MKDIR = mkdir
+INSTALL_FILE = $(COPY_FILE)
+INSTALL_PROGRAM = $(COPY_FILE)
+INSTALL_DIR = $(COPY_DIR)
+
+####### Output directory
+
+OBJECTS_DIR = release
+
+####### Files
+
+SOURCES = main.cpp \
+ mainwindow.cpp release\moc_mainwindow.cpp
+OBJECTS = release\main.obj \
+ release\mainwindow.obj \
+ release\moc_mainwindow.obj
+DIST =
+QMAKE_TARGET = myQtGUIApp
+DESTDIR = release\ #avoid trailing-slash linebreak
+TARGET = myQtGUIApp.exe
+DESTDIR_TARGET = release\myQtGUIApp.exe
+
+####### Implicit rules
+
+.SUFFIXES: .c .cpp .cc .cxx
+
+{release}.cpp{release\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{release}.cc{release\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{release}.cxx{release\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{release}.c{release\}.obj::
+ $(CC) -c $(CFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{.}.cpp{release\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{.}.cc{release\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{.}.cxx{release\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{.}.c{release\}.obj::
+ $(CC) -c $(CFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+####### Build rules
+
+first: all
+all: Makefile.Release $(DESTDIR_TARGET)
+
+$(DESTDIR_TARGET): ui_mainwindow.h $(OBJECTS)
+ $(LINK) $(LFLAGS) /OUT:$(DESTDIR_TARGET) @<<
+ $(OBJECTS) $(LIBS)
+<<
+ mt.exe -nologo -manifest "release\myQtGUIApp.intermediate.manifest" -outputresource:$(DESTDIR_TARGET);1
+
+
+
+qmake: FORCE
+ @$(QMAKE) -spec ..\..\Qt\4.6.3\mkspecs\win32-msvc2008 -win32 CONFIG+=release -o Makefile.Release myQtGUIApp.pro
+
+dist:
+ $(ZIP) myQtGUIApp.zip $(SOURCES) $(DIST) myQtGUIApp.pro ..\..\Qt\4.6.3\mkspecs\qconfig.pri ..\..\Qt\4.6.3\mkspecs\features\qt_functions.prf ..\..\Qt\4.6.3\mkspecs\features\qt_config.prf ..\..\Qt\4.6.3\mkspecs\features\exclusive_builds.prf ..\..\Qt\4.6.3\mkspecs\features\default_pre.prf ..\..\Qt\4.6.3\mkspecs\features\win32\default_pre.prf ..\..\Qt\4.6.3\mkspecs\features\release.prf ..\..\Qt\4.6.3\mkspecs\features\debug_and_release.prf ..\..\Qt\4.6.3\mkspecs\features\default_post.prf ..\..\Qt\4.6.3\mkspecs\features\win32\default_post.prf ..\..\Qt\4.6.3\mkspecs\features\build_pass.prf ..\..\Qt\4.6.3\mkspecs\features\win32\rtti.prf ..\..\Qt\4.6.3\mkspecs\features\win32\exceptions.prf ..\..\Qt\4.6.3\mkspecs\features\win32\stl.prf ..\..\Qt\4.6.3\mkspecs\features\shared.prf ..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_exe.prf ..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_dll.prf ..\..\Qt\4.6.3\mkspecs\features\warn_on.prf ..\..\Qt\4.6.3\mkspecs\features\qt.prf ..\..\Qt\4.6.3\mkspecs\features\win32\thread.prf ..\..\Qt\4.6.3\mkspecs\features\moc.prf ..\..\Qt\4.6.3\mkspecs\features\win32\windows.prf ..\..\Qt\4.6.3\mkspecs\features\resources.prf ..\..\Qt\4.6.3\mkspecs\features\uic.prf ..\..\Qt\4.6.3\mkspecs\features\yacc.prf ..\..\Qt\4.6.3\mkspecs\features\lex.prf ..\..\Qt\4.6.3\mkspecs\features\incredibuild_xge.prf ..\..\Qt\4.6.3\mkspecs\features\include_source_dir.prf c:\Qt\4.6.3\lib\qtmain.prl HEADERS RESOURCES IMAGES SOURCES OBJECTIVE_SOURCES FORMS YACCSOURCES YACCSOURCES LEXSOURCES
+
+clean: compiler_clean
+ -$(DEL_FILE) release\main.obj release\mainwindow.obj release\moc_mainwindow.obj
+ -$(DEL_FILE) release\myQtGUIApp.intermediate.manifest release\myQtGUIApp.exp
+
+distclean: clean
+ -$(DEL_FILE) $(DESTDIR_TARGET)
+ -$(DEL_FILE) Makefile.Release
+
+check: first
+
+mocclean: compiler_moc_header_clean compiler_moc_source_clean
+
+mocables: compiler_moc_header_make_all compiler_moc_source_make_all
+
+compiler_moc_header_make_all: release\moc_mainwindow.cpp
+compiler_moc_header_clean:
+ -$(DEL_FILE) release\moc_mainwindow.cpp
+release\moc_mainwindow.cpp: mainwindow.h
+ C:\Qt\4.6.3\bin\moc.exe $(DEFINES) $(INCPATH) -D_MSC_VER=1500 -DWIN32 mainwindow.h -o release\moc_mainwindow.cpp
+
+compiler_rcc_make_all:
+compiler_rcc_clean:
+compiler_image_collection_make_all: qmake_image_collection.cpp
+compiler_image_collection_clean:
+ -$(DEL_FILE) qmake_image_collection.cpp
+compiler_moc_source_make_all:
+compiler_moc_source_clean:
+compiler_uic_make_all: ui_mainwindow.h
+compiler_uic_clean:
+ -$(DEL_FILE) ui_mainwindow.h
+ui_mainwindow.h: mainwindow.ui
+ c:\Qt\4.6.3\bin\uic.exe mainwindow.ui -o ui_mainwindow.h
+
+compiler_yacc_decl_make_all:
+compiler_yacc_decl_clean:
+compiler_yacc_impl_make_all:
+compiler_yacc_impl_clean:
+compiler_lex_make_all:
+compiler_lex_clean:
+compiler_clean: compiler_moc_header_clean compiler_uic_clean
+
+
+
+####### Compile
+
+release\main.obj: main.cpp mainwindow.h
+
+release\mainwindow.obj: mainwindow.cpp mainwindow.h \
+ ui_mainwindow.h
+
+release\moc_mainwindow.obj: release\moc_mainwindow.cpp
+
+####### Install
+
+install: FORCE
+
+uninstall: FORCE
+
+FORCE:
+
Index: Chapter 01/myQtGUIApp/Makefile
===================================================================
--- Chapter 01/myQtGUIApp/Makefile (nonexistent)
+++ Chapter 01/myQtGUIApp/Makefile (revision 3)
@@ -0,0 +1,153 @@
+#############################################################################
+# Makefile for building: myQtGUIApp
+# Generated by qmake (2.01a) (Qt 4.6.3) on: Mon Feb 28 15:14:16 2011
+# Project: myQtGUIApp.pro
+# Template: app
+# Command: c:\Qt\4.6.3\bin\qmake.exe -spec ..\..\Qt\4.6.3\mkspecs\win32-msvc2008 -win32 CONFIG+=release -o Makefile myQtGUIApp.pro
+#############################################################################
+
+first: release
+install: release-install
+uninstall: release-uninstall
+MAKEFILE = Makefile
+QMAKE = c:\Qt\4.6.3\bin\qmake.exe
+DEL_FILE = del
+CHK_DIR_EXISTS= if not exist
+MKDIR = mkdir
+COPY = copy /y
+COPY_FILE = $(COPY)
+COPY_DIR = xcopy /s /q /y /i
+INSTALL_FILE = $(COPY_FILE)
+INSTALL_PROGRAM = $(COPY_FILE)
+INSTALL_DIR = $(COPY_DIR)
+DEL_FILE = del
+SYMLINK =
+DEL_DIR = rmdir
+MOVE = move
+CHK_DIR_EXISTS= if not exist
+MKDIR = mkdir
+SUBTARGETS = \
+ release \
+ debug
+
+release: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release
+release-make_default: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release
+release-make_first: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release first
+release-all: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release all
+release-clean: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release clean
+release-distclean: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release distclean
+release-install: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release install
+release-uninstall: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release uninstall
+debug: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug
+debug-make_default: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug
+debug-make_first: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug first
+debug-all: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug all
+debug-clean: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug clean
+debug-distclean: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug distclean
+debug-install: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug install
+debug-uninstall: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug uninstall
+
+Makefile: myQtGUIApp.pro ..\..\Qt\4.6.3\mkspecs\win32-msvc2008\qmake.conf ..\..\Qt\4.6.3\mkspecs\qconfig.pri \
+ ..\..\Qt\4.6.3\mkspecs\features\qt_functions.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\qt_config.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\exclusive_builds.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\default_pre.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\default_pre.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\release.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\debug_and_release.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\default_post.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\default_post.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\rtti.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\exceptions.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\stl.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\shared.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_exe.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_dll.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\warn_on.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\qt.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\thread.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\moc.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\windows.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\resources.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\uic.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\yacc.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\lex.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\incredibuild_xge.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\include_source_dir.prf \
+ c:\Qt\4.6.3\lib\qtmain.prl
+ $(QMAKE) -spec ..\..\Qt\4.6.3\mkspecs\win32-msvc2008 -win32 CONFIG+=release -o Makefile myQtGUIApp.pro
+..\..\Qt\4.6.3\mkspecs\qconfig.pri:
+..\..\Qt\4.6.3\mkspecs\features\qt_functions.prf:
+..\..\Qt\4.6.3\mkspecs\features\qt_config.prf:
+..\..\Qt\4.6.3\mkspecs\features\exclusive_builds.prf:
+..\..\Qt\4.6.3\mkspecs\features\default_pre.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\default_pre.prf:
+..\..\Qt\4.6.3\mkspecs\features\release.prf:
+..\..\Qt\4.6.3\mkspecs\features\debug_and_release.prf:
+..\..\Qt\4.6.3\mkspecs\features\default_post.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\default_post.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\rtti.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\exceptions.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\stl.prf:
+..\..\Qt\4.6.3\mkspecs\features\shared.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_exe.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_dll.prf:
+..\..\Qt\4.6.3\mkspecs\features\warn_on.prf:
+..\..\Qt\4.6.3\mkspecs\features\qt.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\thread.prf:
+..\..\Qt\4.6.3\mkspecs\features\moc.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\windows.prf:
+..\..\Qt\4.6.3\mkspecs\features\resources.prf:
+..\..\Qt\4.6.3\mkspecs\features\uic.prf:
+..\..\Qt\4.6.3\mkspecs\features\yacc.prf:
+..\..\Qt\4.6.3\mkspecs\features\lex.prf:
+..\..\Qt\4.6.3\mkspecs\features\incredibuild_xge.prf:
+..\..\Qt\4.6.3\mkspecs\features\include_source_dir.prf:
+c:\Qt\4.6.3\lib\qtmain.prl:
+qmake: qmake_all FORCE
+ @$(QMAKE) -spec ..\..\Qt\4.6.3\mkspecs\win32-msvc2008 -win32 CONFIG+=release -o Makefile myQtGUIApp.pro
+
+qmake_all: FORCE
+
+make_default: release-make_default debug-make_default FORCE
+make_first: release-make_first debug-make_first FORCE
+all: release-all debug-all FORCE
+clean: release-clean debug-clean FORCE
+ -$(DEL_FILE) ".\myQtGUIApp.intermediate.manifest"
+ -$(DEL_FILE) myQtGUIApp.exp
+distclean: release-distclean debug-distclean FORCE
+ -$(DEL_FILE) Makefile
+
+check: first
+
+release-mocclean: $(MAKEFILE).Release
+ $(MAKE) -f $(MAKEFILE).Release mocclean
+debug-mocclean: $(MAKEFILE).Debug
+ $(MAKE) -f $(MAKEFILE).Debug mocclean
+mocclean: release-mocclean debug-mocclean
+
+release-mocables: $(MAKEFILE).Release
+ $(MAKE) -f $(MAKEFILE).Release mocables
+debug-mocables: $(MAKEFILE).Debug
+ $(MAKE) -f $(MAKEFILE).Debug mocables
+mocables: release-mocables debug-mocables
+FORCE:
+
+$(MAKEFILE).Release: Makefile
+$(MAKEFILE).Debug: Makefile
Index: Chapter 01/myQtGUIApp/mainwindow.cpp
===================================================================
--- Chapter 01/myQtGUIApp/mainwindow.cpp (nonexistent)
+++ Chapter 01/myQtGUIApp/mainwindow.cpp (revision 3)
@@ -0,0 +1,47 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 1 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent), ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::on_pushButton_clicked()
+{
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open Image"), ".", tr("Image Files (*.png *.jpg *.bmp)"));
+
+ image= cv::imread(fileName.toAscii().data());
+ cv::namedWindow("Original Image");
+ cv::imshow("Original Image", image);
+}
+
+void MainWindow::on_pushButton_2_clicked()
+{
+ cv::flip(image,image,1);
+ cv::namedWindow("Output Image");
+ cv::imshow("Output Image", image);
+}
/Chapter 01/myQtGUIApp/mainwindow.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 01/myQtConsoleProject.pro
===================================================================
--- Chapter 01/myQtConsoleProject.pro (nonexistent)
+++ Chapter 01/myQtConsoleProject.pro (revision 3)
@@ -0,0 +1,25 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator
+#
+#-------------------------------------------------
+
+QT -= gui
+
+TARGET = myQtConsoleProject
+CONFIG += console
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+
+SOURCES += main.cpp
+
+INCLUDEPATH += C:\OpenCV2.2\include\
+
+LIBS += -LC:\OpenCV2.2\lib \
+ -lopencv_core220 \
+ -lopencv_highgui220 \
+ -lopencv_imgproc220 \
+ -lopencv_features2d220 \
+ -lopencv_calib3d220
Index: Chapter 01/main1.cpp
===================================================================
--- Chapter 01/main1.cpp (nonexistent)
+++ Chapter 01/main1.cpp (revision 3)
@@ -0,0 +1,33 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 1 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+int main() {
+
+ // read an image
+ cv::Mat image= cv::imread("img.jpg");
+ // create image window named "My Image"
+ cv::namedWindow("My Image");
+ // show the image on window
+ cv::imshow("My Image", image);
+ // wait key for 5000 ms
+ cv::waitKey(5000);
+
+ return 1;
+}
/Chapter 01/main1.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 01/main2.cpp
===================================================================
--- Chapter 01/main2.cpp (nonexistent)
+++ Chapter 01/main2.cpp (revision 3)
@@ -0,0 +1,92 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 1 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+// function that creates and returns an image
+cv::Mat function() {
+
+ // create image
+ cv::Mat ima(240,320,CV_8U,cv::Scalar(100));
+ // return it
+ return ima;
+}
+
+int main() {
+
+ // create image
+ cv::Mat image;
+ // print image size
+ std::cout << "size: " << image.size().height << " , "
+ << image.size().width << std::endl;
+ // open image
+ image= cv::imread("img.jpg");
+ // check if image has been successfully read
+ if (!image.data) {
+ // no image has been createdÂ…
+ return 0;
+ }
+ // print image size
+ std::cout << "size (after reading): " << image.size().height << " , "
+ << image.size().width << std::endl;
+
+ // display image
+ cv::namedWindow("Original Image"); // define the window
+ cv::imshow("Original Image", image); // show the image
+
+ // create another image
+ cv::Mat result;
+ // flip the image
+ cv::flip(image,result,1); // positive for horizontal
+ // 0 for vertical,
+ // negative for both
+ // display result
+ cv::namedWindow("Output Image");
+ cv::imshow("Output Image", result);
+ // wait for key pressed
+ cv::waitKey(0);
+ // write image on file
+ cv::imwrite("output.bmp", result);
+
+ // create two new images
+ cv::Mat image2, image3;
+
+ image2= result; // the two images refer to the same data
+ result.copyTo(image3); // a new copy is created
+
+ // flip vertically this time
+ cv::flip(result,result,0);
+
+ // display result
+ cv::namedWindow("image 2");
+ cv::imshow("image 2", image2);
+ cv::namedWindow("image 3");
+ cv::imshow("image 3", image3);
+
+ // get a gray-level image
+ cv::Mat gray= function();
+ // display result
+ cv::namedWindow("Gray Image");
+ cv::imshow("Gray Image", gray);
+
+ // wait for key pressed
+ cv::waitKey(0);
+ return 1;
+}
+
/Chapter 01/main2.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 01/anotherQtGUI/ui_mainwindow.h
===================================================================
--- Chapter 01/anotherQtGUI/ui_mainwindow.h (nonexistent)
+++ Chapter 01/anotherQtGUI/ui_mainwindow.h (revision 3)
@@ -0,0 +1,104 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 1 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+/********************************************************************************
+** Form generated from reading UI file 'mainwindow.ui'
+**
+** Created: Wed Jun 30 08:35:07 2010
+** by: Qt User Interface Compiler version 4.6.3
+**
+** WARNING! All changes made in this file will be lost when recompiling UI file!
+********************************************************************************/
+
+#ifndef UI_MAINWINDOW_H
+#define UI_MAINWINDOW_H
+
+#include <QtCore/QVariant>
+#include <QtGui/QAction>
+#include <QtGui/QApplication>
+#include <QtGui/QButtonGroup>
+#include <QtGui/QHeaderView>
+#include <QtGui/QLabel>
+#include <QtGui/QMainWindow>
+#include <QtGui/QMenuBar>
+#include <QtGui/QPushButton>
+#include <QtGui/QStatusBar>
+#include <QtGui/QToolBar>
+#include <QtGui/QWidget>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_MainWindow
+{
+public:
+ QWidget *centralWidget;
+ QPushButton *pushButton;
+ QPushButton *pushButton_2;
+ QLabel *label;
+ QMenuBar *menuBar;
+ QToolBar *mainToolBar;
+ QStatusBar *statusBar;
+
+ void setupUi(QMainWindow *MainWindow)
+ {
+ if (MainWindow->objectName().isEmpty())
+ MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
+ MainWindow->resize(572, 326);
+ centralWidget = new QWidget(MainWindow);
+ centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
+ pushButton = new QPushButton(centralWidget);
+ pushButton->setObjectName(QString::fromUtf8("pushButton"));
+ pushButton->setGeometry(QRect(10, 10, 111, 51));
+ pushButton_2 = new QPushButton(centralWidget);
+ pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
+ pushButton_2->setGeometry(QRect(10, 70, 111, 51));
+ label = new QLabel(centralWidget);
+ label->setObjectName(QString::fromUtf8("label"));
+ label->setGeometry(QRect(160, 10, 391, 261));
+ MainWindow->setCentralWidget(centralWidget);
+ menuBar = new QMenuBar(MainWindow);
+ menuBar->setObjectName(QString::fromUtf8("menuBar"));
+ menuBar->setGeometry(QRect(0, 0, 572, 25));
+ MainWindow->setMenuBar(menuBar);
+ mainToolBar = new QToolBar(MainWindow);
+ mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
+ MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
+ statusBar = new QStatusBar(MainWindow);
+ statusBar->setObjectName(QString::fromUtf8("statusBar"));
+ MainWindow->setStatusBar(statusBar);
+
+ retranslateUi(MainWindow);
+
+ QMetaObject::connectSlotsByName(MainWindow);
+ } // setupUi
+
+ void retranslateUi(QMainWindow *MainWindow)
+ {
+ MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
+ pushButton->setText(QApplication::translate("MainWindow", "Open Image", 0, QApplication::UnicodeUTF8));
+ pushButton_2->setText(QApplication::translate("MainWindow", "Process", 0, QApplication::UnicodeUTF8));
+ label->setText(QApplication::translate("MainWindow", "Image", 0, QApplication::UnicodeUTF8));
+ } // retranslateUi
+
+};
+
+namespace Ui {
+ class MainWindow: public Ui_MainWindow {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UI_MAINWINDOW_H
/Chapter 01/anotherQtGUI/ui_mainwindow.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 01/anotherQtGUI/Makefile.Debug
===================================================================
--- Chapter 01/anotherQtGUI/Makefile.Debug (nonexistent)
+++ Chapter 01/anotherQtGUI/Makefile.Debug (revision 3)
@@ -0,0 +1,176 @@
+#############################################################################
+# Makefile for building: anotherQtGUI
+# Generated by qmake (2.01a) (Qt 4.6.3) on: Thu Aug 5 11:10:44 2010
+# Project: anotherQtGUI.pro
+# Template: app
+#############################################################################
+
+####### Compiler, tools and options
+
+CC = cl
+CXX = cl
+DEFINES = -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT
+CFLAGS = -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -W3 $(DEFINES)
+CXXFLAGS = -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 $(DEFINES)
+INCPATH = -I"..\..\Qt\4.6.3\include\QtCore" -I"..\..\Qt\4.6.3\include\QtGui" -I"..\..\Qt\4.6.3\include" -I"..\..\OpenCV2.1\include\opencv" -I"..\..\Qt\4.6.3\include\ActiveQt" -I"debug" -I"." -I"..\..\Qt\4.6.3\mkspecs\win32-msvc2008"
+LINK = link
+LFLAGS = /LIBPATH:"c:\Qt\4.6.3\lib" /NOLOGO /DEBUG /MANIFEST /MANIFESTFILE:"debug\anotherQtGUI.intermediate.manifest" /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'"
+LIBS = c:\Qt\4.6.3\lib\qtmaind.lib /LIBPATH:C:\OpenCV2.1\lib C:\OpenCV2.1\lib\cv210.lib C:\OpenCV2.1\lib\cxcore210.lib C:\OpenCV2.1\lib\highgui210.lib c:\Qt\4.6.3\lib\QtGuid4.lib c:\Qt\4.6.3\lib\QtCored4.lib
+QMAKE = c:\Qt\4.6.3\bin\qmake.exe
+IDC = c:\Qt\4.6.3\bin\idc.exe
+IDL = midl
+ZIP = zip -r -9
+DEF_FILE =
+RES_FILE =
+COPY = copy /y
+COPY_FILE = $(COPY)
+COPY_DIR = xcopy /s /q /y /i
+DEL_FILE = del
+DEL_DIR = rmdir
+MOVE = move
+CHK_DIR_EXISTS= if not exist
+MKDIR = mkdir
+INSTALL_FILE = $(COPY_FILE)
+INSTALL_PROGRAM = $(COPY_FILE)
+INSTALL_DIR = $(COPY_DIR)
+
+####### Output directory
+
+OBJECTS_DIR = debug
+
+####### Files
+
+SOURCES = main.cpp \
+ mainwindow.cpp debug\moc_mainwindow.cpp
+OBJECTS = debug\main.obj \
+ debug\mainwindow.obj \
+ debug\moc_mainwindow.obj
+DIST =
+QMAKE_TARGET = anotherQtGUI
+DESTDIR = debug\ #avoid trailing-slash linebreak
+TARGET = anotherQtGUI.exe
+DESTDIR_TARGET = debug\anotherQtGUI.exe
+
+####### Implicit rules
+
+.SUFFIXES: .c .cpp .cc .cxx
+
+{.}.cpp{debug\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{.}.cc{debug\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{.}.cxx{debug\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{.}.c{debug\}.obj::
+ $(CC) -c $(CFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{debug}.cpp{debug\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{debug}.cc{debug\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{debug}.cxx{debug\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+{debug}.c{debug\}.obj::
+ $(CC) -c $(CFLAGS) $(INCPATH) -Fodebug\ @<<
+ $<
+<<
+
+####### Build rules
+
+first: all
+all: Makefile.Debug $(DESTDIR_TARGET)
+
+$(DESTDIR_TARGET): ui_mainwindow.h $(OBJECTS)
+ $(LINK) $(LFLAGS) /OUT:$(DESTDIR_TARGET) @<<
+ $(OBJECTS) $(LIBS)
+<<
+ mt.exe -nologo -manifest "debug\anotherQtGUI.intermediate.manifest" -outputresource:$(DESTDIR_TARGET);1
+
+
+
+qmake: FORCE
+ @$(QMAKE) -spec ..\..\Qt\4.6.3\mkspecs\win32-msvc2008 -win32 CONFIG+=release -o Makefile.Debug anotherQtGUI.pro
+
+dist:
+ $(ZIP) anotherQtGUI.zip $(SOURCES) $(DIST) anotherQtGUI.pro ..\..\Qt\4.6.3\mkspecs\qconfig.pri ..\..\Qt\4.6.3\mkspecs\features\qt_functions.prf ..\..\Qt\4.6.3\mkspecs\features\qt_config.prf ..\..\Qt\4.6.3\mkspecs\features\exclusive_builds.prf ..\..\Qt\4.6.3\mkspecs\features\default_pre.prf ..\..\Qt\4.6.3\mkspecs\features\win32\default_pre.prf ..\..\Qt\4.6.3\mkspecs\features\debug.prf ..\..\Qt\4.6.3\mkspecs\features\debug_and_release.prf ..\..\Qt\4.6.3\mkspecs\features\default_post.prf ..\..\Qt\4.6.3\mkspecs\features\win32\default_post.prf ..\..\Qt\4.6.3\mkspecs\features\build_pass.prf ..\..\Qt\4.6.3\mkspecs\features\win32\rtti.prf ..\..\Qt\4.6.3\mkspecs\features\win32\exceptions.prf ..\..\Qt\4.6.3\mkspecs\features\win32\stl.prf ..\..\Qt\4.6.3\mkspecs\features\shared.prf ..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_exe.prf ..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_dll.prf ..\..\Qt\4.6.3\mkspecs\features\warn_on.prf ..\..\Qt\4.6.3\mkspecs\features\qt.prf ..\..\Qt\4.6.3\mkspecs\features\win32\thread.prf ..\..\Qt\4.6.3\mkspecs\features\moc.prf ..\..\Qt\4.6.3\mkspecs\features\win32\windows.prf ..\..\Qt\4.6.3\mkspecs\features\resources.prf ..\..\Qt\4.6.3\mkspecs\features\uic.prf ..\..\Qt\4.6.3\mkspecs\features\yacc.prf ..\..\Qt\4.6.3\mkspecs\features\lex.prf ..\..\Qt\4.6.3\mkspecs\features\incredibuild_xge.prf ..\..\Qt\4.6.3\mkspecs\features\include_source_dir.prf c:\Qt\4.6.3\lib\qtmaind.prl HEADERS RESOURCES IMAGES SOURCES OBJECTIVE_SOURCES FORMS YACCSOURCES YACCSOURCES LEXSOURCES
+
+clean: compiler_clean
+ -$(DEL_FILE) debug\main.obj debug\mainwindow.obj debug\moc_mainwindow.obj
+ -$(DEL_FILE) debug\anotherQtGUI.intermediate.manifest debug\anotherQtGUI.exp debug\anotherQtGUI.pdb debug\anotherQtGUI.ilk vc*.pdb vc*.idb
+
+distclean: clean
+ -$(DEL_FILE) $(DESTDIR_TARGET)
+ -$(DEL_FILE) Makefile.Debug
+
+check: first
+
+mocclean: compiler_moc_header_clean compiler_moc_source_clean
+
+mocables: compiler_moc_header_make_all compiler_moc_source_make_all
+
+compiler_moc_header_make_all: debug\moc_mainwindow.cpp
+compiler_moc_header_clean:
+ -$(DEL_FILE) debug\moc_mainwindow.cpp
+debug\moc_mainwindow.cpp: mainwindow.h
+ C:\Qt\4.6.3\bin\moc.exe $(DEFINES) $(INCPATH) -D_MSC_VER=1500 -DWIN32 mainwindow.h -o debug\moc_mainwindow.cpp
+
+compiler_rcc_make_all:
+compiler_rcc_clean:
+compiler_image_collection_make_all: qmake_image_collection.cpp
+compiler_image_collection_clean:
+ -$(DEL_FILE) qmake_image_collection.cpp
+compiler_moc_source_make_all:
+compiler_moc_source_clean:
+compiler_uic_make_all: ui_mainwindow.h
+compiler_uic_clean:
+ -$(DEL_FILE) ui_mainwindow.h
+ui_mainwindow.h: mainwindow.ui
+ c:\Qt\4.6.3\bin\uic.exe mainwindow.ui -o ui_mainwindow.h
+
+compiler_yacc_decl_make_all:
+compiler_yacc_decl_clean:
+compiler_yacc_impl_make_all:
+compiler_yacc_impl_clean:
+compiler_lex_make_all:
+compiler_lex_clean:
+compiler_clean: compiler_moc_header_clean compiler_uic_clean
+
+
+
+####### Compile
+
+debug\main.obj: main.cpp mainwindow.h
+
+debug\mainwindow.obj: mainwindow.cpp mainwindow.h \
+ ui_mainwindow.h
+
+debug\moc_mainwindow.obj: debug\moc_mainwindow.cpp
+
+####### Install
+
+install: FORCE
+
+uninstall: FORCE
+
+FORCE:
+
Index: Chapter 01/anotherQtGUI/mainwindow.h
===================================================================
--- Chapter 01/anotherQtGUI/mainwindow.h (nonexistent)
+++ Chapter 01/anotherQtGUI/mainwindow.h (revision 3)
@@ -0,0 +1,47 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 1 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtGui/QMainWindow>
+#include <QFileDialog>
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+namespace Ui
+{
+ class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+private:
+ Ui::MainWindow *ui;
+ cv::Mat image; // the image variable
+
+private slots:
+ void on_pushButton_2_clicked();
+ void on_pushButton_clicked();
+};
+
+#endif // MAINWINDOW_H
/Chapter 01/anotherQtGUI/mainwindow.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 01/anotherQtGUI/main.cpp
===================================================================
--- Chapter 01/anotherQtGUI/main.cpp (nonexistent)
+++ Chapter 01/anotherQtGUI/main.cpp (revision 3)
@@ -0,0 +1,27 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 1 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+ return a.exec();
+}
/Chapter 01/anotherQtGUI/main.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 01/anotherQtGUI/mainwindow.ui
===================================================================
--- Chapter 01/anotherQtGUI/mainwindow.ui (nonexistent)
+++ Chapter 01/anotherQtGUI/mainwindow.ui (revision 3)
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>572</width>
+ <height>326</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <widget class="QPushButton" name="pushButton">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>10</y>
+ <width>111</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Open Image</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="pushButton_2">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>70</y>
+ <width>111</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Process</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label">
+ <property name="geometry">
+ <rect>
+ <x>160</x>
+ <y>10</y>
+ <width>391</width>
+ <height>261</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Image</string>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>572</width>
+ <height>25</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
Index: Chapter 01/anotherQtGUI/anotherQtGUI.pro
===================================================================
--- Chapter 01/anotherQtGUI/anotherQtGUI.pro (nonexistent)
+++ Chapter 01/anotherQtGUI/anotherQtGUI.pro (revision 3)
@@ -0,0 +1,25 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2010-06-30T08:18:42
+#
+#-------------------------------------------------
+
+TARGET = anotherQtGUI
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+ mainwindow.cpp
+
+HEADERS += mainwindow.h
+
+FORMS += mainwindow.ui
+
+INCLUDEPATH += C:\OpenCV2.2\include\
+
+LIBS += -LC:\OpenCV2.2\lib \
+ -lopencv_core220 \
+ -lopencv_highgui220 \
+ -lopencv_imgproc220 \
+ -lopencv_features2d220 \
+ -lopencv_calib3d220
Index: Chapter 01/anotherQtGUI/Makefile.Release
===================================================================
--- Chapter 01/anotherQtGUI/Makefile.Release (nonexistent)
+++ Chapter 01/anotherQtGUI/Makefile.Release (revision 3)
@@ -0,0 +1,176 @@
+#############################################################################
+# Makefile for building: anotherQtGUI
+# Generated by qmake (2.01a) (Qt 4.6.3) on: Thu Aug 5 11:10:44 2010
+# Project: anotherQtGUI.pro
+# Template: app
+#############################################################################
+
+####### Compiler, tools and options
+
+CC = cl
+CXX = cl
+DEFINES = -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT
+CFLAGS = -nologo -Zm200 -Zc:wchar_t- -O2 -MD -W3 $(DEFINES)
+CXXFLAGS = -nologo -Zm200 -Zc:wchar_t- -O2 -MD -GR -EHsc -W3 -w34100 -w34189 $(DEFINES)
+INCPATH = -I"..\..\Qt\4.6.3\include\QtCore" -I"..\..\Qt\4.6.3\include\QtGui" -I"..\..\Qt\4.6.3\include" -I"..\..\OpenCV2.1\include\opencv" -I"..\..\Qt\4.6.3\include\ActiveQt" -I"release" -I"." -I"..\..\Qt\4.6.3\mkspecs\win32-msvc2008"
+LINK = link
+LFLAGS = /LIBPATH:"c:\Qt\4.6.3\lib" /NOLOGO /INCREMENTAL:NO /MANIFEST /MANIFESTFILE:"release\anotherQtGUI.intermediate.manifest" /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'"
+LIBS = c:\Qt\4.6.3\lib\qtmain.lib /LIBPATH:C:\OpenCV2.1\lib C:\OpenCV2.1\lib\cv210.lib C:\OpenCV2.1\lib\cxcore210.lib C:\OpenCV2.1\lib\highgui210.lib c:\Qt\4.6.3\lib\QtGui4.lib c:\Qt\4.6.3\lib\QtCore4.lib
+QMAKE = c:\Qt\4.6.3\bin\qmake.exe
+IDC = c:\Qt\4.6.3\bin\idc.exe
+IDL = midl
+ZIP = zip -r -9
+DEF_FILE =
+RES_FILE =
+COPY = copy /y
+COPY_FILE = $(COPY)
+COPY_DIR = xcopy /s /q /y /i
+DEL_FILE = del
+DEL_DIR = rmdir
+MOVE = move
+CHK_DIR_EXISTS= if not exist
+MKDIR = mkdir
+INSTALL_FILE = $(COPY_FILE)
+INSTALL_PROGRAM = $(COPY_FILE)
+INSTALL_DIR = $(COPY_DIR)
+
+####### Output directory
+
+OBJECTS_DIR = release
+
+####### Files
+
+SOURCES = main.cpp \
+ mainwindow.cpp release\moc_mainwindow.cpp
+OBJECTS = release\main.obj \
+ release\mainwindow.obj \
+ release\moc_mainwindow.obj
+DIST =
+QMAKE_TARGET = anotherQtGUI
+DESTDIR = release\ #avoid trailing-slash linebreak
+TARGET = anotherQtGUI.exe
+DESTDIR_TARGET = release\anotherQtGUI.exe
+
+####### Implicit rules
+
+.SUFFIXES: .c .cpp .cc .cxx
+
+{release}.cpp{release\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{release}.cc{release\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{release}.cxx{release\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{release}.c{release\}.obj::
+ $(CC) -c $(CFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{.}.cpp{release\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{.}.cc{release\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{.}.cxx{release\}.obj::
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+{.}.c{release\}.obj::
+ $(CC) -c $(CFLAGS) $(INCPATH) -Forelease\ @<<
+ $<
+<<
+
+####### Build rules
+
+first: all
+all: Makefile.Release $(DESTDIR_TARGET)
+
+$(DESTDIR_TARGET): ui_mainwindow.h $(OBJECTS)
+ $(LINK) $(LFLAGS) /OUT:$(DESTDIR_TARGET) @<<
+ $(OBJECTS) $(LIBS)
+<<
+ mt.exe -nologo -manifest "release\anotherQtGUI.intermediate.manifest" -outputresource:$(DESTDIR_TARGET);1
+
+
+
+qmake: FORCE
+ @$(QMAKE) -spec ..\..\Qt\4.6.3\mkspecs\win32-msvc2008 -win32 CONFIG+=release -o Makefile.Release anotherQtGUI.pro
+
+dist:
+ $(ZIP) anotherQtGUI.zip $(SOURCES) $(DIST) anotherQtGUI.pro ..\..\Qt\4.6.3\mkspecs\qconfig.pri ..\..\Qt\4.6.3\mkspecs\features\qt_functions.prf ..\..\Qt\4.6.3\mkspecs\features\qt_config.prf ..\..\Qt\4.6.3\mkspecs\features\exclusive_builds.prf ..\..\Qt\4.6.3\mkspecs\features\default_pre.prf ..\..\Qt\4.6.3\mkspecs\features\win32\default_pre.prf ..\..\Qt\4.6.3\mkspecs\features\release.prf ..\..\Qt\4.6.3\mkspecs\features\debug_and_release.prf ..\..\Qt\4.6.3\mkspecs\features\default_post.prf ..\..\Qt\4.6.3\mkspecs\features\win32\default_post.prf ..\..\Qt\4.6.3\mkspecs\features\build_pass.prf ..\..\Qt\4.6.3\mkspecs\features\win32\rtti.prf ..\..\Qt\4.6.3\mkspecs\features\win32\exceptions.prf ..\..\Qt\4.6.3\mkspecs\features\win32\stl.prf ..\..\Qt\4.6.3\mkspecs\features\shared.prf ..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_exe.prf ..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_dll.prf ..\..\Qt\4.6.3\mkspecs\features\warn_on.prf ..\..\Qt\4.6.3\mkspecs\features\qt.prf ..\..\Qt\4.6.3\mkspecs\features\win32\thread.prf ..\..\Qt\4.6.3\mkspecs\features\moc.prf ..\..\Qt\4.6.3\mkspecs\features\win32\windows.prf ..\..\Qt\4.6.3\mkspecs\features\resources.prf ..\..\Qt\4.6.3\mkspecs\features\uic.prf ..\..\Qt\4.6.3\mkspecs\features\yacc.prf ..\..\Qt\4.6.3\mkspecs\features\lex.prf ..\..\Qt\4.6.3\mkspecs\features\incredibuild_xge.prf ..\..\Qt\4.6.3\mkspecs\features\include_source_dir.prf c:\Qt\4.6.3\lib\qtmain.prl HEADERS RESOURCES IMAGES SOURCES OBJECTIVE_SOURCES FORMS YACCSOURCES YACCSOURCES LEXSOURCES
+
+clean: compiler_clean
+ -$(DEL_FILE) release\main.obj release\mainwindow.obj release\moc_mainwindow.obj
+ -$(DEL_FILE) release\anotherQtGUI.intermediate.manifest release\anotherQtGUI.exp
+
+distclean: clean
+ -$(DEL_FILE) $(DESTDIR_TARGET)
+ -$(DEL_FILE) Makefile.Release
+
+check: first
+
+mocclean: compiler_moc_header_clean compiler_moc_source_clean
+
+mocables: compiler_moc_header_make_all compiler_moc_source_make_all
+
+compiler_moc_header_make_all: release\moc_mainwindow.cpp
+compiler_moc_header_clean:
+ -$(DEL_FILE) release\moc_mainwindow.cpp
+release\moc_mainwindow.cpp: mainwindow.h
+ C:\Qt\4.6.3\bin\moc.exe $(DEFINES) $(INCPATH) -D_MSC_VER=1500 -DWIN32 mainwindow.h -o release\moc_mainwindow.cpp
+
+compiler_rcc_make_all:
+compiler_rcc_clean:
+compiler_image_collection_make_all: qmake_image_collection.cpp
+compiler_image_collection_clean:
+ -$(DEL_FILE) qmake_image_collection.cpp
+compiler_moc_source_make_all:
+compiler_moc_source_clean:
+compiler_uic_make_all: ui_mainwindow.h
+compiler_uic_clean:
+ -$(DEL_FILE) ui_mainwindow.h
+ui_mainwindow.h: mainwindow.ui
+ c:\Qt\4.6.3\bin\uic.exe mainwindow.ui -o ui_mainwindow.h
+
+compiler_yacc_decl_make_all:
+compiler_yacc_decl_clean:
+compiler_yacc_impl_make_all:
+compiler_yacc_impl_clean:
+compiler_lex_make_all:
+compiler_lex_clean:
+compiler_clean: compiler_moc_header_clean compiler_uic_clean
+
+
+
+####### Compile
+
+release\main.obj: main.cpp mainwindow.h
+
+release\mainwindow.obj: mainwindow.cpp mainwindow.h \
+ ui_mainwindow.h
+
+release\moc_mainwindow.obj: release\moc_mainwindow.cpp
+
+####### Install
+
+install: FORCE
+
+uninstall: FORCE
+
+FORCE:
+
Index: Chapter 01/anotherQtGUI/Makefile
===================================================================
--- Chapter 01/anotherQtGUI/Makefile (nonexistent)
+++ Chapter 01/anotherQtGUI/Makefile (revision 3)
@@ -0,0 +1,153 @@
+#############################################################################
+# Makefile for building: anotherQtGUI
+# Generated by qmake (2.01a) (Qt 4.6.3) on: Thu Aug 5 11:10:44 2010
+# Project: anotherQtGUI.pro
+# Template: app
+# Command: c:\Qt\4.6.3\bin\qmake.exe -spec ..\..\Qt\4.6.3\mkspecs\win32-msvc2008 -win32 CONFIG+=release -o Makefile anotherQtGUI.pro
+#############################################################################
+
+first: release
+install: release-install
+uninstall: release-uninstall
+MAKEFILE = Makefile
+QMAKE = c:\Qt\4.6.3\bin\qmake.exe
+DEL_FILE = del
+CHK_DIR_EXISTS= if not exist
+MKDIR = mkdir
+COPY = copy /y
+COPY_FILE = $(COPY)
+COPY_DIR = xcopy /s /q /y /i
+INSTALL_FILE = $(COPY_FILE)
+INSTALL_PROGRAM = $(COPY_FILE)
+INSTALL_DIR = $(COPY_DIR)
+DEL_FILE = del
+SYMLINK =
+DEL_DIR = rmdir
+MOVE = move
+CHK_DIR_EXISTS= if not exist
+MKDIR = mkdir
+SUBTARGETS = \
+ release \
+ debug
+
+release: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release
+release-make_default: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release
+release-make_first: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release first
+release-all: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release all
+release-clean: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release clean
+release-distclean: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release distclean
+release-install: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release install
+release-uninstall: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release uninstall
+debug: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug
+debug-make_default: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug
+debug-make_first: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug first
+debug-all: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug all
+debug-clean: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug clean
+debug-distclean: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug distclean
+debug-install: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug install
+debug-uninstall: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug uninstall
+
+Makefile: anotherQtGUI.pro ..\..\Qt\4.6.3\mkspecs\win32-msvc2008\qmake.conf ..\..\Qt\4.6.3\mkspecs\qconfig.pri \
+ ..\..\Qt\4.6.3\mkspecs\features\qt_functions.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\qt_config.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\exclusive_builds.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\default_pre.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\default_pre.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\release.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\debug_and_release.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\default_post.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\default_post.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\rtti.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\exceptions.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\stl.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\shared.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_exe.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_dll.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\warn_on.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\qt.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\thread.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\moc.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\win32\windows.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\resources.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\uic.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\yacc.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\lex.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\incredibuild_xge.prf \
+ ..\..\Qt\4.6.3\mkspecs\features\include_source_dir.prf \
+ c:\Qt\4.6.3\lib\qtmain.prl
+ $(QMAKE) -spec ..\..\Qt\4.6.3\mkspecs\win32-msvc2008 -win32 CONFIG+=release -o Makefile anotherQtGUI.pro
+..\..\Qt\4.6.3\mkspecs\qconfig.pri:
+..\..\Qt\4.6.3\mkspecs\features\qt_functions.prf:
+..\..\Qt\4.6.3\mkspecs\features\qt_config.prf:
+..\..\Qt\4.6.3\mkspecs\features\exclusive_builds.prf:
+..\..\Qt\4.6.3\mkspecs\features\default_pre.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\default_pre.prf:
+..\..\Qt\4.6.3\mkspecs\features\release.prf:
+..\..\Qt\4.6.3\mkspecs\features\debug_and_release.prf:
+..\..\Qt\4.6.3\mkspecs\features\default_post.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\default_post.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\rtti.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\exceptions.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\stl.prf:
+..\..\Qt\4.6.3\mkspecs\features\shared.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_exe.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\embed_manifest_dll.prf:
+..\..\Qt\4.6.3\mkspecs\features\warn_on.prf:
+..\..\Qt\4.6.3\mkspecs\features\qt.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\thread.prf:
+..\..\Qt\4.6.3\mkspecs\features\moc.prf:
+..\..\Qt\4.6.3\mkspecs\features\win32\windows.prf:
+..\..\Qt\4.6.3\mkspecs\features\resources.prf:
+..\..\Qt\4.6.3\mkspecs\features\uic.prf:
+..\..\Qt\4.6.3\mkspecs\features\yacc.prf:
+..\..\Qt\4.6.3\mkspecs\features\lex.prf:
+..\..\Qt\4.6.3\mkspecs\features\incredibuild_xge.prf:
+..\..\Qt\4.6.3\mkspecs\features\include_source_dir.prf:
+c:\Qt\4.6.3\lib\qtmain.prl:
+qmake: qmake_all FORCE
+ @$(QMAKE) -spec ..\..\Qt\4.6.3\mkspecs\win32-msvc2008 -win32 CONFIG+=release -o Makefile anotherQtGUI.pro
+
+qmake_all: FORCE
+
+make_default: release-make_default debug-make_default FORCE
+make_first: release-make_first debug-make_first FORCE
+all: release-all debug-all FORCE
+clean: release-clean debug-clean FORCE
+ -$(DEL_FILE) ".\anotherQtGUI.intermediate.manifest"
+ -$(DEL_FILE) anotherQtGUI.exp
+distclean: release-distclean debug-distclean FORCE
+ -$(DEL_FILE) Makefile
+
+check: first
+
+release-mocclean: $(MAKEFILE).Release
+ $(MAKE) -f $(MAKEFILE).Release mocclean
+debug-mocclean: $(MAKEFILE).Debug
+ $(MAKE) -f $(MAKEFILE).Debug mocclean
+mocclean: release-mocclean debug-mocclean
+
+release-mocables: $(MAKEFILE).Release
+ $(MAKE) -f $(MAKEFILE).Release mocables
+debug-mocables: $(MAKEFILE).Debug
+ $(MAKE) -f $(MAKEFILE).Debug mocables
+mocables: release-mocables debug-mocables
+FORCE:
+
+$(MAKEFILE).Release: Makefile
+$(MAKEFILE).Debug: Makefile
Index: Chapter 01/anotherQtGUI/mainwindow.cpp
===================================================================
--- Chapter 01/anotherQtGUI/mainwindow.cpp (nonexistent)
+++ Chapter 01/anotherQtGUI/mainwindow.cpp (revision 3)
@@ -0,0 +1,55 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 1 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent), ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+ ui->pushButton_2->setEnabled(false);
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::on_pushButton_clicked()
+{
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open Image"), ".", tr("Image Files (*.png *.jpg *.bmp)"));
+
+ image= cv::imread(fileName.toAscii().data());
+
+ if (image.data) {
+ cv::namedWindow("Original Image");
+ cv::imshow("Original Image", image);
+ ui->pushButton_2->setEnabled(true);
+ }
+}
+
+void MainWindow::on_pushButton_2_clicked()
+{
+ cv::flip(image,image,1); // process the image
+
+ cv::cvtColor(image,image,CV_BGR2RGB); // change color channel ordering
+ QImage img= QImage((const unsigned char*)(image.data), // Qt image structure
+ image.cols,image.rows,QImage::Format_RGB888);
+ ui->label->setPixmap(QPixmap::fromImage(img)); // display on label
+ ui->label->resize(ui->label->pixmap()->size()); // resize the label to fit the image
+}
/Chapter 01/anotherQtGUI/mainwindow.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 01/README.txt
===================================================================
--- Chapter 01/README.txt (nonexistent)
+++ Chapter 01/README.txt (revision 3)
@@ -0,0 +1,21 @@
+This directory contains material supporting chapter 1 of the cookbook:
+Computer Vision Programming using the OpenCV Library.
+by Robert Laganiere, Packt Publishing, 2011.
+
+
+File:
+ main1.cpp
+correspond to Recipes:
+Creating an OpenCV project with MS Visual C++
+Creating an OpenCV project with Qt
+
+File:
+ main2.cpp
+correspond to Recipe:
+Loading, displaying and saving images
+
+Files in :
+ myQtGUIApp
+ anotherQtGUI
+correspond to Recipe:
+Creating a GUI application using Qt
/Chapter 01/README.txt
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 10/BGFGSegmentor.h
===================================================================
--- Chapter 10/BGFGSegmentor.h (nonexistent)
+++ Chapter 10/BGFGSegmentor.h (revision 3)
@@ -0,0 +1,76 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 10 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined BGFGSeg
+#define BGFGSeg
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+
+#include "videoprocessor.h"
+
+class BGFGSegmentor : public FrameProcessor {
+
+ cv::Mat gray; // current gray-level image
+ cv::Mat background; // accumulated background
+ cv::Mat backImage; // background image
+ cv::Mat foreground; // foreground image
+ double learningRate; // learning rate in background accumulation
+ int threshold; // threshold for foreground extraction
+
+ public:
+
+ BGFGSegmentor() : threshold(10), learningRate(0.01) {}
+
+ // Set the threshold used to declare a foreground
+ void setThreshold(int t) {
+
+ threshold= t;
+ }
+
+ // Set the learning rate
+ void setLearningRate(double r) {
+
+ learningRate= r;
+ }
+
+ // processing method
+ void process(cv:: Mat &frame, cv:: Mat &output) {
+
+ // convert to gray-level image
+ cv::cvtColor(frame, gray, CV_BGR2GRAY);
+
+ // initialize background to 1st frame
+ if (background.empty())
+ gray.convertTo(background, CV_32F);
+
+ // convert background to 8U
+ background.convertTo(backImage,CV_8U);
+
+ // compute difference between current image and background
+ cv::absdiff(backImage,gray,foreground);
+
+ // apply threshold to foreground image
+ cv::threshold(foreground,output,threshold,255,cv::THRESH_BINARY_INV);
+
+ // accumulate background
+ cv::accumulateWeighted(gray, background, learningRate, output);
+ }
+};
+
+#endif
/Chapter 10/BGFGSegmentor.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 10/tracking.cpp
===================================================================
--- Chapter 10/tracking.cpp (nonexistent)
+++ Chapter 10/tracking.cpp (revision 3)
@@ -0,0 +1,159 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 10 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/features2d/features2d.hpp>
+#include <opencv2/video/tracking.hpp>
+
+#include "featuretracker.h"
+
+int main()
+{
+ // Create video procesor instance
+ VideoProcessor processor;
+
+ // Create feature tracker instance
+ FeatureTracker tracker;
+
+ // Open video file
+ processor.setInput("../bike.avi");
+
+ // set frame processor
+ processor.setFrameProcessor(&tracker);
+
+ // Declare a window to display the video
+ processor.displayOutput("Tracked Features");
+
+ // Play the video at the original frame rate
+ processor.setDelay(1000./processor.getFrameRate());
+
+ // Start the process
+ processor.run();
+
+ cv::waitKey();
+ /*
+ // Open the video file
+ cv::VideoCapture capture("../bike.avi");
+ // check if video successfully opened
+ if (!capture.isOpened())
+ return 1;
+
+ // Get the frame rate
+ double rate= capture.get(CV_CAP_PROP_FPS);
+
+ bool stop(false);
+ cv::Mat frame; // current video frame
+ cv::namedWindow("Extracted Frame");
+
+ // Delay between each frame
+ // corresponds to video frame rate
+ int delay= 1000/rate/2;
+
+
+
+ cv::Mat gray,gray_prev;
+ std::vector<cv::Point2f> points[2];
+ std::vector<cv::Point2f> features;
+ const int MAX_COUNT = 500;
+ cv::Size winSize(10,10);
+ cv::TermCriteria termcrit(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03);
+ bool firstframe =true;
+
+
+
+ // for all frames in video
+ while (!stop) {
+
+ // read next frame if any
+ if (!capture.read(frame))
+ break;
+
+
+ cv::cvtColor(frame, gray, CV_BGR2GRAY);
+ if(firstframe)
+ {
+ cv::goodFeaturesToTrack(gray, features, MAX_COUNT, 0.01, 10, cv::Mat(), 3, 0, 0.04);
+ cv::cornerSubPix(gray, features, winSize, cv::Size(-1,-1), termcrit);
+ points[0].insert(points[0].end(),features.begin(),features.end());
+ firstframe=false;
+ }
+
+ {
+ std::vector<uchar> status;
+ std::vector<float> err;
+ if(gray_prev.empty())
+ gray.copyTo(gray_prev);
+ cv::calcOpticalFlowPyrLK(gray_prev, gray, points[0], points[1], status, err, winSize,3, termcrit, 0);
+ size_t i, k;
+ for( i = k = 0; i < points[1].size(); i++ )
+ {
+ if( !status[i] )
+ continue;
+ if ((abs(points[0][i].x-points[1][i].x)+(abs(points[0][i].y-points[1][i].y))<2))
+ continue;
+
+ cv::line( frame, points[0][i],points[1][i], cv::Scalar(0,255,0));
+ points[1][k++] = points[1][i];
+ cv::circle( frame, points[1][i], 3, cv::Scalar(0,255,0), -1, 8);
+ }
+ points[1].resize(k);
+ }
+ if(points[1].size()<=10)
+ firstframe=true;
+ std::swap(points[1], points[0]);
+ cv::swap(gray_prev, gray);
+
+
+ cv::imshow("Extracted Frame",frame);
+
+ // introduce a delay
+ // or press key to stop
+ if (cv::waitKey(delay)>=0)
+ stop= true;
+ }
+
+ // Close the video file
+ capture.release();
+
+ cv::waitKey();
+
+
+ // Create instance
+ VideoProcessor processor;
+ // Open video file
+ processor.setInput("../bike.avi");
+ // Output filename
+// processor.setOutput("../output/bikeOut",".jpg");
+
+ // Declare a window to display the video
+ processor.displayInput("Current Frame");
+ processor.displayOutput("Output Frame");
+
+ // Play the video at the original frame rate
+ processor.setDelay(1000./processor.getFrameRate());
+
+ // Set the frame processor callback function
+ processor.setFrameProcessor(draw);
+
+ // Start the process
+ processor.run();
+
+ cv::waitKey(5000);*/
+}
\ No newline at end of file
/Chapter 10/tracking.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 10/videoprocessing.cpp
===================================================================
--- Chapter 10/videoprocessing.cpp (nonexistent)
+++ Chapter 10/videoprocessing.cpp (revision 3)
@@ -0,0 +1,137 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 10 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+#include "videoprocessor.h"
+
+void draw(cv::Mat& img, cv::Mat& out) {
+
+ img.copyTo(out);
+ cv::circle(out, cv::Point(100,100),5,cv::Scalar(255,0,0),2);
+}
+
+void canny(cv::Mat& img, cv::Mat& out) {
+
+ // Convert to gray
+ cv::cvtColor(img,out,CV_BGR2GRAY);
+ // Compute Canny edges
+ cv::Canny(out,out,100,200);
+ // Invert the image
+ cv::threshold(out,out,128,255,cv::THRESH_BINARY_INV);
+}
+
+int main()
+{
+ // Open the video file
+ cv::VideoCapture capture("../bike.avi");
+ // check if video successfully opened
+ if (!capture.isOpened())
+ return 1;
+
+ // Get the frame rate
+ double rate= capture.get(CV_CAP_PROP_FPS);
+
+ bool stop(false);
+ cv::Mat frame; // current video frame
+ cv::namedWindow("Extracted Frame");
+
+ // Delay between each frame
+ // corresponds to video frame rate
+ int delay= 1000/rate;
+
+ // for all frames in video
+ while (!stop) {
+
+ // read next frame if any
+ if (!capture.read(frame))
+ break;
+
+ cv::imshow("Extracted Frame",frame);
+
+ // introduce a delay
+ // or press key to stop
+ if (cv::waitKey(delay)>=0)
+ stop= true;
+ }
+
+ // Close the video file
+ capture.release();
+
+ cv::waitKey();
+
+ // Now using the VideoProcessor class
+
+ // Create instance
+ VideoProcessor processor;
+ // Open video file
+ processor.setInput("../bike.avi");
+ // Declare a window to display the video
+ processor.displayInput("Input Video");
+ processor.displayOutput("Output Video");
+ // Play the video at the original frame rate
+ processor.setDelay(1000./processor.getFrameRate());
+ // Set the frame processor callback function
+ processor.setFrameProcessor(canny);
+ // Start the process
+ processor.run();
+ cv::waitKey();
+
+ // Second test
+ // Create instance
+ // VideoProcessor processor;
+ // Open video file
+ processor.setInput("../bike.avi");
+
+ // Get basic info about video file
+ cv::Size size= processor.getFrameSize();
+ std::cout << size.width << " " << size.height << std::endl;
+ std::cout << processor.getFrameRate() << std::endl;
+ std::cout << processor.getTotalFrameCount() << std::endl;
+ std::cout << processor.getFrameNumber() << std::endl;
+ std::cout << processor.getPositionMS() << std::endl;
+
+ // No processing
+ processor.dontCallProcess();
+ // Output filename
+// processor.setOutput("../output/bikeOut",".jpg");
+ char codec[4];
+ processor.setOutput("../output/bike.avi",processor.getCodec(codec),processor.getFrameRate());
+ std::cout << "Codec: " << codec[0] << codec[1] << codec[2] << codec[3] << std::endl;
+
+ // Position the stream at frame 300
+ // processor.setFrameNumber(300);
+ // processor.stopAtFrameNo(120);
+
+ // Declare a window to display the video
+ processor.displayInput("Current Frame");
+ processor.displayOutput("Output Frame");
+
+ // Play the video at the original frame rate
+ processor.setDelay(1000./processor.getFrameRate());
+
+ // Start the process
+ processor.run();
+
+ std::cout << processor.getFrameNumber() << std::endl;
+ std::cout << processor.getPositionMS() << std::endl;
+
+ cv::waitKey();
+}
\ No newline at end of file
/Chapter 10/videoprocessing.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 10/README.txt
===================================================================
--- Chapter 10/README.txt (nonexistent)
+++ Chapter 10/README.txt (revision 3)
@@ -0,0 +1,23 @@
+This directory contains material supporting chapter 10 of the cookbook:
+Computer Vision Programming using the OpenCV Library.
+by Robert Laganiere, Packt Publishing, 2011.
+
+Files:
+ videoprocessing.cpp
+ videoprocessor.h
+correspond to Recipes:
+Reading Video Sequences
+Processing the Video Frames
+Writing Video Sequences
+
+Files:
+ featuretracker.h
+ tracking.cpp
+correspond to Recipe:
+Tracking Feature Points in Video
+
+Files:
+ BGFGSegmentor.h
+ foreground.cpp
+correspond to Recipe:
+Extracting the Foreground Objects in Video
/Chapter 10/README.txt
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 10/foreground.cpp
===================================================================
--- Chapter 10/foreground.cpp (nonexistent)
+++ Chapter 10/foreground.cpp (revision 3)
@@ -0,0 +1,95 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 10 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/video/background_segm.hpp>
+
+#include "videoprocessor.h"
+#include "BGFGSegmentor.h"
+
+int main()
+{
+ // Open the video file
+ cv::VideoCapture capture("../bike.avi");
+ // check if video successfully opened
+ if (!capture.isOpened())
+ return 0;
+
+ // current video frame
+ cv::Mat frame;
+ // foreground binary image
+ cv::Mat foreground;
+
+ cv::namedWindow("Extracted Foreground");
+
+ // The Mixture of Gaussian object
+ // used with all default parameters
+ cv::BackgroundSubtractorMOG mog;
+
+ bool stop(false);
+ // for all frames in video
+ while (!stop) {
+
+ // read next frame if any
+ if (!capture.read(frame))
+ break;
+
+ // update the background
+ // and return the foreground
+ mog(frame,foreground,0.01);
+
+ // Complement the image
+ cv::threshold(foreground,foreground,128,255,cv::THRESH_BINARY_INV);
+
+ // show foreground
+ cv::imshow("Extracted Foreground",foreground);
+
+ // introduce a delay
+ // or press key to stop
+ if (cv::waitKey(10)>=0)
+ stop= true;
+ }
+
+ cv::waitKey();
+
+ // Create video procesor instance
+ VideoProcessor processor;
+
+ // Create background/foreground segmentor
+ BGFGSegmentor segmentor;
+ segmentor.setThreshold(25);
+
+ // Open video file
+ processor.setInput("../bike.avi");
+
+ // set frame processor
+ processor.setFrameProcessor(&segmentor);
+
+ // Declare a window to display the video
+ processor.displayOutput("Extracted Foreground");
+
+ // Play the video at the original frame rate
+ processor.setDelay(1000./processor.getFrameRate());
+
+ // Start the process
+ processor.run();
+
+ cv::waitKey();
+}
\ No newline at end of file
/Chapter 10/foreground.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 10/videoprocessor.h
===================================================================
--- Chapter 10/videoprocessor.h (nonexistent)
+++ Chapter 10/videoprocessor.h (revision 3)
@@ -0,0 +1,497 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 10 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined VPROCESSOR
+#define VPROCESSOR
+
+#include <iostream>
+#include <iomanip>
+#include <sstream>
+#include <string>
+#include <vector>
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+// The frame processor interface
+class FrameProcessor {
+
+ public:
+ // processing method
+ virtual void process(cv:: Mat &input, cv:: Mat &output)= 0;
+};
+
+class VideoProcessor {
+
+ private:
+
+ // the OpenCV video capture object
+ cv::VideoCapture capture;
+ // the callback function to be called
+ // for the processing of each frame
+ void (*process)(cv::Mat&, cv::Mat&);
+ // the pointer to the class implementing
+ // the FrameProcessor interface
+ FrameProcessor *frameProcessor;
+ // a bool to determine if the
+ // process callback will be called
+ bool callIt;
+ // Input display window name
+ std::string windowNameInput;
+ // Output display window name
+ std::string windowNameOutput;
+ // delay between each frame processing
+ int delay;
+ // number of processed frames
+ long fnumber;
+ // stop at this frame number
+ long frameToStop;
+ // to stop the processing
+ bool stop;
+
+ // vector of image filename to be used as input
+ std::vector<std::string> images;
+ // image vector iterator
+ std::vector<std::string>::const_iterator itImg;
+
+ // the OpenCV video writer object
+ cv::VideoWriter writer;
+ // output filename
+ std::string outputFile;
+
+ // current index for output images
+ int currentIndex;
+ // number of digits in output image filename
+ int digits;
+ // extension of output images
+ std::string extension;
+
+ // to get the next frame
+ // could be: video file; camera; vector of images
+ bool readNextFrame(cv::Mat& frame) {
+
+ if (images.size()==0)
+ return capture.read(frame);
+ else {
+
+ if (itImg != images.end()) {
+
+ frame= cv::imread(*itImg);
+ itImg++;
+ return frame.data != 0;
+ }
+ }
+ }
+
+ // to write the output frame
+ // could be: video file or images
+ void writeNextFrame(cv::Mat& frame) {
+
+ if (extension.length()) { // then we write images
+
+ std::stringstream ss;
+ ss << outputFile << std::setfill('0') << std::setw(digits) << currentIndex++ << extension;
+ cv::imwrite(ss.str(),frame);
+
+ } else { // then write video file
+
+ writer.write(frame);
+ }
+ }
+
+ public:
+
+ // Constructor setting the default values
+ VideoProcessor() : callIt(false), delay(-1),
+ fnumber(0), stop(false), digits(0), frameToStop(-1),
+ process(0), frameProcessor(0) {}
+
+ // set the name of the video file
+ bool setInput(std::string filename) {
+
+ fnumber= 0;
+ // In case a resource was already
+ // associated with the VideoCapture instance
+ capture.release();
+ images.clear();
+
+ // Open the video file
+ return capture.open(filename);
+ }
+
+ // set the camera ID
+ bool setInput(int id) {
+
+ fnumber= 0;
+ // In case a resource was already
+ // associated with the VideoCapture instance
+ capture.release();
+ images.clear();
+
+ // Open the video file
+ return capture.open(id);
+ }
+
+ // set the vector of input images
+ bool setInput(const std::vector<std::string>& imgs) {
+
+ fnumber= 0;
+ // In case a resource was already
+ // associated with the VideoCapture instance
+ capture.release();
+
+ // the input will be this vector of images
+ images= imgs;
+ itImg= images.begin();
+
+ return true;
+ }
+
+ // set the output video file
+ // by default the same parameters than input video will be used
+ bool setOutput(const std::string &filename, int codec=0, double framerate=0.0, bool isColor=true) {
+
+ outputFile= filename;
+ extension.clear();
+
+ if (framerate==0.0)
+ framerate= getFrameRate(); // same as input
+
+ char c[4];
+ // use same codec as input
+ if (codec==0) {
+ codec= getCodec(c);
+ }
+
+ // Open output video
+ return writer.open(outputFile, // filename
+ codec, // codec to be used
+ framerate, // frame rate of the video
+ getFrameSize(), // frame size
+ isColor); // color video?
+ }
+
+ // set the output as a series of image files
+ // extension must be ".jpg", ".bmp" ...
+ bool setOutput(const std::string &filename, // filename prefix
+ const std::string &ext, // image file extension
+ int numberOfDigits=3, // number of digits
+ int startIndex=0) { // start index
+
+ // number of digits must be positive
+ if (numberOfDigits<0)
+ return false;
+
+ // filenames and their common extension
+ outputFile= filename;
+ extension= ext;
+
+ // number of digits in the file numbering scheme
+ digits= numberOfDigits;
+ // start numbering at this index
+ currentIndex= startIndex;
+
+ return true;
+ }
+
+ // set the callback function that will be called for each frame
+ void setFrameProcessor(void (*frameProcessingCallback)(cv::Mat&, cv::Mat&)) {
+
+ // invalidate frame processor class instance
+ frameProcessor= 0;
+ // this is the frame processor function that will be called
+ process= frameProcessingCallback;
+ callProcess();
+ }
+
+ // set the instance of the class that implements the FrameProcessor interface
+ void setFrameProcessor(FrameProcessor* frameProcessorPtr) {
+
+ // invalidate callback function
+ process= 0;
+ // this is the frame processor instance that will be called
+ frameProcessor= frameProcessorPtr;
+ callProcess();
+ }
+
+ // stop streaming at this frame number
+ void stopAtFrameNo(long frame) {
+
+ frameToStop= frame;
+ }
+
+ // process callback to be called
+ void callProcess() {
+
+ callIt= true;
+ }
+
+ // do not call process callback
+ void dontCallProcess() {
+
+ callIt= false;
+ }
+
+ // to display the processed frames
+ void displayInput(std::string wn) {
+
+ windowNameInput= wn;
+ cv::namedWindow(windowNameInput);
+ }
+
+ // to display the processed frames
+ void displayOutput(std::string wn) {
+
+ windowNameOutput= wn;
+ cv::namedWindow(windowNameOutput);
+ }
+
+ // do not display the processed frames
+ void dontDisplay() {
+
+ cv::destroyWindow(windowNameInput);
+ cv::destroyWindow(windowNameOutput);
+ windowNameInput.clear();
+ windowNameOutput.clear();
+ }
+
+ // set a delay between each frame
+ // 0 means wait at each frame
+ // negative means no delay
+ void setDelay(int d) {
+
+ delay= d;
+ }
+
+ // a count is kept of the processed frames
+ long getNumberOfProcessedFrames() {
+
+ return fnumber;
+ }
+
+ // return the size of the video frame
+ cv::Size getFrameSize() {
+
+ if (images.size()==0) {
+
+ // get size of from the capture device
+ int w= static_cast<int>(capture.get(CV_CAP_PROP_FRAME_WIDTH));
+ int h= static_cast<int>(capture.get(CV_CAP_PROP_FRAME_HEIGHT));
+
+ return cv::Size(w,h);
+
+ } else { // if input is vector of images
+
+ cv::Mat tmp= cv::imread(images[0]);
+ if (!tmp.data) return cv::Size(0,0);
+ else return tmp.size();
+ }
+ }
+
+ // return the frame number of the next frame
+ long getFrameNumber() {
+
+ if (images.size()==0) {
+
+ // get info of from the capture device
+ long f= static_cast<long>(capture.get(CV_CAP_PROP_POS_FRAMES));
+ return f;
+
+ } else { // if input is vector of images
+
+ return static_cast<long>(itImg-images.begin());
+ }
+ }
+
+ // return the position in ms
+ double getPositionMS() {
+
+ // undefined for vector of images
+ if (images.size()!=0) return 0.0;
+
+ double t= capture.get(CV_CAP_PROP_POS_MSEC);
+ return t;
+ }
+
+ // return the frame rate
+ double getFrameRate() {
+
+ // undefined for vector of images
+ if (images.size()!=0) return 0;
+
+ double r= capture.get(CV_CAP_PROP_FPS);
+ return r;
+ }
+
+ // return the number of frames in video
+ long getTotalFrameCount() {
+
+ // for vector of images
+ if (images.size()!=0) return images.size();
+
+ long t= capture.get(CV_CAP_PROP_FRAME_COUNT);
+ return t;
+ }
+
+ // get the codec of input video
+ int getCodec(char codec[4]) {
+
+ // undefined for vector of images
+ if (images.size()!=0) return -1;
+
+ union {
+ int value;
+ char code[4]; } returned;
+
+ returned.value= static_cast<int>(capture.get(CV_CAP_PROP_FOURCC));
+
+ codec[0]= returned.code[0];
+ codec[1]= returned.code[1];
+ codec[2]= returned.code[2];
+ codec[3]= returned.code[3];
+
+ return returned.value;
+ }
+
+ // go to this frame number
+ bool setFrameNumber(long pos) {
+
+ // for vector of images
+ if (images.size()!=0) {
+
+ // move to position in vector
+ itImg= images.begin() + pos;
+ // is it a valid position?
+ if (pos < images.size())
+ return true;
+ else
+ return false;
+
+ } else { // if input is a capture device
+
+ return capture.set(CV_CAP_PROP_POS_FRAMES, pos);
+ }
+ }
+
+ // go to this position
+ bool setPositionMS(double pos) {
+
+ // not defined in vector of images
+ if (images.size()!=0)
+ return false;
+ else
+ return capture.set(CV_CAP_PROP_POS_MSEC, pos);
+ }
+
+ // go to this position expressed in fraction of total film length
+ bool setRelativePosition(double pos) {
+
+ // for vector of images
+ if (images.size()!=0) {
+
+ // move to position in vector
+ long posI= static_cast<long>(pos*images.size()+0.5);
+ itImg= images.begin() + posI;
+ // is it a valid position?
+ if (posI < images.size())
+ return true;
+ else
+ return false;
+
+ } else { // if input is a capture device
+
+ return capture.set(CV_CAP_PROP_POS_AVI_RATIO, pos);
+ }
+ }
+
+ // Stop the processing
+ void stopIt() {
+
+ stop= true;
+ }
+
+ // Is the process stopped?
+ bool isStopped() {
+
+ return stop;
+ }
+
+ // Is a capture device opened?
+ bool isOpened() {
+
+ return capture.isOpened() || !images.empty();
+ }
+
+ // to grab (and process) the frames of the sequence
+ void run() {
+
+ // current frame
+ cv::Mat frame;
+ // output frame
+ cv::Mat output;
+
+ // if no capture device has been set
+ if (!isOpened())
+ return;
+
+ stop= false;
+
+ while (!isStopped()) {
+
+ // read next frame if any
+ if (!readNextFrame(frame))
+ break;
+
+ // display input frame
+ if (windowNameInput.length()!=0)
+ cv::imshow(windowNameInput,frame);
+
+ // calling the process function or method
+ if (callIt) {
+
+ // process the frame
+ if (process)
+ process(frame, output);
+ else if (frameProcessor)
+ frameProcessor->process(frame,output);
+ // increment frame number
+ fnumber++;
+
+ } else {
+
+ output= frame;
+ }
+
+ // write output sequence
+ if (outputFile.length()!=0)
+ writeNextFrame(output);
+
+ // display output frame
+ if (windowNameOutput.length()!=0)
+ cv::imshow(windowNameOutput,output);
+
+ // introduce a delay
+ if (delay>=0 && cv::waitKey(delay)>=0)
+ stopIt();
+
+ // check if we should stop
+ if (frameToStop>=0 && getFrameNumber()==frameToStop)
+ stopIt();
+ }
+ }
+};
+
+#endif
/Chapter 10/videoprocessor.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 10/featuretracker.h
===================================================================
--- Chapter 10/featuretracker.h (nonexistent)
+++ Chapter 10/featuretracker.h (revision 3)
@@ -0,0 +1,141 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 10 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined FTRACKER
+#define FTRACKER
+
+#include <string>
+#include <vector>
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/features2d/features2d.hpp>
+#include <opencv2/video/tracking.hpp>
+
+#include "videoprocessor.h"
+
+class FeatureTracker : public FrameProcessor {
+
+ cv::Mat gray; // current gray-level image
+ cv::Mat gray_prev; // previous gray-level image
+ std::vector<cv::Point2f> points[2]; // tracked features from 0->1
+ std::vector<cv::Point2f> initial; // initial position of tracked points
+ std::vector<cv::Point2f> features; // detected features
+ int max_count; // maximum number of features to detect
+ double qlevel; // quality level for feature detection
+ double minDist; // minimum distance between two feature points
+ std::vector<uchar> status; // status of tracked features
+ std::vector<float> err; // error in tracking
+
+ public:
+
+ FeatureTracker() : max_count(500), qlevel(0.01), minDist(10.) {}
+
+ // processing method
+ void process(cv:: Mat &frame, cv:: Mat &output) {
+
+ // convert to gray-level image
+ cv::cvtColor(frame, gray, CV_BGR2GRAY);
+ frame.copyTo(output);
+
+ // 1. if new feature points must be added
+ if(addNewPoints())
+ {
+ // detect feature points
+ detectFeaturePoints();
+ // add the detected features to the currently tracked features
+ points[0].insert(points[0].end(),features.begin(),features.end());
+ initial.insert(initial.end(),features.begin(),features.end());
+ }
+
+ // for first image of the sequence
+ if(gray_prev.empty())
+ gray.copyTo(gray_prev);
+
+ // 2. track features
+ cv::calcOpticalFlowPyrLK(gray_prev, gray, // 2 consecutive images
+ points[0], // input point position in first image
+ points[1], // output point postion in the second image
+ status, // tracking success
+ err); // tracking error
+
+ // 2. loop over the tracked points to reject the undesirables
+ int k=0;
+ for( int i= 0; i < points[1].size(); i++ ) {
+
+ // do we keep this point?
+ if (acceptTrackedPoint(i)) {
+
+ // keep this point in vector
+ initial[k]= initial[i];
+ points[1][k++] = points[1][i];
+ }
+ }
+
+ // eliminate unsuccesful points
+ points[1].resize(k);
+ initial.resize(k);
+
+ // 3. handle the accepted tracked points
+ handleTrackedPoints(frame, output);
+
+ // 4. current points and image become previous ones
+ std::swap(points[1], points[0]);
+ cv::swap(gray_prev, gray);
+ }
+
+ // feature point detection
+ void detectFeaturePoints() {
+
+ // detect the features
+ cv::goodFeaturesToTrack(gray, // the image
+ features, // the output detected features
+ max_count, // the maximum number of features
+ qlevel, // quality level
+ minDist); // min distance between two features
+ }
+
+ // determine if new points should be added
+ bool addNewPoints() {
+
+ // if too few points
+ return points[0].size()<=10;
+ }
+
+ // determine which tracked point should be accepted
+ bool acceptTrackedPoint(int i) {
+
+ return status[i] &&
+ // if point has moved
+ (abs(points[0][i].x-points[1][i].x)+
+ (abs(points[0][i].y-points[1][i].y))>2);
+ }
+
+ // handle the currently tracked points
+ void handleTrackedPoints(cv:: Mat &frame, cv:: Mat &output) {
+
+ // for all tracked points
+ for(int i= 0; i < points[1].size(); i++ ) {
+
+ // draw line and circle
+ cv::line(output, initial[i], points[1][i], cv::Scalar(255,255,255));
+ cv::circle(output, points[1][i], 3, cv::Scalar(255,255,255),-1);
+ }
+ }
+};
+
+#endif
/Chapter 10/featuretracker.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 02/addImages.cpp
===================================================================
--- Chapter 02/addImages.cpp (nonexistent)
+++ Chapter 02/addImages.cpp (revision 3)
@@ -0,0 +1,120 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 2 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+
+#include <vector>
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+
+int main()
+{
+ cv::Mat image1;
+ cv::Mat image2;
+
+ image1= cv::imread("boldt.jpg");
+ image2= cv::imread("rain.jpg");
+ if (!image1.data)
+ return 0;
+ if (!image2.data)
+ return 0;
+
+ cv::namedWindow("Image 1");
+ cv::imshow("Image 1",image1);
+ cv::namedWindow("Image 2");
+ cv::imshow("Image 2",image2);
+
+ cv::Mat result;
+ cv::addWeighted(image1,0.7,image2,0.9,0.,result);
+
+ cv::namedWindow("result");
+ cv::imshow("result",result);
+
+ // using overloaded operator
+ result= 0.7*image1+0.9*image2;
+
+ cv::namedWindow("result with operators");
+ cv::imshow("result with operators",result);
+
+ image2= cv::imread("rain.jpg",0);
+
+ // create vector of 3 images
+ std::vector<cv::Mat> planes;
+ // split 1 3-channel image into 3 1-channel images
+ cv::split(image1,planes);
+ // add to blue channel
+ planes[0]+= image2;
+ // merge the 3 1-channel images into 1 3-channel image
+ cv::merge(planes,result);
+
+ cv::namedWindow("Result on blue channel");
+ cv::imshow("Result on blue channel",result);
+
+ // read images
+ cv::Mat image= cv::imread("boldt.jpg");
+ cv::Mat logo= cv::imread("logo.bmp");
+
+ // define image ROI
+ cv::Mat imageROI;
+ imageROI= image(cv::Rect(385,270,logo.cols,logo.rows));
+
+ // add logo to image
+ cv::addWeighted(imageROI,1.0,logo,0.3,0.,imageROI);
+
+ // show result
+ cv::namedWindow("with logo");
+ cv::imshow("with logo",image);
+
+ // read images
+ image= cv::imread("boldt.jpg");
+ logo= cv::imread("logo.bmp");
+
+ // define ROI
+ imageROI= image(cv::Rect(385,270,logo.cols,logo.rows));
+
+ // load the mask (must be gray-level)
+ cv::Mat mask= cv::imread("logo.bmp",0);
+
+ // copy to ROI with mask
+ logo.copyTo(imageROI,mask);
+
+ // show result
+ cv::namedWindow("with logo 2");
+ cv::imshow("with logo 2",image);
+
+ // read images
+ logo= cv::imread("logo.bmp",0);
+ image1= cv::imread("boldt.jpg");
+
+ // split 3-channel image into 3 1-channel images
+ std::vector<cv::Mat> channels;
+ cv::split(image1,channels);
+
+ imageROI= channels.at(1);
+
+ cv::addWeighted(imageROI(cv::Rect(385,270,logo.cols,logo.rows)),1.0,
+ logo,0.5,0.,imageROI(cv::Rect(385,270,logo.cols,logo.rows)));
+
+ cv::merge(channels,image1);
+
+ cv::namedWindow("with logo 3");
+ cv::imshow("with logo 3",image1);
+
+ cv::waitKey();
+
+ return 0;
+}
/Chapter 02/addImages.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 02/colorReduce.cpp
===================================================================
--- Chapter 02/colorReduce.cpp (nonexistent)
+++ Chapter 02/colorReduce.cpp (revision 3)
@@ -0,0 +1,507 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 2 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+// using .ptr and []
+void colorReduce0(cv::Mat &image, int div=64) {
+
+ int nl= image.rows; // number of lines
+ int nc= image.cols * image.channels(); // total number of elements per line
+
+ for (int j=0; j<nl; j++) {
+
+ uchar* data= image.ptr<uchar>(j);
+
+ for (int i=0; i<nc; i++) {
+
+ // process each pixel ---------------------
+
+ data[i]= data[i]/div*div + div/2;
+
+ // end of pixel processing ----------------
+
+ } // end of line
+ }
+}
+
+// using .ptr and * ++
+void colorReduce1(cv::Mat &image, int div=64) {
+
+ int nl= image.rows; // number of lines
+ int nc= image.cols * image.channels(); // total number of elements per line
+
+ for (int j=0; j<nl; j++) {
+
+ uchar* data= image.ptr<uchar>(j);
+
+ for (int i=0; i<nc; i++) {
+
+ // process each pixel ---------------------
+
+ *data++= *data/div*div + div/2;
+
+ // end of pixel processing ----------------
+
+ } // end of line
+ }
+}
+
+// using .ptr and * ++ and modulo
+void colorReduce2(cv::Mat &image, int div=64) {
+
+ int nl= image.rows; // number of lines
+ int nc= image.cols * image.channels(); // total number of elements per line
+
+ for (int j=0; j<nl; j++) {
+
+ uchar* data= image.ptr<uchar>(j);
+
+ for (int i=0; i<nc; i++) {
+
+ // process each pixel ---------------------
+
+ int v= *data;
+ *data++= v - v%div + div/2;
+
+ // end of pixel processing ----------------
+
+ } // end of line
+ }
+}
+
+// using .ptr and * ++ and bitwise
+void colorReduce3(cv::Mat &image, int div=64) {
+
+ int nl= image.rows; // number of lines
+ int nc= image.cols * image.channels(); // total number of elements per line
+ int n= static_cast<int>(log(static_cast<double>(div))/log(2.0));
+ // mask used to round the pixel value
+ uchar mask= 0xFF<<n; // e.g. for div=16, mask= 0xF0
+
+ for (int j=0; j<nl; j++) {
+
+ uchar* data= image.ptr<uchar>(j);
+
+ for (int i=0; i<nc; i++) {
+
+ // process each pixel ---------------------
+
+ *data++= *data&mask + div/2;
+
+ // end of pixel processing ----------------
+
+ } // end of line
+ }
+}
+
+
+// direct pointer arithmetic
+void colorReduce4(cv::Mat &image, int div=64) {
+
+ int nl= image.rows; // number of lines
+ int nc= image.cols * image.channels(); // total number of elements per line
+ int n= static_cast<int>(log(static_cast<double>(div))/log(2.0));
+ int step= image.step; // effective width
+ // mask used to round the pixel value
+ uchar mask= 0xFF<<n; // e.g. for div=16, mask= 0xF0
+
+ // get the pointer to the image buffer
+ uchar *data= image.data;
+
+ for (int j=0; j<nl; j++) {
+
+ for (int i=0; i<nc; i++) {
+
+ // process each pixel ---------------------
+
+ *(data+i)= *data&mask + div/2;
+
+ // end of pixel processing ----------------
+
+ } // end of line
+
+ data+= step; // next line
+ }
+}
+
+// using .ptr and * ++ and bitwise with image.cols * image.channels()
+void colorReduce5(cv::Mat &image, int div=64) {
+
+ int nl= image.rows; // number of lines
+ int n= static_cast<int>(log(static_cast<double>(div))/log(2.0));
+ // mask used to round the pixel value
+ uchar mask= 0xFF<<n; // e.g. for div=16, mask= 0xF0
+
+ for (int j=0; j<nl; j++) {
+
+ uchar* data= image.ptr<uchar>(j);
+
+ for (int i=0; i<image.cols * image.channels(); i++) {
+
+ // process each pixel ---------------------
+
+ *data++= *data&mask + div/2;
+
+ // end of pixel processing ----------------
+
+ } // end of line
+ }
+}
+
+// using .ptr and * ++ and bitwise (continuous)
+void colorReduce6(cv::Mat &image, int div=64) {
+
+ int nl= image.rows; // number of lines
+ int nc= image.cols * image.channels(); // total number of elements per line
+
+ if (image.isContinuous()) {
+ // then no padded pixels
+ nc= nc*nl;
+ nl= 1; // it is now a 1D array
+ }
+
+ int n= static_cast<int>(log(static_cast<double>(div))/log(2.0));
+ // mask used to round the pixel value
+ uchar mask= 0xFF<<n; // e.g. for div=16, mask= 0xF0
+
+ for (int j=0; j<nl; j++) {
+
+ uchar* data= image.ptr<uchar>(j);
+
+ for (int i=0; i<nc; i++) {
+
+ // process each pixel ---------------------
+
+ *data++= *data&mask + div/2;
+
+ // end of pixel processing ----------------
+
+ } // end of line
+ }
+}
+
+// using .ptr and * ++ and bitwise (continuous+channels)
+void colorReduce7(cv::Mat &image, int div=64) {
+
+ int nl= image.rows; // number of lines
+ int nc= image.cols ; // number of columns
+
+ if (image.isContinuous()) {
+ // then no padded pixels
+ nc= nc*nl;
+ nl= 1; // it is now a 1D array
+ }
+
+ int n= static_cast<int>(log(static_cast<double>(div))/log(2.0));
+ // mask used to round the pixel value
+ uchar mask= 0xFF<<n; // e.g. for div=16, mask= 0xF0
+
+ for (int j=0; j<nl; j++) {
+
+ uchar* data= image.ptr<uchar>(j);
+
+ for (int i=0; i<nc; i++) {
+
+ // process each pixel ---------------------
+
+ *data++= *data&mask + div/2;
+ *data++= *data&mask + div/2;
+ *data++= *data&mask + div/2;
+
+ // end of pixel processing ----------------
+
+ } // end of line
+ }
+}
+
+
+// using Mat_ iterator
+void colorReduce8(cv::Mat &image, int div=64) {
+
+ // get iterators
+ cv::Mat_<cv::Vec3b>::iterator it= image.begin<cv::Vec3b>();
+ cv::Mat_<cv::Vec3b>::iterator itend= image.end<cv::Vec3b>();
+
+ for ( ; it!= itend; ++it) {
+
+ // process each pixel ---------------------
+
+ (*it)[0]= (*it)[0]/div*div + div/2;
+ (*it)[1]= (*it)[1]/div*div + div/2;
+ (*it)[2]= (*it)[2]/div*div + div/2;
+
+ // end of pixel processing ----------------
+ }
+}
+
+// using Mat_ iterator and bitwise
+void colorReduce9(cv::Mat &image, int div=64) {
+
+ // div must be a power of 2
+ int n= static_cast<int>(log(static_cast<double>(div))/log(2.0));
+ // mask used to round the pixel value
+ uchar mask= 0xFF<<n; // e.g. for div=16, mask= 0xF0
+
+ // get iterators
+ cv::Mat_<cv::Vec3b>::iterator it= image.begin<cv::Vec3b>();
+ cv::Mat_<cv::Vec3b>::iterator itend= image.end<cv::Vec3b>();
+
+ // scan all pixels
+ for ( ; it!= itend; ++it) {
+
+ // process each pixel ---------------------
+
+ (*it)[0]= (*it)[0]&mask + div/2;
+ (*it)[1]= (*it)[1]&mask + div/2;
+ (*it)[2]= (*it)[2]&mask + div/2;
+
+ // end of pixel processing ----------------
+ }
+}
+
+// using MatIterator_
+void colorReduce10(cv::Mat &image, int div=64) {
+
+ // get iterators
+ cv::Mat_<cv::Vec3b> cimage= image;
+ cv::Mat_<cv::Vec3b>::iterator it=cimage.begin();
+ cv::Mat_<cv::Vec3b>::iterator itend=cimage.end();
+
+ for ( ; it!= itend; it++) {
+
+ // process each pixel ---------------------
+
+ (*it)[0]= (*it)[0]/div*div + div/2;
+ (*it)[1]= (*it)[1]/div*div + div/2;
+ (*it)[2]= (*it)[2]/div*div + div/2;
+
+ // end of pixel processing ----------------
+ }
+}
+
+
+void colorReduce11(cv::Mat &image, int div=64) {
+
+ int nl= image.rows; // number of lines
+ int nc= image.cols; // number of columns
+
+ for (int j=0; j<nl; j++) {
+ for (int i=0; i<nc; i++) {
+
+ // process each pixel ---------------------
+
+ image.at<cv::Vec3b>(j,i)[0]= image.at<cv::Vec3b>(j,i)[0]/div*div + div/2;
+ image.at<cv::Vec3b>(j,i)[1]= image.at<cv::Vec3b>(j,i)[1]/div*div + div/2;
+ image.at<cv::Vec3b>(j,i)[2]= image.at<cv::Vec3b>(j,i)[2]/div*div + div/2;
+
+ // end of pixel processing ----------------
+
+ } // end of line
+ }
+}
+
+// with input/ouput images
+void colorReduce12(const cv::Mat &image, // input image
+ cv::Mat &result, // output image
+ int div=64) {
+
+ int nl= image.rows; // number of lines
+ int nc= image.cols ; // number of columns
+
+ // allocate output image if necessary
+ result.create(image.rows,image.cols,image.type());
+
+ // created images have no padded pixels
+ nc= nc*nl;
+ nl= 1; // it is now a 1D array
+
+ int n= static_cast<int>(log(static_cast<double>(div))/log(2.0));
+ // mask used to round the pixel value
+ uchar mask= 0xFF<<n; // e.g. for div=16, mask= 0xF0
+
+ for (int j=0; j<nl; j++) {
+
+ uchar* data= result.ptr<uchar>(j);
+ const uchar* idata= image.ptr<uchar>(j);
+
+ for (int i=0; i<nc; i++) {
+
+ // process each pixel ---------------------
+
+ *data++= (*idata++)&mask + div/2;
+ *data++= (*idata++)&mask + div/2;
+ *data++= (*idata++)&mask + div/2;
+
+ // end of pixel processing ----------------
+
+ } // end of line
+ }
+}
+
+// using overloaded operators
+void colorReduce13(cv::Mat &image, int div=64) {
+
+ int n= static_cast<int>(log(static_cast<double>(div))/log(2.0));
+ // mask used to round the pixel value
+ uchar mask= 0xFF<<n; // e.g. for div=16, mask= 0xF0
+
+ // perform color reduction
+ image=(image&cv::Scalar(mask,mask,mask))+cv::Scalar(div/2,div/2,div/2);
+}
+
+
+#define NTESTS 14
+#define NITERATIONS 20
+
+int main()
+{
+ int64 t[NTESTS],tinit;
+ cv::Mat image1;
+ cv::Mat image2;
+
+ // timer values set to 0
+ for (int i=0; i<NTESTS; i++)
+ t[i]= 0;
+
+ // repeat the tests several times
+ int n=NITERATIONS;
+ for (int k=0; k<n; k++) {
+
+ std::cout << k << " of " << n << std::endl;
+
+ image1= cv::imread("../image.jpg");
+ if (!image1.data)
+ return 0;
+
+ // using .ptr and []
+ tinit= cv::getTickCount();
+ colorReduce0(image1);
+ t[0]+= cv::getTickCount()-tinit;
+
+ image1= cv::imread("../image.jpg");
+ // using .ptr and * ++
+ tinit= cv::getTickCount();
+ colorReduce1(image1);
+ t[1]+= cv::getTickCount()-tinit;
+
+ image1= cv::imread("../image.jpg");
+ // using .ptr and * ++ and modulo
+ tinit= cv::getTickCount();
+ colorReduce2(image1);
+ t[2]+= cv::getTickCount()-tinit;
+
+ image1= cv::imread("../image.jpg");
+ // using .ptr and * ++ and bitwise
+ tinit= cv::getTickCount();
+ colorReduce3(image1);
+ t[3]+= cv::getTickCount()-tinit;
+
+ image1= cv::imread("../image.jpg");
+ // using direct pointer arithmetic
+ tinit= cv::getTickCount();
+ colorReduce4(image1);
+ t[4]+= cv::getTickCount()-tinit;
+
+ image1= cv::imread("../image.jpg");
+ // using .ptr and * ++ and bitwise with image.cols * image.channels()
+ tinit= cv::getTickCount();
+ colorReduce5(image1);
+ t[5]+= cv::getTickCount()-tinit;
+
+ image1= cv::imread("../image.jpg");
+ // using .ptr and * ++ and bitwise (continuous)
+ tinit= cv::getTickCount();
+ colorReduce6(image1);
+ t[6]+= cv::getTickCount()-tinit;
+
+ image1= cv::imread("../image.jpg");
+ // using .ptr and * ++ and bitwise (continuous+channels)
+ tinit= cv::getTickCount();
+ colorReduce7(image1);
+ t[7]+= cv::getTickCount()-tinit;
+
+ image1= cv::imread("../image.jpg");
+ // using Mat_ iterator
+ tinit= cv::getTickCount();
+ colorReduce8(image1);
+ t[8]+= cv::getTickCount()-tinit;
+
+ image1= cv::imread("../image.jpg");
+ // using Mat_ iterator and bitwise
+ tinit= cv::getTickCount();
+ colorReduce9(image1);
+ t[9]+= cv::getTickCount()-tinit;
+
+ image1= cv::imread("../image.jpg");
+ // using Mat_ iterator
+ tinit= cv::getTickCount();
+ colorReduce10(image1);
+ t[10]+= cv::getTickCount()-tinit;
+
+ image1= cv::imread("../image.jpg");
+ // using at
+ tinit= cv::getTickCount();
+ colorReduce11(image1);
+ t[11]+= cv::getTickCount()-tinit;
+
+ image1= cv::imread("../image.jpg");
+ // using input/output images
+ tinit= cv::getTickCount();
+ cv::Mat result;
+ colorReduce12(image1, result);
+ t[12]+= cv::getTickCount()-tinit;
+
+ image2= result;
+
+ image1= cv::imread("../image.jpg");
+ // using input/output images
+ tinit= cv::getTickCount();
+ colorReduce13(image1);
+ t[13]+= cv::getTickCount()-tinit;
+
+ //------------------------------
+ }
+
+ cv::namedWindow("Result");
+ cv::imshow("Result",image2);
+ cv::namedWindow("Image Result");
+ cv::imshow("Image Result",image1);
+
+ // print average execution time
+ std::cout << std::endl << "-------------------------------------------" << std::endl << std::endl;
+ std::cout << "using .ptr and [] =" << 1000.*t[0]/cv::getTickFrequency()/n << "ms" << std::endl;
+ std::cout << "using .ptr and * ++ =" << 1000.*t[1]/cv::getTickFrequency()/n << "ms" << std::endl;
+ std::cout << "using .ptr and * ++ and modulo =" << 1000.*t[2]/cv::getTickFrequency()/n << "ms" << std::endl;
+ std::cout << "using .ptr and * ++ and bitwise =" << 1000.*t[3]/cv::getTickFrequency()/n << "ms" << std::endl;
+ std::cout << "using direct pointer arithmetic =" << 1000.*t[4]/cv::getTickFrequency()/n << "ms" << std::endl;
+ std::cout << "using .ptr and * ++ and bitwise with image.cols * image.channels() =" << 1000.*t[5]/cv::getTickFrequency()/n << "ms" << std::endl;
+ std::cout << "using .ptr and * ++ and bitwise (continuous) =" << 1000.*t[6]/cv::getTickFrequency()/n << "ms" << std::endl;
+ std::cout << "using .ptr and * ++ and bitwise (continuous+channels) =" << 1000.*t[7]/cv::getTickFrequency()/n << "ms" << std::endl;
+ std::cout << "using Mat_ iterator =" << 1000.*t[8]/cv::getTickFrequency()/n << "ms" << std::endl;
+ std::cout << "using Mat_ iterator and bitwise =" << 1000.*t[9]/cv::getTickFrequency()/n << "ms" << std::endl;
+ std::cout << "using MatIterator_ =" << 1000.*t[10]/cv::getTickFrequency()/n << "ms" << std::endl;
+ std::cout << "using at =" << 1000.*t[11]/cv::getTickFrequency()/n << "ms" << std::endl;
+ std::cout << "using input/output images =" << 1000.*t[12]/cv::getTickFrequency()/n << "ms" << std::endl;
+ std::cout << "using overloaded operators =" << 1000.*t[13]/cv::getTickFrequency()/n << "ms" << std::endl;
+
+ cv::waitKey();
+ return 0;
+}
/Chapter 02/colorReduce.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 02/saltImage.cpp
===================================================================
--- Chapter 02/saltImage.cpp (nonexistent)
+++ Chapter 02/saltImage.cpp (revision 3)
@@ -0,0 +1,62 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 2 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+void salt(cv::Mat &image, int n) {
+
+ int i,j;
+ for (int k=0; k<n; k++) {
+
+ // rand() is the MFC random number generator
+ i= rand()%image.cols;
+ j= rand()%image.rows;
+
+
+ if (image.channels() == 1) { // gray-level image
+
+ image.at<uchar>(j,i)= 255;
+
+ } else if (image.channels() == 3) { // color image
+
+ image.at<cv::Vec3b>(j,i)[0]= 255;
+ image.at<cv::Vec3b>(j,i)[1]= 255;
+ image.at<cv::Vec3b>(j,i)[2]= 255;
+ }
+ }
+}
+
+int main()
+{
+ srand(cv::getTickCount()); // init random number generator
+
+ cv::Mat image= cv::imread("boldt.jpg",0);
+
+ salt(image,3000);
+
+ cv::namedWindow("Image");
+ cv::imshow("Image",image);
+
+ cv::imwrite("salted.bmp",image);
+
+ cv::waitKey(5000);
+
+ return 0;
+}
+
+
/Chapter 02/saltImage.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 02/README.txt
===================================================================
--- Chapter 02/README.txt (nonexistent)
+++ Chapter 02/README.txt (revision 3)
@@ -0,0 +1,26 @@
+This directory contains material supporting chapter 2 of the cookbook:
+Computer Vision Programming using the OpenCV Library.
+by Robert Laganiere, Packt Publishing, 2011.
+
+File:
+ saltImage.cpp
+correspond to Recipe:
+Accessing the pixel values
+
+File:
+ colorReduce.cpp
+correspond to Recipes:
+Scanning an image with pointers
+Scanning an image with iterators
+Writing efficient image scanning loops
+
+File:
+ contrast.cpp
+correspond to Recipe:
+Scanning an image with neighbour access
+
+File:
+ addImages.cpp
+correspond to Recipes:
+Performing simple image arithmetic
+Defining regions of interest
/Chapter 02/README.txt
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 02/contrast.cpp
===================================================================
--- Chapter 02/contrast.cpp (nonexistent)
+++ Chapter 02/contrast.cpp (revision 3)
@@ -0,0 +1,151 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 2 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+
+
+void sharpen(const cv::Mat &image, cv::Mat &result) {
+
+ result.create(image.size(), image.type()); // allocate if necessary
+
+ for (int j= 1; j<image.rows-1; j++) { // for all rows (except first and last)
+
+ const uchar* previous= image.ptr<const uchar>(j-1); // previous row
+ const uchar* current= image.ptr<const uchar>(j); // current row
+ const uchar* next= image.ptr<const uchar>(j+1); // next row
+
+ uchar* output= result.ptr<uchar>(j); // output row
+
+ for (int i=1; i<image.cols-1; i++) {
+
+ *output++= cv::saturate_cast<uchar>(5*current[i]-current[i-1]-current[i+1]-previous[i]-next[i]);
+// output[i]= cv::saturate_cast<uchar>(5*current[i]-current[i-1]-current[i+1]-previous[i]-next[i]);
+ }
+ }
+
+ // Set the unprocess pixels to 0
+ result.row(0).setTo(cv::Scalar(0));
+ result.row(result.rows-1).setTo(cv::Scalar(0));
+ result.col(0).setTo(cv::Scalar(0));
+ result.col(result.cols-1).setTo(cv::Scalar(0));
+}
+
+void sharpen2(const cv::Mat &image, cv::Mat &result) {
+
+ result.create(image.size(), image.type()); // allocate if necessary
+
+ int step= image.step1();
+ const uchar* previous= image.data; // ptr to previous row
+ const uchar* current= image.data+step; // ptr to current row
+ const uchar* next= image.data+2*step; // ptr to next row
+ uchar *output= result.data+step; // ptr to output row
+
+ for (int j= 1; j<image.rows-1; j++) { // for each row (except first and last)
+ for (int i=1; i<image.cols-1; i++) { // for each column (except first and last)
+
+ output[i]= cv::saturate_cast<uchar>(5*current[i]-current[i-1]-current[i+1]-previous[i]-next[i]);
+ }
+
+ previous+= step;
+ current+= step;
+ next+= step;
+ output+= step;
+ }
+
+ // Set the unprocess pixels to 0
+ result.row(0).setTo(cv::Scalar(0));
+ result.row(result.rows-1).setTo(cv::Scalar(0));
+ result.col(0).setTo(cv::Scalar(0));
+ result.col(result.cols-1).setTo(cv::Scalar(0));
+}
+
+void sharpen3(const cv::Mat &image, cv::Mat &result) {
+
+ cv::Mat_<uchar>::const_iterator it= image.begin<uchar>()+image.step;
+ cv::Mat_<uchar>::const_iterator itend= image.end<uchar>()-image.step;
+ cv::Mat_<uchar>::const_iterator itup= image.begin<uchar>();
+ cv::Mat_<uchar>::const_iterator itdown= image.begin<uchar>()+2*image.step;
+
+ result.create(image.size(), image.type()); // allocate if necessary
+ cv::Mat_<uchar>::iterator itout= result.begin<uchar>()+result.step;
+
+ for ( ; it!= itend; ++it, ++itup, ++itdown) {
+
+ *itout= cv::saturate_cast<uchar>(*it *5 - *(it-1)- *(it+1)- *itup - *itdown);
+ }
+}
+
+void sharpen2D(const cv::Mat &image, cv::Mat &result) {
+
+ // Construct kernel (all entries initialized to 0)
+ cv::Mat kernel(3,3,CV_32F,cv::Scalar(0));
+ // assigns kernel values
+ kernel.at<float>(1,1)= 5.0;
+ kernel.at<float>(0,1)= -1.0;
+ kernel.at<float>(2,1)= -1.0;
+ kernel.at<float>(1,0)= -1.0;
+ kernel.at<float>(1,2)= -1.0;
+
+ //filter the image
+ cv::filter2D(image,result,image.depth(),kernel);
+}
+
+int main()
+{
+ cv::Mat image= cv::imread("boldt.jpg",0);
+ if (!image.data)
+ return 0;
+
+ cv::Mat result;
+ result.create(image.size(),image.type());
+
+ double time= static_cast<double>(cv::getTickCount());
+ sharpen(image, result);
+ time= (static_cast<double>(cv::getTickCount())-time)/cv::getTickFrequency();
+ std::cout << "time= " << time << std::endl;
+
+ cv::namedWindow("Image");
+ cv::imshow("Image",result);
+
+ image= cv::imread("boldt.jpg",0);
+ time= static_cast<double>(cv::getTickCount());
+ sharpen3(image, result);
+ time= (static_cast<double>(cv::getTickCount())-time)/cv::getTickFrequency();
+ std::cout << "time 3= " << time << std::endl;
+
+ cv::namedWindow("Image 3");
+ cv::imshow("Image 3",result);
+
+ image= cv::imread("boldt.jpg",0);
+ time= static_cast<double>(cv::getTickCount());
+ sharpen2D(image, result);
+ time= (static_cast<double>(cv::getTickCount())-time)/cv::getTickFrequency();
+ std::cout << "time 2D= " << time << std::endl;
+
+ cv::namedWindow("Image 2D");
+ cv::imshow("Image 2D",result);
+
+ cv::waitKey();
+
+ return 0;
+}
+
+
/Chapter 02/contrast.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/colorDetectController.h
===================================================================
--- Chapter 03/colorDetectController.h (nonexistent)
+++ Chapter 03/colorDetectController.h (revision 3)
@@ -0,0 +1,127 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 3 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined CD_CNTRLLR
+#define CD_CNTRLLR
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include "colordetector.h"
+
+class ColorDetectController {
+
+ private:
+
+ static ColorDetectController *singleton; // pointer to the singleton
+
+ ColorDetector *cdetect;
+
+ // The image to be processed
+ cv::Mat image;
+ cv::Mat result;
+
+ public:
+ ColorDetectController() { // private constructor
+
+ //setting up the application
+ cdetect= new ColorDetector();
+ }
+
+ // Sets the color distance threshold
+ void setColorDistanceThreshold(int distance) {
+
+ cdetect->setColorDistanceThreshold(distance);
+ }
+
+ // Gets the color distance threshold
+ int getColorDistanceThreshold() const {
+
+ return cdetect->getColorDistanceThreshold();
+ }
+
+ // Sets the color to be detected
+ void setTargetColor(unsigned char red, unsigned char green, unsigned char blue) {
+
+ cdetect->setTargetColor(red,green,blue);
+ }
+
+ // Gets the color to be detected
+ void getTargetColor(unsigned char &red, unsigned char &green, unsigned char &blue) const {
+
+ cv::Vec3b color= cdetect->getTargetColor();
+
+ red= color[2];
+ green= color[1];
+ blue= color[0];
+ }
+
+ // Sets the input image. Reads it from file.
+ bool setInputImage(std::string filename) {
+
+ image= cv::imread(filename);
+
+ if (!image.data)
+ return false;
+ else
+ return true;
+ }
+
+ // Returns the current input image.
+ const cv::Mat getInputImage() const {
+
+ return image;
+ }
+
+ // Performs image processing.
+ void process() {
+
+ result= cdetect->process(image);
+ }
+
+
+ // Returns the image result from the latest processing.
+ const cv::Mat getLastResult() const {
+
+ return result;
+ }
+
+ // Deletes all processor objects created by the controller.
+ ~ColorDetectController() {
+
+ delete cdetect;
+ }
+
+ // Singleton static members
+ static ColorDetectController *getInstance() {
+
+ if (singleton == 0)
+ singleton= new ColorDetectController;
+
+ return singleton;
+ }
+
+ // Releases the singleton instance of this controller.
+ static void destroy() {
+
+ if (singleton != 0) {
+ delete singleton;
+ singleton= 0;
+ }
+ }
+};
+
+#endif
/Chapter 03/colorDetectController.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/color_detector/ui_mainwindow.h
===================================================================
--- Chapter 03/color_detector/ui_mainwindow.h (nonexistent)
+++ Chapter 03/color_detector/ui_mainwindow.h (revision 3)
@@ -0,0 +1,131 @@
+/********************************************************************************
+** Form generated from reading UI file 'mainwindow.ui'
+**
+** Created: Tue Sep 21 18:32:00 2010
+** by: Qt User Interface Compiler version 4.6.3
+**
+** WARNING! All changes made in this file will be lost when recompiling UI file!
+********************************************************************************/
+
+#ifndef UI_MAINWINDOW_H
+#define UI_MAINWINDOW_H
+
+#include <QtCore/QVariant>
+#include <QtGui/QAction>
+#include <QtGui/QApplication>
+#include <QtGui/QButtonGroup>
+#include <QtGui/QHeaderView>
+#include <QtGui/QLabel>
+#include <QtGui/QMainWindow>
+#include <QtGui/QMenu>
+#include <QtGui/QMenuBar>
+#include <QtGui/QPushButton>
+#include <QtGui/QSlider>
+#include <QtGui/QStatusBar>
+#include <QtGui/QWidget>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_MainWindow
+{
+public:
+ QAction *actionOpen_Image;
+ QAction *actionChoose_Color;
+ QAction *actionProcess;
+ QAction *actionQuit;
+ QWidget *centralWidget;
+ QPushButton *pushButton_openImage;
+ QPushButton *pushButton_color;
+ QPushButton *pushButton_process;
+ QLabel *label;
+ QSlider *verticalSlider_Threshold;
+ QLabel *label_2;
+ QMenuBar *menuBar;
+ QMenu *menuFile;
+ QStatusBar *statusBar;
+
+ void setupUi(QMainWindow *MainWindow)
+ {
+ if (MainWindow->objectName().isEmpty())
+ MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
+ MainWindow->resize(600, 394);
+ actionOpen_Image = new QAction(MainWindow);
+ actionOpen_Image->setObjectName(QString::fromUtf8("actionOpen_Image"));
+ actionChoose_Color = new QAction(MainWindow);
+ actionChoose_Color->setObjectName(QString::fromUtf8("actionChoose_Color"));
+ actionProcess = new QAction(MainWindow);
+ actionProcess->setObjectName(QString::fromUtf8("actionProcess"));
+ actionQuit = new QAction(MainWindow);
+ actionQuit->setObjectName(QString::fromUtf8("actionQuit"));
+ centralWidget = new QWidget(MainWindow);
+ centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
+ pushButton_openImage = new QPushButton(centralWidget);
+ pushButton_openImage->setObjectName(QString::fromUtf8("pushButton_openImage"));
+ pushButton_openImage->setGeometry(QRect(10, 10, 81, 23));
+ pushButton_color = new QPushButton(centralWidget);
+ pushButton_color->setObjectName(QString::fromUtf8("pushButton_color"));
+ pushButton_color->setGeometry(QRect(10, 40, 81, 23));
+ pushButton_process = new QPushButton(centralWidget);
+ pushButton_process->setObjectName(QString::fromUtf8("pushButton_process"));
+ pushButton_process->setGeometry(QRect(10, 320, 81, 23));
+ label = new QLabel(centralWidget);
+ label->setObjectName(QString::fromUtf8("label"));
+ label->setGeometry(QRect(100, 10, 491, 331));
+ label->setFrameShape(QFrame::Box);
+ verticalSlider_Threshold = new QSlider(centralWidget);
+ verticalSlider_Threshold->setObjectName(QString::fromUtf8("verticalSlider_Threshold"));
+ verticalSlider_Threshold->setGeometry(QRect(40, 80, 20, 151));
+ verticalSlider_Threshold->setMaximum(442);
+ verticalSlider_Threshold->setOrientation(Qt::Vertical);
+ label_2 = new QLabel(centralWidget);
+ label_2->setObjectName(QString::fromUtf8("label_2"));
+ label_2->setGeometry(QRect(10, 240, 81, 71));
+ label_2->setWordWrap(true);
+ MainWindow->setCentralWidget(centralWidget);
+ menuBar = new QMenuBar(MainWindow);
+ menuBar->setObjectName(QString::fromUtf8("menuBar"));
+ menuBar->setGeometry(QRect(0, 0, 600, 23));
+ menuFile = new QMenu(menuBar);
+ menuFile->setObjectName(QString::fromUtf8("menuFile"));
+ MainWindow->setMenuBar(menuBar);
+ statusBar = new QStatusBar(MainWindow);
+ statusBar->setObjectName(QString::fromUtf8("statusBar"));
+ MainWindow->setStatusBar(statusBar);
+
+ menuBar->addAction(menuFile->menuAction());
+ menuFile->addAction(actionOpen_Image);
+ menuFile->addAction(actionChoose_Color);
+ menuFile->addAction(actionProcess);
+ menuFile->addSeparator();
+ menuFile->addAction(actionQuit);
+
+ retranslateUi(MainWindow);
+ QObject::connect(actionQuit, SIGNAL(triggered()), MainWindow, SLOT(close()));
+
+ QMetaObject::connectSlotsByName(MainWindow);
+ } // setupUi
+
+ void retranslateUi(QMainWindow *MainWindow)
+ {
+ MainWindow->setWindowTitle(QApplication::translate("MainWindow", "Color Detector (CIE Lab)", 0, QApplication::UnicodeUTF8));
+ actionOpen_Image->setText(QApplication::translate("MainWindow", "Open Image", 0, QApplication::UnicodeUTF8));
+ actionChoose_Color->setText(QApplication::translate("MainWindow", "Choose Color", 0, QApplication::UnicodeUTF8));
+ actionProcess->setText(QApplication::translate("MainWindow", "Process", 0, QApplication::UnicodeUTF8));
+ actionQuit->setText(QApplication::translate("MainWindow", "Quit", 0, QApplication::UnicodeUTF8));
+ pushButton_openImage->setText(QApplication::translate("MainWindow", "Open Image", 0, QApplication::UnicodeUTF8));
+ pushButton_color->setText(QApplication::translate("MainWindow", "Select Color", 0, QApplication::UnicodeUTF8));
+ pushButton_process->setText(QApplication::translate("MainWindow", "Process", 0, QApplication::UnicodeUTF8));
+ label->setText(QApplication::translate("MainWindow", "Image", 0, QApplication::UnicodeUTF8));
+ label_2->setText(QApplication::translate("MainWindow", "Color Distance Threshold: 0", 0, QApplication::UnicodeUTF8));
+ menuFile->setTitle(QApplication::translate("MainWindow", "File", 0, QApplication::UnicodeUTF8));
+ } // retranslateUi
+
+};
+
+namespace Ui {
+ class MainWindow: public Ui_MainWindow {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UI_MAINWINDOW_H
/Chapter 03/color_detector/ui_mainwindow.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/color_detector/colorDetectController.h
===================================================================
--- Chapter 03/color_detector/colorDetectController.h (nonexistent)
+++ Chapter 03/color_detector/colorDetectController.h (revision 3)
@@ -0,0 +1,110 @@
+#if !defined CD_CNTRLLR
+#define CD_CNTRLLR
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include "colordetector.h"
+
+class ColorDetectController {
+
+ private:
+
+ static ColorDetectController *singleton; // pointer to the singleton
+
+ ColorDetector *cdetect;
+
+ // The image to be processed
+ cv::Mat image;
+ cv::Mat result;
+
+ public:
+ ColorDetectController() { // private constructor
+
+ //setting up the application
+ cdetect= new ColorDetector();
+ }
+
+ // Sets the color distance threshold
+ void setColorDistanceThreshold(int distance) {
+
+ cdetect->setColorDistanceThreshold(distance);
+ }
+
+ // Gets the color distance threshold
+ int getColorDistanceThreshold() const {
+
+ return cdetect->getColorDistanceThreshold();
+ }
+
+ // Sets the color to be detected
+ void setTargetColor(unsigned char red, unsigned char green, unsigned char blue) {
+
+ cdetect->setTargetColor(red,green,blue);
+ }
+
+ // Gets the color to be detected
+ void getTargetColor(unsigned char &red, unsigned char &green, unsigned char &blue) const {
+
+ cv::Vec3b color= cdetect->getTargetColor();
+
+ red= color[2];
+ green= color[1];
+ blue= color[0];
+ }
+
+ // Sets the input image. Reads it from file.
+ bool setInputImage(std::string filename) {
+
+ image= cv::imread(filename);
+
+ if (!image.data)
+ return false;
+ else
+ return true;
+ }
+
+ // Returns the current input image.
+ const cv::Mat getInputImage() const {
+
+ return image;
+ }
+
+ // Performs image processing.
+ void process() {
+
+ result= cdetect->process(image);
+ }
+
+
+ // Returns the image result from the latest processing.
+ const cv::Mat getLastResult() const {
+
+ return result;
+ }
+
+ // Deletes all processor objects created by the controller.
+ ~ColorDetectController() {
+
+ delete cdetect;
+ }
+
+ // Singleton static members
+ static ColorDetectController *getInstance() {
+
+ if (singleton == 0)
+ singleton= new ColorDetectController;
+
+ return singleton;
+ }
+
+ // Releases the singleton instance of this controller.
+ static void destroy() {
+
+ if (singleton != 0) {
+ delete singleton;
+ singleton= 0;
+ }
+ }
+};
+
+#endif
/Chapter 03/color_detector/colorDetectController.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/color_detector/mainwindow.h
===================================================================
--- Chapter 03/color_detector/mainwindow.h (nonexistent)
+++ Chapter 03/color_detector/mainwindow.h (revision 3)
@@ -0,0 +1,64 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 3 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QFileDialog>
+#include <QColorDialog>
+
+//OpenCV
+#include "cv.h"
+#include "highgui.h"
+
+//color detector, controller
+#include "colorDetectController.h"
+#include "colordetector.h"
+
+namespace Ui {
+ class MainWindow;
+}
+
+class MainWindow : public QMainWindow {
+ Q_OBJECT
+public:
+ MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+protected:
+ void changeEvent(QEvent *e);
+ void displayMat(const cv::Mat& img);
+
+ //Main Image
+ //cv::Mat img_mat;
+
+private:
+ Ui::MainWindow *ui;
+
+private slots:
+ void on_pushButton_color_clicked();
+ void processColorDetection();
+ void on_verticalSlider_Threshold_valueChanged(int value);
+
+ void setColor();
+ void setImage();
+
+
+};
+
+#endif // MAINWINDOW_H
/Chapter 03/color_detector/mainwindow.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/color_detector/main.cpp
===================================================================
--- Chapter 03/color_detector/main.cpp (nonexistent)
+++ Chapter 03/color_detector/main.cpp (revision 3)
@@ -0,0 +1,27 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 3 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+ return a.exec();
+}
/Chapter 03/color_detector/main.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/color_detector/color_detector.pro
===================================================================
--- Chapter 03/color_detector/color_detector.pro (nonexistent)
+++ Chapter 03/color_detector/color_detector.pro (revision 3)
@@ -0,0 +1,21 @@
+# -------------------------------------------------
+# Project created by QtCreator 2010-09-10T15:33:45
+# -------------------------------------------------
+TARGET = color_detector
+TEMPLATE = app
+SOURCES += main.cpp \
+ mainwindow.cpp \
+ colordetector.cpp \
+ colordetector.cpp \
+ colorDetectController.cpp
+HEADERS += mainwindow.h \
+ colordetector.h \
+ colorDetectController.h
+FORMS += mainwindow.ui
+INCLUDEPATH += C:\OpenCV2.2\include\
+LIBS += -LC:\OpenCV2.2\lib \
+ -lopencv_core220 \
+ -lopencv_highgui220 \
+ -lopencv_imgproc220 \
+ -lopencv_features2d220 \
+ -lopencv_calib3d220
Index: Chapter 03/color_detector/mainwindow.ui
===================================================================
--- Chapter 03/color_detector/mainwindow.ui (nonexistent)
+++ Chapter 03/color_detector/mainwindow.ui (revision 3)
@@ -0,0 +1,168 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>394</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Color Detector (CIE Lab)</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <widget class="QPushButton" name="pushButton_openImage">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>10</y>
+ <width>81</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Open Image</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="pushButton_color">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>40</y>
+ <width>81</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Select Color</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="pushButton_process">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>320</y>
+ <width>81</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Process</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label">
+ <property name="geometry">
+ <rect>
+ <x>100</x>
+ <y>10</y>
+ <width>491</width>
+ <height>331</height>
+ </rect>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::Box</enum>
+ </property>
+ <property name="text">
+ <string>Image</string>
+ </property>
+ </widget>
+ <widget class="QSlider" name="verticalSlider_Threshold">
+ <property name="geometry">
+ <rect>
+ <x>40</x>
+ <y>80</y>
+ <width>20</width>
+ <height>151</height>
+ </rect>
+ </property>
+ <property name="maximum">
+ <number>442</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_2">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>240</y>
+ <width>81</width>
+ <height>71</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Color Distance Threshold: 0</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuFile">
+ <property name="title">
+ <string>File</string>
+ </property>
+ <addaction name="actionOpen_Image"/>
+ <addaction name="actionChoose_Color"/>
+ <addaction name="actionProcess"/>
+ <addaction name="separator"/>
+ <addaction name="actionQuit"/>
+ </widget>
+ <addaction name="menuFile"/>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ <action name="actionOpen_Image">
+ <property name="text">
+ <string>Open Image</string>
+ </property>
+ </action>
+ <action name="actionChoose_Color">
+ <property name="text">
+ <string>Choose Color</string>
+ </property>
+ </action>
+ <action name="actionProcess">
+ <property name="text">
+ <string>Process</string>
+ </property>
+ </action>
+ <action name="actionQuit">
+ <property name="text">
+ <string>Quit</string>
+ </property>
+ </action>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>actionQuit</sender>
+ <signal>triggered()</signal>
+ <receiver>MainWindow</receiver>
+ <slot>close()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>-1</x>
+ <y>-1</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>299</x>
+ <y>199</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
Index: Chapter 03/color_detector/colordetector.cpp
===================================================================
--- Chapter 03/color_detector/colordetector.cpp (nonexistent)
+++ Chapter 03/color_detector/colordetector.cpp (revision 3)
@@ -0,0 +1,57 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 3 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include "colordetector.h"
+
+cv::Mat ColorDetector::process(const cv::Mat &image) {
+
+ // re-allocate binary map if necessary
+ // same size as input image, but 1-channel
+ result.create(image.rows,image.cols,CV_8U);
+
+ // re-allocate intermediate image if necessary
+ converted.create(image.rows,image.cols,image.type());
+
+ // Converting to Lab color space
+ cv::cvtColor(image, converted, CV_BGR2Lab);
+
+ // get the iterators
+ cv::Mat_<cv::Vec3b>::iterator it= converted.begin<cv::Vec3b>();
+ cv::Mat_<cv::Vec3b>::iterator itend= converted.end<cv::Vec3b>();
+ cv::Mat_<uchar>::iterator itout= result.begin<uchar>();
+
+ // for each pixel
+ for ( ; it!= itend; ++it, ++itout) {
+
+ // process each pixel ---------------------
+
+ // compute distance from target color
+ if (getDistance(*it)<minDist) {
+
+ *itout= 255;
+
+ } else {
+
+ *itout= 0;
+ }
+
+ // end of pixel processing ----------------
+ }
+
+ return result;
+}
+
/Chapter 03/color_detector/colordetector.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/color_detector/colorDetectController.cpp
===================================================================
--- Chapter 03/color_detector/colorDetectController.cpp (nonexistent)
+++ Chapter 03/color_detector/colorDetectController.cpp (revision 3)
@@ -0,0 +1,20 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 3 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include "colorDetectController.h"
+
+ColorDetectController *ColorDetectController::singleton=0;
/Chapter 03/color_detector/colorDetectController.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/color_detector/Makefile
===================================================================
--- Chapter 03/color_detector/Makefile (nonexistent)
+++ Chapter 03/color_detector/Makefile (revision 3)
@@ -0,0 +1,153 @@
+#############################################################################
+# Makefile for building: color_detector
+# Generated by qmake (2.01a) (Qt 4.6.3) on: Tue Sep 21 18:30:06 2010
+# Project: color_detector.pro
+# Template: app
+# Command: c:\Qt\4.6.3\bin\qmake.exe -spec c:\Qt\4.6.3\mkspecs\win32-msvc2008 -win32 CONFIG+=release -o Makefile color_detector.pro
+#############################################################################
+
+first: release
+install: release-install
+uninstall: release-uninstall
+MAKEFILE = Makefile
+QMAKE = c:\Qt\4.6.3\bin\qmake.exe
+DEL_FILE = del
+CHK_DIR_EXISTS= if not exist
+MKDIR = mkdir
+COPY = copy /y
+COPY_FILE = $(COPY)
+COPY_DIR = xcopy /s /q /y /i
+INSTALL_FILE = $(COPY_FILE)
+INSTALL_PROGRAM = $(COPY_FILE)
+INSTALL_DIR = $(COPY_DIR)
+DEL_FILE = del
+SYMLINK =
+DEL_DIR = rmdir
+MOVE = move
+CHK_DIR_EXISTS= if not exist
+MKDIR = mkdir
+SUBTARGETS = \
+ release \
+ debug
+
+release: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release
+release-make_default: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release
+release-make_first: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release first
+release-all: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release all
+release-clean: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release clean
+release-distclean: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release distclean
+release-install: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release install
+release-uninstall: $(MAKEFILE).Release FORCE
+ $(MAKE) -f $(MAKEFILE).Release uninstall
+debug: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug
+debug-make_default: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug
+debug-make_first: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug first
+debug-all: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug all
+debug-clean: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug clean
+debug-distclean: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug distclean
+debug-install: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug install
+debug-uninstall: $(MAKEFILE).Debug FORCE
+ $(MAKE) -f $(MAKEFILE).Debug uninstall
+
+Makefile: color_detector.pro c:\Qt\4.6.3\mkspecs\win32-msvc2008\qmake.conf c:\Qt\4.6.3\mkspecs\qconfig.pri \
+ c:\Qt\4.6.3\mkspecs\features\qt_functions.prf \
+ c:\Qt\4.6.3\mkspecs\features\qt_config.prf \
+ c:\Qt\4.6.3\mkspecs\features\exclusive_builds.prf \
+ c:\Qt\4.6.3\mkspecs\features\default_pre.prf \
+ c:\Qt\4.6.3\mkspecs\features\win32\default_pre.prf \
+ c:\Qt\4.6.3\mkspecs\features\release.prf \
+ c:\Qt\4.6.3\mkspecs\features\debug_and_release.prf \
+ c:\Qt\4.6.3\mkspecs\features\default_post.prf \
+ c:\Qt\4.6.3\mkspecs\features\win32\default_post.prf \
+ c:\Qt\4.6.3\mkspecs\features\win32\rtti.prf \
+ c:\Qt\4.6.3\mkspecs\features\win32\exceptions.prf \
+ c:\Qt\4.6.3\mkspecs\features\win32\stl.prf \
+ c:\Qt\4.6.3\mkspecs\features\shared.prf \
+ c:\Qt\4.6.3\mkspecs\features\win32\embed_manifest_exe.prf \
+ c:\Qt\4.6.3\mkspecs\features\win32\embed_manifest_dll.prf \
+ c:\Qt\4.6.3\mkspecs\features\warn_on.prf \
+ c:\Qt\4.6.3\mkspecs\features\qt.prf \
+ c:\Qt\4.6.3\mkspecs\features\win32\thread.prf \
+ c:\Qt\4.6.3\mkspecs\features\moc.prf \
+ c:\Qt\4.6.3\mkspecs\features\win32\windows.prf \
+ c:\Qt\4.6.3\mkspecs\features\resources.prf \
+ c:\Qt\4.6.3\mkspecs\features\uic.prf \
+ c:\Qt\4.6.3\mkspecs\features\yacc.prf \
+ c:\Qt\4.6.3\mkspecs\features\lex.prf \
+ c:\Qt\4.6.3\mkspecs\features\incredibuild_xge.prf \
+ c:\Qt\4.6.3\mkspecs\features\include_source_dir.prf \
+ c:\Qt\4.6.3\lib\qtmain.prl
+ $(QMAKE) -spec c:\Qt\4.6.3\mkspecs\win32-msvc2008 -win32 CONFIG+=release -o Makefile color_detector.pro
+c:\Qt\4.6.3\mkspecs\qconfig.pri:
+c:\Qt\4.6.3\mkspecs\features\qt_functions.prf:
+c:\Qt\4.6.3\mkspecs\features\qt_config.prf:
+c:\Qt\4.6.3\mkspecs\features\exclusive_builds.prf:
+c:\Qt\4.6.3\mkspecs\features\default_pre.prf:
+c:\Qt\4.6.3\mkspecs\features\win32\default_pre.prf:
+c:\Qt\4.6.3\mkspecs\features\release.prf:
+c:\Qt\4.6.3\mkspecs\features\debug_and_release.prf:
+c:\Qt\4.6.3\mkspecs\features\default_post.prf:
+c:\Qt\4.6.3\mkspecs\features\win32\default_post.prf:
+c:\Qt\4.6.3\mkspecs\features\win32\rtti.prf:
+c:\Qt\4.6.3\mkspecs\features\win32\exceptions.prf:
+c:\Qt\4.6.3\mkspecs\features\win32\stl.prf:
+c:\Qt\4.6.3\mkspecs\features\shared.prf:
+c:\Qt\4.6.3\mkspecs\features\win32\embed_manifest_exe.prf:
+c:\Qt\4.6.3\mkspecs\features\win32\embed_manifest_dll.prf:
+c:\Qt\4.6.3\mkspecs\features\warn_on.prf:
+c:\Qt\4.6.3\mkspecs\features\qt.prf:
+c:\Qt\4.6.3\mkspecs\features\win32\thread.prf:
+c:\Qt\4.6.3\mkspecs\features\moc.prf:
+c:\Qt\4.6.3\mkspecs\features\win32\windows.prf:
+c:\Qt\4.6.3\mkspecs\features\resources.prf:
+c:\Qt\4.6.3\mkspecs\features\uic.prf:
+c:\Qt\4.6.3\mkspecs\features\yacc.prf:
+c:\Qt\4.6.3\mkspecs\features\lex.prf:
+c:\Qt\4.6.3\mkspecs\features\incredibuild_xge.prf:
+c:\Qt\4.6.3\mkspecs\features\include_source_dir.prf:
+c:\Qt\4.6.3\lib\qtmain.prl:
+qmake: qmake_all FORCE
+ @$(QMAKE) -spec c:\Qt\4.6.3\mkspecs\win32-msvc2008 -win32 CONFIG+=release -o Makefile color_detector.pro
+
+qmake_all: FORCE
+
+make_default: release-make_default debug-make_default FORCE
+make_first: release-make_first debug-make_first FORCE
+all: release-all debug-all FORCE
+clean: release-clean debug-clean FORCE
+ -$(DEL_FILE) ".\color_detector.intermediate.manifest"
+ -$(DEL_FILE) color_detector.exp
+distclean: release-distclean debug-distclean FORCE
+ -$(DEL_FILE) Makefile
+
+check: first
+
+release-mocclean: $(MAKEFILE).Release
+ $(MAKE) -f $(MAKEFILE).Release mocclean
+debug-mocclean: $(MAKEFILE).Debug
+ $(MAKE) -f $(MAKEFILE).Debug mocclean
+mocclean: release-mocclean debug-mocclean
+
+release-mocables: $(MAKEFILE).Release
+ $(MAKE) -f $(MAKEFILE).Release mocables
+debug-mocables: $(MAKEFILE).Debug
+ $(MAKE) -f $(MAKEFILE).Debug mocables
+mocables: release-mocables debug-mocables
+FORCE:
+
+$(MAKEFILE).Release: Makefile
+$(MAKEFILE).Debug: Makefile
Index: Chapter 03/color_detector/mainwindow.cpp
===================================================================
--- Chapter 03/color_detector/mainwindow.cpp (nonexistent)
+++ Chapter 03/color_detector/mainwindow.cpp (revision 3)
@@ -0,0 +1,122 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 3 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+
+ //select color
+ connect(ui->pushButton_color, SIGNAL(clicked()), this, SLOT(setColor()));
+ connect(ui->actionChoose_Color, SIGNAL(triggered()), this, SLOT(setColor()));
+
+ //open image
+ connect(ui->pushButton_openImage, SIGNAL(clicked()), this, SLOT(setImage()));
+ connect(ui->actionOpen_Image, SIGNAL(triggered()), this, SLOT(setImage()));
+
+ //process Color Detection
+ connect(ui->pushButton_process, SIGNAL(clicked()), this, SLOT(processColorDetection()));
+ connect(ui->actionProcess, SIGNAL(triggered()), this, SLOT(processColorDetection()));
+
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::changeEvent(QEvent *e)
+{
+ QMainWindow::changeEvent(e);
+ switch (e->type()) {
+ case QEvent::LanguageChange:
+ ui->retranslateUi(this);
+ break;
+ default:
+ break;
+ }
+}
+
+void MainWindow::setImage()
+{
+ QFileDialog::Options options;
+ QString selectedFilter;
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open Image Files"),
+ "",
+ tr("Image files (*.jpg *.jpeg *.png *.gif *.bmp)"),
+ &selectedFilter,
+ options);
+ if (!fileName.isEmpty()){
+ cv::Mat img_mat = cv::imread(fileName.toStdString(),1); //0 for grayscale
+ displayMat(img_mat);
+ }
+ //Set Filename
+ ColorDetectController::getInstance()->setInputImage(fileName.toStdString());
+}
+
+//Convert cv::Mat to QImage and display
+void MainWindow::displayMat(const cv::Mat& image){
+
+ //BGR openCV Mat to QImage
+ QImage img_qt = QImage((const unsigned char*)image.data,image.cols, image.rows, image.step, QImage::Format_RGB888);
+
+ //For Binary Images
+ if (img_qt.isNull()){
+ //ColorTable for Binary Images
+ QVector<QRgb> colorTable;
+ for (int i = 0; i < 256; i++)
+ colorTable.push_back(qRgb(i, i, i));
+
+ img_qt = QImage((const unsigned char*)image.data,image.cols, image.rows, QImage::Format_Indexed8);
+ img_qt.setColorTable(colorTable);
+ }
+
+ //Display the QImage in the Label
+ QPixmap img_pix = QPixmap::fromImage(img_qt.rgbSwapped()); //BGR to RGB
+ this->ui->label->setPixmap(img_pix.scaled(ui->label->size(), Qt::KeepAspectRatio));
+}
+
+void MainWindow::on_verticalSlider_Threshold_valueChanged(int value)
+{
+ QString cdt("Color Distance Threshold: ");
+ cdt.append(QString::number(value));
+ this->ui->label_2->setText(cdt);
+}
+
+void MainWindow::setColor()
+{
+ QColor color = QColorDialog::getColor(Qt::green, this);
+ if (color.isValid()) {
+ ColorDetectController::getInstance()->setTargetColor(color.red(),color.green(),color.blue());
+ }
+}
+
+void MainWindow::processColorDetection()
+{
+ ColorDetectController::getInstance()->setColorDistanceThreshold(ui->verticalSlider_Threshold->value());
+ ColorDetectController::getInstance()->process();
+
+ cv::Mat resulting = ColorDetectController::getInstance()->getLastResult();
+ if (!resulting.empty())
+ displayMat(resulting);
+
+}
/Chapter 03/color_detector/mainwindow.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/color_detector/colordetector.h
===================================================================
--- Chapter 03/color_detector/colordetector.h (nonexistent)
+++ Chapter 03/color_detector/colordetector.h (revision 3)
@@ -0,0 +1,112 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 3 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined COLORDETECT
+#define COLORDETECT
+
+#include <opencv2/core/core.hpp>
+
+class ColorDetector {
+
+ private:
+
+ // minimum acceptable distance
+ int minDist;
+
+ // target color
+ cv::Vec3b target;
+
+ // image containing resulting binary map
+ cv::Mat result;
+
+ // image containing color converted image
+ cv::Mat converted;
+
+ // inline private member function
+ // Computes the distance from target color.
+ int getDistance(const cv::Vec3b& color) const {
+ // return static_cast<int>(cv::norm<int,3>(cv::Vec3i(color[0]-target[0],color[1]-target[1],color[2]-target[2])));
+ return abs(color[0]-target[0])+
+ abs(color[1]-target[1])+
+ abs(color[2]-target[2]);
+ }
+
+ public:
+
+ // empty constructor
+ ColorDetector() : minDist(100) {
+
+ // default parameter initialization here
+ target[0]= target[1]= target[2]= 0;
+ }
+
+ // Getters and setters
+
+ // Sets the color distance threshold.
+ // Threshold must be positive, otherwise distance threshold
+ // is set to 0.
+ void setColorDistanceThreshold(int distance) {
+
+ if (distance<0)
+ distance=0;
+ minDist= distance;
+ }
+
+ // Gets the color distance threshold
+ int getColorDistanceThreshold() const {
+
+ return minDist;
+ }
+
+ // Sets the color to be detected
+ void setTargetColor(unsigned char red, unsigned char green, unsigned char blue) {
+
+ cv::Mat tmp(1,1,CV_8UC3);
+ tmp.at<cv::Vec3b>(0,0)[0]= blue;
+ tmp.at<cv::Vec3b>(0,0)[1]= green;
+ tmp.at<cv::Vec3b>(0,0)[2]= red;
+
+ // Converting the target to Lab color space
+ cv::cvtColor(tmp, tmp, CV_BGR2Lab);
+
+ target= tmp.at<cv::Vec3b>(0,0);
+ }
+
+ // Sets the color to be detected
+ void setTargetColor(cv::Vec3b color) {
+
+ cv::Mat tmp(1,1,CV_8UC3);
+ tmp.at<cv::Vec3b>(0,0)= color;
+
+ // Converting the target to Lab color space
+ cv::cvtColor(tmp, tmp, CV_BGR2Lab);
+
+ target= tmp.at<cv::Vec3b>(0,0);
+ }
+
+ // Gets the color to be detected
+ cv::Vec3b getTargetColor() const {
+
+ return target;
+ }
+
+ // Processes the image. Returns a 1-channel binary image.
+ cv::Mat process(const cv::Mat &image);
+};
+
+
+#endif
/Chapter 03/color_detector/colordetector.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/colordetectorLab.cpp
===================================================================
--- Chapter 03/colordetectorLab.cpp (nonexistent)
+++ Chapter 03/colordetectorLab.cpp (revision 3)
@@ -0,0 +1,57 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 3 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include "colordetector.h"
+
+cv::Mat ColorDetector::process(const cv::Mat &image) {
+
+ // re-allocate binary map if necessary
+ // same size as input image, but 1-channel
+ result.create(image.rows,image.cols,CV_8U);
+
+ // re-allocate intermediate image if necessary
+ converted.create(image.rows,image.cols,image.type());
+
+ // Converting to Lab color space
+ cv::cvtColor(image, converted, CV_BGR2Lab);
+
+ // get the iterators
+ cv::Mat_<cv::Vec3b>::iterator it= converted.begin<cv::Vec3b>();
+ cv::Mat_<cv::Vec3b>::iterator itend= converted.end<cv::Vec3b>();
+ cv::Mat_<uchar>::iterator itout= result.begin<uchar>();
+
+ // for each pixel
+ for ( ; it!= itend; ++it, ++itout) {
+
+ // process each pixel ---------------------
+
+ // compute distance from target color
+ if (getDistance(*it)<minDist) {
+
+ *itout= 255;
+
+ } else {
+
+ *itout= 0;
+ }
+
+ // end of pixel processing ----------------
+ }
+
+ return result;
+}
+
/Chapter 03/colordetectorLab.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/colordetector.cpp
===================================================================
--- Chapter 03/colordetector.cpp (nonexistent)
+++ Chapter 03/colordetector.cpp (revision 3)
@@ -0,0 +1,51 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 3 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include "colordetector.h"
+
+cv::Mat ColorDetector::process(const cv::Mat &image) {
+
+ // re-allocate binary map if necessary
+ // same size as input image, but 1-channel
+ result.create(image.rows,image.cols,CV_8U);
+
+ // get the iterators
+ cv::Mat_<cv::Vec3b>::const_iterator it= image.begin<cv::Vec3b>();
+ cv::Mat_<cv::Vec3b>::const_iterator itend= image.end<cv::Vec3b>();
+ cv::Mat_<uchar>::iterator itout= result.begin<uchar>();
+
+ // for each pixel
+ for ( ; it!= itend; ++it, ++itout) {
+
+ // process each pixel ---------------------
+
+ // compute distance from target color
+ if (getDistance(*it)<minDist) {
+
+ *itout= 255;
+
+ } else {
+
+ *itout= 0;
+ }
+
+ // end of pixel processing ----------------
+ }
+
+ return result;
+}
+
/Chapter 03/colordetector.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/README.txt
===================================================================
--- Chapter 03/README.txt (nonexistent)
+++ Chapter 03/README.txt (revision 3)
@@ -0,0 +1,23 @@
+This directory contains material supporting chapter 3 of the cookbook:
+Computer Vision Programming using the OpenCV Library.
+by Robert Laganiere, Packt Publishing, 2011.
+
+Files:
+ colorDetection.h
+ colorDetection.cpp
+ colordetector.cpp
+correspond to Recipe:
+Using the Strategy Pattern in Algorithm Design
+
+Files:
+ colorDetectContoller.h
+ colorDetectContoller.cpp
+correspond to Recipes:
+Using the Controller Pattern to Communicate with Processing Modules
+Using the Singleton Design Pattern
+
+Directory:
+ color_detector
+correspond to Recipes:
+Using the Model-View-Controller Pattern to Design an Application
+Converting Color Spaces
/Chapter 03/README.txt
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/colorDetectController.cpp
===================================================================
--- Chapter 03/colorDetectController.cpp (nonexistent)
+++ Chapter 03/colorDetectController.cpp (revision 3)
@@ -0,0 +1,20 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 3 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include "colorDetectController.h"
+
+ColorDetectController *ColorDetectController::singleton=0;
/Chapter 03/colorDetectController.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/colordetectorLab.h
===================================================================
--- Chapter 03/colordetectorLab.h (nonexistent)
+++ Chapter 03/colordetectorLab.h (revision 3)
@@ -0,0 +1,112 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 3 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined COLORDETECT
+#define COLORDETECT
+
+#include <opencv2/core/core.hpp>
+
+class ColorDetector {
+
+ private:
+
+ // minimum acceptable distance
+ int minDist;
+
+ // target color
+ cv::Vec3b target;
+
+ // image containing resulting binary map
+ cv::Mat result;
+
+ // image containing color converted image
+ cv::Mat converted;
+
+ // inline private member function
+ // Computes the distance from target color.
+ int getDistance(const cv::Vec3b& color) const {
+ // return static_cast<int>(cv::norm<int,3>(cv::Vec3i(color[0]-target[0],color[1]-target[1],color[2]-target[2])));
+ return abs(color[0]-target[0])+
+ abs(color[1]-target[1])+
+ abs(color[2]-target[2]);
+ }
+
+ public:
+
+ // empty constructor
+ ColorDetector() : minDist(100) {
+
+ // default parameter initialization here
+ target[0]= target[1]= target[2]= 0;
+ }
+
+ // Getters and setters
+
+ // Sets the color distance threshold.
+ // Threshold must be positive, otherwise distance threshold
+ // is set to 0.
+ void setColorDistanceThreshold(int distance) {
+
+ if (distance<0)
+ distance=0;
+ minDist= distance;
+ }
+
+ // Gets the color distance threshold
+ int getColorDistanceThreshold() const {
+
+ return minDist;
+ }
+
+ // Sets the color to be detected
+ void setTargetColor(unsigned char red, unsigned char green, unsigned char blue) {
+
+ cv::Mat tmp(1,1,CV_8UC3);
+ tmp.at<cv::Vec3b>(0,0)[0]= blue;
+ tmp.at<cv::Vec3b>(0,0)[1]= green;
+ tmp.at<cv::Vec3b>(0,0)[2]= red;
+
+ // Converting the target to Lab color space
+ cv::cvtColor(tmp, tmp, CV_BGR2Lab);
+
+ target= tmp.at<cv::Vec3b>(0,0);
+ }
+
+ // Sets the color to be detected
+ void setTargetColor(cv::Vec3b color) {
+
+ cv::Mat tmp(1,1,CV_8UC3);
+ tmp.at<cv::Vec3b>(0,0)= color;
+
+ // Converting the target to Lab color space
+ cv::cvtColor(tmp, tmp, CV_BGR2Lab);
+
+ target= tmp.at<cv::Vec3b>(0,0);
+ }
+
+ // Gets the color to be detected
+ cv::Vec3b getTargetColor() const {
+
+ return target;
+ }
+
+ // Processes the image. Returns a 1-channel binary image.
+ cv::Mat process(const cv::Mat &image);
+};
+
+
+#endif
/Chapter 03/colordetectorLab.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/colorDetection.cpp
===================================================================
--- Chapter 03/colorDetection.cpp (nonexistent)
+++ Chapter 03/colorDetection.cpp (revision 3)
@@ -0,0 +1,44 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 3 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+#include "colordetector.h"
+
+int main()
+{
+ // Create image processor object
+ ColorDetector cdetect;
+
+ // Read input image
+ cv::Mat image= cv::imread("boldt.jpg");
+ if (!image.data)
+ return 0;
+
+ // set input parameters
+ cdetect.setTargetColor(130,190,230); // here blue sky
+
+ // Read image, process it and display the result
+ cv::namedWindow("result");
+ cv::imshow("result",cdetect.process(image));
+
+ cv::waitKey();
+
+ return 0;
+}
+
/Chapter 03/colorDetection.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 03/colordetector.h
===================================================================
--- Chapter 03/colordetector.h (nonexistent)
+++ Chapter 03/colordetector.h (revision 3)
@@ -0,0 +1,97 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 3 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined COLORDETECT
+#define COLORDETECT
+
+#include <opencv2/core/core.hpp>
+
+class ColorDetector {
+
+ private:
+
+ // minimum acceptable distance
+ int minDist;
+
+ // target color
+ cv::Vec3b target;
+
+ // image containing resulting binary map
+ cv::Mat result;
+
+ // inline private member function
+ // Computes the distance from target color.
+ int getDistance(const cv::Vec3b& color) const {
+ // return static_cast<int>(cv::norm<int,3>(cv::Vec3i(color[0]-target[0],color[1]-target[1],color[2]-target[2])));
+ return abs(color[0]-target[0])+
+ abs(color[1]-target[1])+
+ abs(color[2]-target[2]);
+ }
+
+ public:
+
+ // empty constructor
+ ColorDetector() : minDist(100) {
+
+ // default parameter initialization here
+ target[0]= target[1]= target[2]= 0;
+ }
+
+ // Getters and setters
+
+ // Sets the color distance threshold.
+ // Threshold must be positive, otherwise distance threshold
+ // is set to 0.
+ void setColorDistanceThreshold(int distance) {
+
+ if (distance<0)
+ distance=0;
+ minDist= distance;
+ }
+
+ // Gets the color distance threshold
+ int getColorDistanceThreshold() const {
+
+ return minDist;
+ }
+
+ // Sets the color to be detected
+ void setTargetColor(unsigned char red, unsigned char green, unsigned char blue) {
+
+ target[2]= red;
+ target[1]= green;
+ target[0]= blue;
+ }
+
+ // Sets the color to be detected
+ void setTargetColor(cv::Vec3b color) {
+
+ target= color;
+ }
+
+ // Gets the color to be detected
+ cv::Vec3b getTargetColor() const {
+
+ return target;
+ }
+
+ // Processes the image. Returns a 1-channel binary image.
+ cv::Mat process(const cv::Mat &image);
+};
+
+
+#endif
/Chapter 03/colordetector.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 04/objectfinder.cpp
===================================================================
--- Chapter 04/objectfinder.cpp (nonexistent)
+++ Chapter 04/objectfinder.cpp (revision 3)
@@ -0,0 +1,186 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 4 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+using namespace std;
+
+#include "cv.h"
+#include "highgui.h"
+
+#include "histogram.h"
+#include "objectFinder.h"
+#include "colorhistogram.h"
+
+int main()
+{
+ // Read input image
+ cv::Mat image= cv::imread("../waves.jpg",0);
+ if (!image.data)
+ return 0;
+
+ // define image ROI
+ cv::Mat imageROI;
+ imageROI= image(cv::Rect(360,55,40,50)); // Cloud region
+
+ // Display reference patch
+ cv::namedWindow("Reference");
+ cv::imshow("Reference",imageROI);
+
+ // Find histogram of reference
+ Histogram1D h;
+ cv::MatND hist= h.getHistogram(imageROI);
+ cv::namedWindow("Reference Hist");
+ cv::imshow("Reference Hist",h.getHistogramImage(imageROI));
+
+ // Create the objectfinder
+ ContentFinder finder;
+ finder.setHistogram(hist);
+
+ finder.setThreshold(-1.0f);
+
+ // Get back-projection
+ cv::Mat result1;
+ result1= finder.find(image);
+
+ // Create negative image and display result
+ cv::Mat tmp;
+ result1.convertTo(tmp,CV_8U,-1.0,255.0);
+ cv::namedWindow("Backprojection result");
+ cv::imshow("Backprojection result",tmp);
+
+ // Get binary back-projection
+ finder.setThreshold(0.12f);
+ result1= finder.find(image);
+
+ // Draw a rectangle around the reference area
+ cv::rectangle(image,cv::Rect(360,55,40,50),cv::Scalar(0,0,0));
+
+ // Display image
+ cv::namedWindow("Image");
+ cv::imshow("Image",image);
+
+ // Display result
+ cv::namedWindow("Detection Result");
+ cv::imshow("Detection Result",result1);
+
+ // Second test image
+ cv::Mat image2= cv::imread("../dog.jpg",0);
+ cv::Mat result2;
+ result2= finder.find(image2);
+
+ // Display result
+ cv::namedWindow("Result (2)");
+ cv::imshow("Result (2)",result2);
+
+ // Load color image
+ ColorHistogram hc;
+ cv::Mat color= cv::imread("../waves.jpg");
+ color= hc.colorReduce(color,32);
+ cv::namedWindow("Color Image");
+ cv::imshow("Color Image",color);
+
+ imageROI= color(cv::Rect(0,0,165,75)); // blue sky area
+
+ // Get 3D color histogram
+ cv::MatND shist= hc.getHistogram(imageROI);
+ // Histograms with SparseMat does not work with OpenCV2.1
+ // cv::SparseMat shist= hc.getSparseHistogram(imageROI);
+
+ finder.setHistogram(shist);
+ finder.setThreshold(0.05f);
+
+ // Get back-projection of color histogram
+ result1= finder.find(color);
+
+ cv::namedWindow("Color Backproject Result");
+ cv::imshow("Color Backproject Result",result1);
+
+ // Second color image
+ cv::Mat color2= cv::imread("../dog.jpg");
+ color2= hc.colorReduce(color2,32);
+
+ // Get back-projection of color histogram
+ result2= finder.find(color2);
+
+ cv::namedWindow("Result color (2)");
+ cv::imshow("Result color (2)",result2);
+
+ // Get ab color histogram
+ color= cv::imread("../waves.jpg");
+ imageROI= color(cv::Rect(0,0,165,75)); // blue sky area
+ cv::MatND colorhist= hc.getabHistogram(imageROI);
+
+ finder.setHistogram(colorhist);
+ finder.setThreshold(0.05f);
+
+ // Convert to Lab space
+ cv::Mat lab;
+ cv::cvtColor(color, lab, CV_BGR2Lab);
+
+ // Get back-projection of ab histogram
+ int ch[2]={1,2};
+ result1= finder.find(lab,-128.0f,127.0f,ch,2);
+
+ cv::namedWindow("Result ab (1)");
+ cv::imshow("Result ab (1)",result1);
+
+ // Second color image
+ color2= cv::imread("../dog.jpg");
+
+ cv::namedWindow("Color Image (2)");
+ cv::imshow("Color Image (2)",color2);
+
+ cv::cvtColor(color2, lab, CV_BGR2Lab);
+
+ result2= finder.find(lab,-128.0f,127.0f,ch,2);
+
+ cv::namedWindow("Result ab (2)");
+ cv::imshow("Result ab (2)",result2);
+
+ // Get Hue color histogram
+ color= cv::imread("../waves.jpg");
+ imageROI= color(cv::Rect(0,0,165,75)); // blue sky area
+ colorhist= hc.getHueHistogram(imageROI);
+
+ finder.setHistogram(colorhist);
+ finder.setThreshold(0.3f);
+
+ // Convert to HSV space
+ cv::Mat hsv;
+ cv::cvtColor(color, hsv, CV_BGR2HSV);
+
+ // Get back-projection of hue histogram
+ ch[0]=0;
+ result1= finder.find(hsv,0.0f,180.0f,ch,1);
+
+ cv::namedWindow("Result Hue (1)");
+ cv::imshow("Result Hue (1)",result1);
+
+ // Second color image
+ color2= cv::imread("../dog.jpg");
+
+ cv::cvtColor(color2, hsv, CV_BGR2HSV);
+
+ result2= finder.find(hsv,0.0f,180.0f,ch,1);
+
+ cv::namedWindow("Result Hue (2)");
+ cv::imshow("Result Hue (2)",result2);
+
+ cv::waitKey();
+ return 0;
+}
+
/Chapter 04/objectfinder.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 04/imageComparator.h
===================================================================
--- Chapter 04/imageComparator.h (nonexistent)
+++ Chapter 04/imageComparator.h (revision 3)
@@ -0,0 +1,72 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 4 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined ICOMPARATOR
+#define ICOMPARATOR
+
+#include <opencv2\core\core.hpp>
+#include <opencv2\imgproc\imgproc.hpp>
+#include "colorhistogram.h"
+
+class ImageComparator {
+
+ private:
+
+ cv::Mat reference;
+ cv::Mat input;
+ cv::MatND refH;
+ cv::MatND inputH;
+
+ ColorHistogram hist;
+ int div;
+
+ public:
+
+ ImageComparator() : div(32) {
+
+ }
+
+ // Color reduction factor
+ // The comparaison will be made on images with
+ // color space reduced by this factor in each dimension
+ void setColorReduction( int factor) {
+
+ div= factor;
+ }
+
+ int getColorReduction() {
+
+ return div;
+ }
+
+ void setReferenceImage(const cv::Mat& image) {
+
+ reference= hist.colorReduce(image,div);
+ refH= hist.getHistogram(reference);
+ }
+
+ double compare(const cv::Mat& image) {
+
+ input= hist.colorReduce(image,div);
+ inputH= hist.getHistogram(input);
+
+ return cv::compareHist(refH,inputH,CV_COMP_INTERSECT);
+ }
+};
+
+
+#endif
/Chapter 04/imageComparator.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 04/histograms.cpp
===================================================================
--- Chapter 04/histograms.cpp (nonexistent)
+++ Chapter 04/histograms.cpp (revision 3)
@@ -0,0 +1,96 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 4 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+using namespace std;
+
+#include "cv.h"
+#include "highgui.h"
+#include "histogram.h"
+
+int main()
+{
+ // Read input image
+ cv::Mat image= cv::imread("../group.jpg",0);
+ if (!image.data)
+ return 0;
+
+ // Display the image
+ cv::namedWindow("Image");
+ cv::imshow("Image",image);
+
+ // The histogram object
+ Histogram1D h;
+
+ // Compute the histogram
+ cv::MatND histo= h.getHistogram(image);
+
+ // Loop over each bin
+ for (int i=0; i<256; i++)
+ cout << "Value " << i << " = " << histo.at<float>(i) << endl;
+
+ // Display a histogram as an image
+ cv::namedWindow("Histogram");
+ cv::imshow("Histogram",h.getHistogramImage(image));
+
+ // creating a binary image by thresholding at the valley
+ cv::Mat thresholded;
+ cv::threshold(image,thresholded,60,255,cv::THRESH_BINARY);
+
+ // Display the thresholded image
+ cv::namedWindow("Binary Image");
+ cv::imshow("Binary Image",thresholded);
+ cv::imwrite("binary.bmp",thresholded);
+
+ // Equalize the image
+ cv::Mat eq= h.equalize(image);
+
+ // Show the result
+ cv::namedWindow("Equalized Image");
+ cv::imshow("Equalized Image",eq);
+
+ // Show the new histogram
+ cv::namedWindow("Equalized Histogram");
+ cv::imshow("Equalized Histogram",h.getHistogramImage(eq));
+
+ // Stretch the image ignoring bins with less than 5 pixels
+ cv::Mat str= h.stretch(image,5);
+
+ // Show the result
+ cv::namedWindow("Stretched Image");
+ cv::imshow("Stretched Image",str);
+
+ // Show the new histogram
+ cv::namedWindow("Stretched Histogram");
+ cv::imshow("Stretched Histogram",h.getHistogramImage(str));
+
+ // Create an image inversion table
+ uchar lookup[256];
+
+ for (int i=0; i<256; i++) {
+
+ lookup[i]= 255-i;
+ }
+
+ // Apply lookup and display negative image
+ cv::namedWindow("Negative image");
+ cv::imshow("Negative image",h.applyLookUp(image,lookup));
+
+ cv::waitKey();
+ return 0;
+}
+
/Chapter 04/histograms.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 04/colorhistogram.h
===================================================================
--- Chapter 04/colorhistogram.h (nonexistent)
+++ Chapter 04/colorhistogram.h (revision 3)
@@ -0,0 +1,169 @@
+#if !defined COLHISTOGRAM
+#define COLHISTOGRAM
+
+#include <opencv2\core\core.hpp>
+#include <opencv2\imgproc\imgproc.hpp>
+
+class ColorHistogram {
+
+ private:
+
+ int histSize[3];
+ float hranges[2];
+ const float* ranges[3];
+ int channels[3];
+
+ public:
+
+ ColorHistogram() {
+
+ // Prepare arguments for a color histogram
+ histSize[0]= histSize[1]= histSize[2]= 256;
+ hranges[0]= 0.0; // BRG range
+ hranges[1]= 255.0;
+ ranges[0]= hranges; // all channels have the same range
+ ranges[1]= hranges;
+ ranges[2]= hranges;
+ channels[0]= 0; // the three channels
+ channels[1]= 1;
+ channels[2]= 2;
+ }
+
+ // Computes the histogram.
+ cv::MatND getHistogram(const cv::Mat &image) {
+
+ cv::MatND hist;
+
+ // BGR color histogram
+ hranges[0]= 0.0; // BRG range
+ hranges[1]= 255.0;
+ channels[0]= 0; // the three channels
+ channels[1]= 1;
+ channels[2]= 2;
+
+ // Compute histogram
+ cv::calcHist(&image,
+ 1, // histogram of 1 image only
+ channels, // the channel used
+ cv::Mat(), // no mask is used
+ hist, // the resulting histogram
+ 3, // it is a 3D histogram
+ histSize, // number of bins
+ ranges // pixel value range
+ );
+
+ return hist;
+ }
+
+ // Computes the histogram.
+ cv::SparseMat getSparseHistogram(const cv::Mat &image) {
+
+ cv::SparseMat hist(3,histSize,CV_32F);
+
+ // BGR color histogram
+ hranges[0]= 0.0; // BRG range
+ hranges[1]= 255.0;
+ channels[0]= 0; // the three channels
+ channels[1]= 1;
+ channels[2]= 2;
+
+ // Compute histogram
+ cv::calcHist(&image,
+ 1, // histogram of 1 image only
+ channels, // the channel used
+ cv::Mat(), // no mask is used
+ hist, // the resulting histogram
+ 3, // it is a 3D histogram
+ histSize, // number of bins
+ ranges // pixel value range
+ );
+
+ return hist;
+ }
+
+ // Computes the 2D ab histogram.
+ // BGR source image is converted to Lab
+ cv::MatND getabHistogram(const cv::Mat &image) {
+
+ cv::MatND hist;
+
+ // Convert to Lab color space
+ cv::Mat lab;
+ cv::cvtColor(image, lab, CV_BGR2Lab);
+
+ // Prepare arguments for a 2D color histogram
+ hranges[0]= -128.0;
+ hranges[1]= 127.0;
+ channels[0]= 1; // the two channels used are ab
+ channels[1]= 2;
+
+ // Compute histogram
+ cv::calcHist(&lab,
+ 1, // histogram of 1 image only
+ channels, // the channel used
+ cv::Mat(), // no mask is used
+ hist, // the resulting histogram
+ 2, // it is a 2D histogram
+ histSize, // number of bins
+ ranges // pixel value range
+ );
+
+ return hist;
+ }
+
+ // Computes the 1D Hue histogram with a mask.
+ // BGR source image is converted to HSV
+ cv::MatND getHueHistogram(const cv::Mat &image) {
+
+ cv::MatND hist;
+
+ // Convert to Lab color space
+ cv::Mat hue;
+ cv::cvtColor(image, hue, CV_BGR2HSV);
+
+ // Prepare arguments for a 1D hue histogram
+ hranges[0]= 0.0;
+ hranges[1]= 180.0;
+ channels[0]= 0; // the hue channel
+
+ // Compute histogram
+ cv::calcHist(&hue,
+ 1, // histogram of 1 image only
+ channels, // the channel used
+ cv::Mat(), // no mask is used
+ hist, // the resulting histogram
+ 1, // it is a 1D histogram
+ histSize, // number of bins
+ ranges // pixel value range
+ );
+
+ return hist;
+ }
+
+ cv::Mat colorReduce(const cv::Mat &image, int div=64) {
+
+ int n= static_cast<int>(log(static_cast<double>(div))/log(2.0));
+ // mask used to round the pixel value
+ uchar mask= 0xFF<<n; // e.g. for div=16, mask= 0xF0
+
+ cv::Mat_<cv::Vec3b>::const_iterator it= image.begin<cv::Vec3b>();
+ cv::Mat_<cv::Vec3b>::const_iterator itend= image.end<cv::Vec3b>();
+
+ // Set output image (always 1-channel)
+ cv::Mat result(image.rows,image.cols,image.type());
+ cv::Mat_<cv::Vec3b>::iterator itr= result.begin<cv::Vec3b>();
+
+ for ( ; it!= itend; ++it, ++itr) {
+
+ (*itr)[0]= ((*it)[0]&mask) + div/2;
+ (*itr)[1]= ((*it)[1]&mask) + div/2;
+ (*itr)[2]= ((*it)[2]&mask) + div/2;
+ }
+
+ return result;
+}
+
+};
+
+
+#endif
/Chapter 04/colorhistogram.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 04/histogram.h
===================================================================
--- Chapter 04/histogram.h (nonexistent)
+++ Chapter 04/histogram.h (revision 3)
@@ -0,0 +1,192 @@
+#if !defined HISTOGRAM
+#define HISTOGRAM
+
+#include <opencv2\core\core.hpp>
+#include <opencv2\imgproc\imgproc.hpp>
+
+class Histogram1D {
+
+ private:
+
+ int histSize[1];
+ float hranges[2];
+ const float* ranges[1];
+ int channels[1];
+
+ public:
+
+ Histogram1D() {
+
+ // Prepare arguments for 1D histogram
+ histSize[0]= 256;
+ hranges[0]= 0.0;
+ hranges[1]= 255.0;
+ ranges[0]= hranges;
+ channels[0]= 0; // by default, we look at channel 0
+ }
+
+ // Sets the channel on which histogram will be calculated.
+ // By default it is channel 0.
+ void setChannel(int c) {
+
+ channels[0]= c;
+ }
+
+ // Gets the channel used.
+ int getChannel() {
+
+ return channels[0];
+ }
+
+ // Sets the range for the pixel values.
+ // By default it is [0,255]
+ void setRange(float minValue, float maxValue) {
+
+ hranges[0]= minValue;
+ hranges[1]= maxValue;
+ }
+
+ // Gets the min pixel value.
+ float getMinValue() {
+
+ return hranges[0];
+ }
+
+ // Gets the max pixel value.
+ float getMaxValue() {
+
+ return hranges[1];
+ }
+
+ // Sets the number of bins in histogram.
+ // By default it is 256.
+ void setNBins(int nbins) {
+
+ histSize[0]= nbins;
+ }
+
+ // Gets the number of bins in histogram.
+ int getNBins() {
+
+ return histSize[0];
+ }
+
+ // Computes the 1D histogram.
+ cv::MatND getHistogram(const cv::Mat &image) {
+
+ cv::MatND hist;
+
+ // Compute histogram
+ cv::calcHist(&image,
+ 1, // histogram of 1 image only
+ channels, // the channel used
+ cv::Mat(), // no mask is used
+ hist, // the resulting histogram
+ 1, // it is a 1D histogram
+ histSize, // number of bins
+ ranges // pixel value range
+ );
+
+ return hist;
+ }
+
+ // Computes the 1D histogram and returns an image of it.
+ cv::Mat getHistogramImage(const cv::Mat &image){
+
+ // Compute histogram first
+ cv::MatND hist= getHistogram(image);
+
+ // Get min and max bin values
+ double maxVal=0;
+ double minVal=0;
+ cv::minMaxLoc(hist, &minVal, &maxVal, 0, 0);
+
+ // Image on which to display histogram
+ cv::Mat histImg(histSize[0], histSize[0], CV_8U,cv::Scalar(255));
+
+ // set highest point at 90% of nbins
+ int hpt = static_cast<int>(0.9*histSize[0]);
+
+ // Draw vertical line for each bin
+ for( int h = 0; h < histSize[0]; h++ ) {
+
+ float binVal = hist.at<float>(h);
+ int intensity = static_cast<int>(binVal*hpt/maxVal);
+ cv::line(histImg,cv::Point(h,histSize[0]),cv::Point(h,histSize[0]-intensity),cv::Scalar::all(0));
+ }
+
+ return histImg;
+ }
+
+ // Equalizes the source image.
+ cv::Mat equalize(const cv::Mat &image) {
+
+ cv::Mat result;
+ cv::equalizeHist(image,result);
+
+ return result;
+ }
+
+ // Stretches the source image.
+ cv::Mat stretch(const cv::Mat &image, int minValue=0) {
+
+ // Compute histogram first
+ cv::MatND hist= getHistogram(image);
+
+ // find left extremity of the histogram
+ int imin= 0;
+ for( ; imin < histSize[0]; imin++ ) {
+ std::cout<<hist.at<float>(imin)<<std::endl;
+ if (hist.at<float>(imin) > minValue)
+ break;
+ }
+
+ // find right extremity of the histogram
+ int imax= histSize[0]-1;
+ for( ; imax >= 0; imax-- ) {
+
+ if (hist.at<float>(imax) > minValue)
+ break;
+ }
+
+ // Create lookup table
+ int dims[1]={256};
+ cv::MatND lookup(1,dims,CV_8U);
+
+ for (int i=0; i<256; i++) {
+
+ if (i < imin) lookup.at<uchar>(i)= 0;
+ else if (i > imax) lookup.at<uchar>(i)= 255;
+ else lookup.at<uchar>(i)= static_cast<uchar>(255.0*(i-imin)/(imax-imin)+0.5);
+ }
+
+ // Apply lookup table
+ cv::Mat result;
+ result= applyLookUp(image,lookup);
+
+ return result;
+ }
+
+ // Applies a lookup table transforming an input image into a 1-channel image
+ cv::Mat applyLookUp(const cv::Mat& image, const cv::MatND& lookup) {
+
+ // Set output image (always 1-channel)
+ cv::Mat result(image.rows,image.cols,CV_8U);
+ cv::Mat_<uchar>::iterator itr= result.begin<uchar>();
+
+ // Iterates over the input image
+ cv::Mat_<uchar>::const_iterator it= image.begin<uchar>();
+ cv::Mat_<uchar>::const_iterator itend= image.end<uchar>();
+
+ // Applies lookup to each pixel
+ for ( ; it!= itend; ++it, ++itr) {
+
+ *itr= lookup.at<uchar>(*it);
+ }
+
+ return result;
+ }
+};
+
+
+#endif
/Chapter 04/histogram.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 04/objectFinder.h
===================================================================
--- Chapter 04/objectFinder.h (nonexistent)
+++ Chapter 04/objectFinder.h (revision 3)
@@ -0,0 +1,142 @@
+#if !defined OFINDER
+#define OFINDER
+
+#include <opencv2\core\core.hpp>
+#include <opencv2\imgproc\imgproc.hpp>
+
+class ObjectFinder {
+
+ private:
+
+ float hranges[2];
+ const float* ranges[3];
+ int channels[3];
+
+ float threshold;
+ cv::MatND histogram;
+ cv::SparseMat shistogram;
+ bool isSparse;
+
+ public:
+
+ ObjectFinder() : threshold(0.1f), isSparse(false) {
+
+ ranges[0]= hranges; // all channels have the same range
+ ranges[1]= hranges;
+ ranges[2]= hranges;
+ }
+
+ // Sets the threshold on histogram values [0,1]
+ void setThreshold(float t) {
+
+ threshold= t;
+ }
+
+ // Gets the threshold
+ float getThreshold() {
+
+ return threshold;
+ }
+
+ // Sets the reference histogram
+ void setHistogram(const cv::MatND& h) {
+
+ isSparse= false;
+ histogram= h;
+ cv::normalize(histogram,histogram,1.0);
+ }
+
+ // Sets the reference histogram
+ void setHistogram(const cv::SparseMat& h) {
+
+ isSparse= true;
+ shistogram= h;
+ cv::normalize(shistogram,shistogram,1.0,cv::NORM_L2);
+ }
+
+ // Finds the pixels belonging to the histogram
+ cv::Mat find(const cv::Mat& image) {
+
+ cv::Mat result;
+
+ hranges[0]= 0.0; // range [0,255]
+ hranges[1]= 255.0;
+ channels[0]= 0; // the three channels
+ channels[1]= 1;
+ channels[2]= 2;
+
+ if (isSparse) { // call the right function based on histogram type
+
+ cv::calcBackProject(&image,
+ 1, // one image
+ channels, // vector specifying what histogram dimensions belong to what image channels
+ shistogram, // the histogram we are using
+ result, // the resulting back projection image
+ ranges, // the range of values, for each dimension
+ 255.0 // the scaling factor is chosen such that a histogram value of 1 maps to 255
+ );
+
+ } else {
+
+ cv::calcBackProject(&image,
+ 1, // one image
+ channels, // vector specifying what histogram dimensions belong to what image channels
+ histogram, // the histogram we are using
+ result, // the resulting back projection image
+ ranges, // the range of values, for each dimension
+ 255.0 // the scaling factor is chosen such that a histogram value of 1 maps to 255
+ );
+ }
+
+
+ // Threshold back projection to obtain a binary image
+ if (threshold>0.0)
+ cv::threshold(result, result, 255*threshold, 255, cv::THRESH_BINARY);
+
+ return result;
+ }
+
+ cv::Mat find(const cv::Mat& image, float minValue, float maxValue, int *channels, int dim) {
+
+ cv::Mat result;
+
+ hranges[0]= minValue;
+ hranges[1]= maxValue;
+
+ for (int i=0; i<dim; i++)
+ this->channels[i]= channels[i];
+
+ if (isSparse) { // call the right function based on histogram type
+
+ cv::calcBackProject(&image,
+ 1, // we only use one image at a time
+ channels, // vector specifying what histogram dimensions belong to what image channels
+ shistogram, // the histogram we are using
+ result, // the resulting back projection image
+ ranges, // the range of values, for each dimension
+ 255.0 // the scaling factor is chosen such that a histogram value of 1 maps to 255
+ );
+
+ } else {
+
+ cv::calcBackProject(&image,
+ 1, // we only use one image at a time
+ channels, // vector specifying what histogram dimensions belong to what image channels
+ histogram, // the histogram we are using
+ result, // the resulting back projection image
+ ranges, // the range of values, for each dimension
+ 255.0 // the scaling factor is chosen such that a histogram value of 1 maps to 255
+ );
+ }
+
+ // Threshold back projection to obtain a binary image
+ if (threshold>0.0)
+ cv::threshold(result, result, 255*threshold, 255, cv::THRESH_BINARY);
+
+ return result;
+ }
+
+};
+
+
+#endif
/Chapter 04/objectFinder.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 04/retrieve.cpp
===================================================================
--- Chapter 04/retrieve.cpp (nonexistent)
+++ Chapter 04/retrieve.cpp (revision 3)
@@ -0,0 +1,74 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 4 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+using namespace std;
+
+#include <opencv2\core\core.hpp>
+#include <opencv2\highgui\highgui.hpp>
+
+#include "imageComparator.h"
+
+int main()
+{
+ // Read reference image
+ cv::Mat image= cv::imread("../waves.jpg");
+ if (!image.data)
+ return 0;
+
+ // Display image
+ cv::namedWindow("Query Image");
+ cv::imshow("Query Image",image);
+
+ ImageComparator c;
+ c.setReferenceImage(image);
+
+ // Read an image and compare it with reference
+ cv::Mat input= cv::imread("../dog.jpg");
+ cout << "waves vs dog: " << c.compare(input) << endl;
+
+ // Read an image and compare it with reference
+ input= cv::imread("../marais.jpg");
+ cout << "waves vs marais: " << c.compare(input) << endl;
+
+ // Read an image and compare it with reference
+ input= cv::imread("../bear.jpg");
+ cout << "waves vs bear: " << c.compare(input) << endl;
+
+ // Read an image and compare it with reference
+ input= cv::imread("../beach.jpg");
+ cout << "waves vs beach: " << c.compare(input) << endl;
+
+ // Read an image and compare it with reference
+ input= cv::imread("../polar.jpg");
+ cout << "waves vs polar: " << c.compare(input) << endl;
+
+ // Read an image and compare it with reference
+ input= cv::imread("../moose.jpg");
+ cout << "waves vs moose: " << c.compare(input) << endl;
+
+ // Read an image and compare it with reference
+ input= cv::imread("../lake.jpg");
+ cout << "waves vs lake: " << c.compare(input) << endl;
+
+ // Read an image and compare it with reference
+ input= cv::imread("../fundy.jpg");
+ cout << "waves vs fundy: " << c.compare(input) << endl;
+
+ cv::waitKey();
+ return 0;
+}
\ No newline at end of file
/Chapter 04/retrieve.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 04/finder.cpp
===================================================================
--- Chapter 04/finder.cpp (nonexistent)
+++ Chapter 04/finder.cpp (revision 3)
@@ -0,0 +1,128 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 4 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <vector>
+using namespace std;
+
+#include <opencv2\core\core.hpp>
+#include <opencv2\highgui\highgui.hpp>
+#include <opencv2\imgproc\imgproc.hpp>
+#include <opencv2\video\tracking.hpp>
+
+#include "objectFinder.h"
+#include "colorhistogram.h"
+
+int main()
+{
+ // Read reference image
+ cv::Mat image= cv::imread("../baboon1.jpg");
+ if (!image.data)
+ return 0;
+
+ // Define ROI
+ cv::Mat imageROI= image(cv::Rect(110,260,35,40));
+ cv::rectangle(image, cv::Rect(110,260,35,40),cv::Scalar(0,0,255));
+
+ // Display image
+ cv::namedWindow("Image");
+ cv::imshow("Image",image);
+
+ // Get the Hue histogram
+ int minSat=65;
+ ColorHistogram hc;
+ cv::MatND colorhist= hc.getHueHistogram(imageROI,minSat);
+
+ ObjectFinder finder;
+ finder.setHistogram(colorhist);
+ finder.setThreshold(0.2f);
+
+ // Convert to HSV space
+ cv::Mat hsv;
+ cv::cvtColor(image, hsv, CV_BGR2HSV);
+
+ // Split the image
+ vector<cv::Mat> v;
+ cv::split(hsv,v);
+
+ // Eliminate pixels with low saturation
+ cv::threshold(v[1],v[1],minSat,255,cv::THRESH_BINARY);
+ cv::namedWindow("Saturation");
+ cv::imshow("Saturation",v[1]);
+
+ // Get back-projection of hue histogram
+ int ch[1]={0};
+ cv::Mat result= finder.find(hsv,0.0f,180.0f,ch,1);
+
+ cv::namedWindow("Result Hue");
+ cv::imshow("Result Hue",result);
+
+ cv::bitwise_and(result,v[1],result);
+ cv::namedWindow("Result Hue and");
+ cv::imshow("Result Hue and",result);
+
+ // Second image
+ image= cv::imread("../baboon3.jpg");
+
+ // Display image
+ cv::namedWindow("Image 2");
+ cv::imshow("Image 2",image);
+
+ // Convert to HSV space
+ cv::cvtColor(image, hsv, CV_BGR2HSV);
+
+ // Split the image
+ cv::split(hsv,v);
+
+ // Eliminate pixels with low saturation
+ cv::threshold(v[1],v[1],minSat,255,cv::THRESH_BINARY);
+ cv::namedWindow("Saturation");
+ cv::imshow("Saturation",v[1]);
+
+ // Get back-projection of hue histogram
+ result= finder.find(hsv,0.0f,180.0f,ch,1);
+
+ cv::namedWindow("Result Hue");
+ cv::imshow("Result Hue",result);
+
+ // Eliminate low stauration pixels
+ cv::bitwise_and(result,v[1],result);
+ cv::namedWindow("Result Hue and");
+ cv::imshow("Result Hue and",result);
+
+ // Get back-projection of hue histogram
+ finder.setThreshold(-1.0f);
+ result= finder.find(hsv,0.0f,180.0f,ch,1);
+ cv::bitwise_and(result,v[1],result);
+ cv::namedWindow("Result Hue and raw");
+ cv::imshow("Result Hue and raw",result);
+
+ cv::Rect rect(110,260,35,40);
+ cv::rectangle(image, rect, cv::Scalar(0,0,255));
+
+ cv::TermCriteria criteria(cv::TermCriteria::MAX_ITER,10,0.01);
+ cout << "meanshift= " << cv::meanShift(result,rect,criteria) << endl;
+
+ cv::rectangle(image, rect, cv::Scalar(0,255,0));
+
+ // Display image
+ cv::namedWindow("Image 2 result");
+ cv::imshow("Image 2 result",image);
+
+ cv::waitKey();
+ return 0;
+}
\ No newline at end of file
/Chapter 04/finder.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 04/README.txt
===================================================================
--- Chapter 04/README.txt (nonexistent)
+++ Chapter 04/README.txt (revision 3)
@@ -0,0 +1,28 @@
+This directory contains material supporting chapter 4 of the cookbook:
+Computer Vision Programming using the OpenCV Library.
+by Robert Laganiere, Packt Publishing, 2011.
+
+Files:
+ histogram.h
+ histograms.cpp
+correspond to Recipes:
+Computing the Image Histogram
+Applying Look-up Tables to Modify Image Appearance
+
+Files:
+ colorhistogram.h
+ objectfinder.h
+ objectfinder.cpp
+correspond to Recipe:
+Backprojecting a Histogram to Detect Specific Image Content
+
+File:
+ finder.cpp
+correspond to Recipe:
+Using the Meanshift Algorithm to Find an Object
+
+Files:
+ imageComparator.h
+ retrieve.cpp
+correspond to Recipes:
+Retrieving Similar Images using Histogram Comparison
/Chapter 04/README.txt
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 05/morphology.cpp
===================================================================
--- Chapter 05/morphology.cpp (nonexistent)
+++ Chapter 05/morphology.cpp (revision 3)
@@ -0,0 +1,104 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 5 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+int main()
+{
+ // Read input image
+ cv::Mat image= cv::imread("../binary.bmp");
+ if (!image.data)
+ return 0;
+
+ // Display the image
+ cv::namedWindow("Image");
+ cv::imshow("Image",image);
+
+ // Erode the image
+ cv::Mat eroded;
+ cv::erode(image,eroded,cv::Mat());
+
+ // Display the eroded image
+ cv::namedWindow("Eroded Image");
+ cv::imshow("Eroded Image",eroded);
+
+ // Dilate the image
+ cv::Mat dilated;
+ cv::dilate(image,dilated,cv::Mat());
+
+ // Display the dialted image
+ cv::namedWindow("Dilated Image");
+ cv::imshow("Dilated Image",dilated);
+
+ // Erode the image with a larger s.e.
+ cv::Mat element(7,7,CV_8U,cv::Scalar(1));
+ cv::erode(image,eroded,element);
+
+ // Display the eroded image
+ cv::namedWindow("Eroded Image (7x7)");
+ cv::imshow("Eroded Image (7x7)",eroded);
+
+ // Erode the image 3 times.
+ cv::erode(image,eroded,cv::Mat(),cv::Point(-1,-1),3);
+
+ // Display the eroded image
+ cv::namedWindow("Eroded Image (3 times)");
+ cv::imshow("Eroded Image (3 times)",eroded);
+
+ // Close the image
+ cv::Mat element5(5,5,CV_8U,cv::Scalar(1));
+ cv::Mat closed;
+ cv::morphologyEx(image,closed,cv::MORPH_CLOSE,element5);
+
+ // Display the opened image
+ cv::namedWindow("Closed Image");
+ cv::imshow("Closed Image",closed);
+
+ // Open the image
+ cv::Mat opened;
+ cv::morphologyEx(image,opened,cv::MORPH_OPEN,element5);
+
+ // Display the opened image
+ cv::namedWindow("Opened Image");
+ cv::imshow("Opened Image",opened);
+
+ // Close and Open the image
+ cv::morphologyEx(image,image,cv::MORPH_CLOSE,element5);
+ cv::morphologyEx(image,image,cv::MORPH_OPEN,element5);
+
+ // Display the close/opened image
+ cv::namedWindow("Closed and Opened Image");
+ cv::imshow("Closed and Opened Image",image);
+ cv::imwrite("binaryGroup.bmp",image);
+
+ // Read input image
+ image= cv::imread("../binary.bmp");
+
+ // Open and Close the image
+ cv::morphologyEx(image,image,cv::MORPH_OPEN,element5);
+ cv::morphologyEx(image,image,cv::MORPH_CLOSE,element5);
+
+ // Display the close/opened image
+ cv::namedWindow("Opened and Closed Image");
+ cv::imshow("Opened and Closed Image",image);
+
+ cv::waitKey();
+ return 0;
+}
+
/Chapter 05/morphology.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 05/segment.cpp
===================================================================
--- Chapter 05/segment.cpp (nonexistent)
+++ Chapter 05/segment.cpp (revision 3)
@@ -0,0 +1,167 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 5 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include "watershedSegmentation.h"
+
+
+int main()
+{
+ // Read input image
+ cv::Mat image= cv::imread("../group.jpg");
+ if (!image.data)
+ return 0;
+
+ // Display the image
+ cv::namedWindow("Original Image");
+ cv::imshow("Original Image",image);
+
+ // Get the binary map
+ cv::Mat binary;
+ binary= cv::imread("../binary.bmp",0);
+
+ // Display the binary image
+ cv::namedWindow("Binary Image");
+ cv::imshow("Binary Image",binary);
+
+ // Eliminate noise and smaller objects
+ cv::Mat fg;
+ cv::erode(binary,fg,cv::Mat(),cv::Point(-1,-1),6);
+
+ // Display the foreground image
+ cv::namedWindow("Foreground Image");
+ cv::imshow("Foreground Image",fg);
+
+ // Identify image pixels without objects
+ cv::Mat bg;
+ cv::dilate(binary,bg,cv::Mat(),cv::Point(-1,-1),6);
+ cv::threshold(bg,bg,1,128,cv::THRESH_BINARY_INV);
+
+ // Display the background image
+ cv::namedWindow("Background Image");
+ cv::imshow("Background Image",bg);
+
+ // Show markers image
+ cv::Mat markers(binary.size(),CV_8U,cv::Scalar(0));
+ markers= fg+bg;
+ cv::namedWindow("Markers");
+ cv::imshow("Markers",markers);
+
+ // Create watershed segmentation object
+ WatershedSegmenter segmenter;
+
+ // Set markers and process
+ segmenter.setMarkers(markers);
+ segmenter.process(image);
+
+ // Display segmentation result
+ cv::namedWindow("Segmentation");
+ cv::imshow("Segmentation",segmenter.getSegmentation());
+
+ // Display watersheds
+ cv::namedWindow("Watersheds");
+ cv::imshow("Watersheds",segmenter.getWatersheds());
+
+ // Open another image
+ image= cv::imread("../tower.jpg");
+
+ // Identify background pixels
+ cv::Mat imageMask(image.size(),CV_8U,cv::Scalar(0));
+ cv::rectangle(imageMask,cv::Point(5,5),cv::Point(image.cols-5,image.rows-5),cv::Scalar(255),3);
+ // Identify foreground pixels (in the middle of the image)
+ cv::rectangle(imageMask,cv::Point(image.cols/2-10,image.rows/2-10),
+ cv::Point(image.cols/2+10,image.rows/2+10),cv::Scalar(1),10);
+
+ // Set markers and process
+ segmenter.setMarkers(imageMask);
+ segmenter.process(image);
+
+ // Display the image with markers
+ cv::rectangle(image,cv::Point(5,5),cv::Point(image.cols-5,image.rows-5),cv::Scalar(255,255,255),3);
+ cv::rectangle(image,cv::Point(image.cols/2-10,image.rows/2-10),
+ cv::Point(image.cols/2+10,image.rows/2+10),cv::Scalar(1,1,1),10);
+ cv::namedWindow("Image with marker");
+ cv::imshow("Image with marker",image);
+
+ // Display watersheds
+ cv::namedWindow("Watersheds of foreground object");
+ cv::imshow("Watersheds of foreground object",segmenter.getWatersheds());
+
+ // Open another image
+ image= cv::imread("../tower.jpg");
+
+ // define bounding rectangle
+ cv::Rect rectangle(50,70,image.cols-150,image.rows-180);
+
+ cv::Mat result; // segmentation result (4 possible values)
+ cv::Mat bgModel,fgModel; // the models (internally used)
+ // GrabCut segmentation
+ cv::grabCut(image, // input image
+ result, // segmentation result
+ rectangle,// rectangle containing foreground
+ bgModel,fgModel, // models
+ 1, // number of iterations
+ cv::GC_INIT_WITH_RECT); // use rectangle
+
+ // Get the pixels marked as likely foreground
+ cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ);
+ // Generate output image
+ cv::Mat foreground(image.size(),CV_8UC3,cv::Scalar(255,255,255));
+ image.copyTo(foreground,result); // bg pixels not copied
+
+ // draw rectangle on original image
+ cv::rectangle(image, rectangle, cv::Scalar(255,255,255),1);
+ cv::namedWindow("Image");
+ cv::imshow("Image",image);
+
+ // display result
+ cv::namedWindow("Segmented Image");
+ cv::imshow("Segmented Image",foreground);
+
+ // Open another image
+ image= cv::imread("../group.jpg");
+
+ // define bounding rectangle
+ cv::Rect rectangle2(10,100,380,180);
+
+ cv::Mat bkgModel,fgrModel; // the models (internally used)
+ // GrabCut segmentation
+ cv::grabCut(image, // input image
+ result, // segmentation result
+ rectangle2,bkgModel,fgrModel,5,cv::GC_INIT_WITH_RECT);
+ // Get the pixels marked as likely foreground
+// cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ);
+ result= result&1;
+ foreground.create(image.size(),CV_8UC3);
+ foreground.setTo(cv::Scalar(255,255,255));
+ image.copyTo(foreground,result); // bg pixels not copied
+
+ // draw rectangle on original image
+ cv::rectangle(image, rectangle2, cv::Scalar(255,255,255),1);
+ cv::namedWindow("Image 2");
+ cv::imshow("Image 2",image);
+
+ // display result
+ cv::namedWindow("Foreground objects");
+ cv::imshow("Foreground objects",foreground);
+
+ cv::waitKey();
+ return 0;
+}
/Chapter 05/segment.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 05/morpho2.cpp
===================================================================
--- Chapter 05/morpho2.cpp (nonexistent)
+++ Chapter 05/morpho2.cpp (revision 3)
@@ -0,0 +1,125 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 5 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include "morphoFeatures.h"
+
+int main()
+{
+ // Read input image
+ cv::Mat image= cv::imread("../building.jpg",0);
+ if (!image.data)
+ return 0;
+
+ // Display the image
+ cv::namedWindow("Image");
+ cv::imshow("Image",image);
+
+ // Create the morphological features instance
+ MorphoFeatures morpho;
+ morpho.setThreshold(40);
+
+ // Get the edges
+ cv::Mat edges;
+ edges= morpho.getEdges(image);
+
+ // Display the edge image
+ cv::namedWindow("Edge Image");
+ cv::imshow("Edge Image",edges);
+
+ // Get the corners
+ morpho.setThreshold(-1);
+ cv::Mat corners;
+ corners= morpho.getCorners(image);
+ cv::morphologyEx(corners,corners,cv::MORPH_TOPHAT,cv::Mat());
+ cv::threshold(corners, corners, 40, 255, cv::THRESH_BINARY_INV);
+
+ // Display the corner image
+ cv::namedWindow("Corner Image");
+ cv::imshow("Corner Image",corners);
+
+ // Display the corner on the image
+ morpho.drawOnImage(corners,image);
+ cv::namedWindow("Corners on Image");
+ cv::imshow("Corners on Image",image);
+
+ // Read and display image of square
+ image= cv::imread("../square.bmp",0);
+ cv::namedWindow("Square Image");
+ cv::imshow("Square Image",image);
+
+ // Creating the cross-shaped structuring element
+ cv::Mat cross(5,5,CV_8U,cv::Scalar(0));
+ for (int i=0; i<5; i++) {
+
+ cross.at<uchar>(2,i)= 1;
+ cross.at<uchar>(i,2)= 1;
+ }
+
+ // Dilate with a cross
+ cv::Mat result;
+ cv::dilate(image,result,cross);
+
+ // Display the result
+ cv::namedWindow("Dilated square with cross");
+ cv::imshow("Dilated square with cross",result);
+
+ // Creating the diamond-shaped structuring element
+ cv::Mat diamond(5,5,CV_8U,cv::Scalar(1));
+ diamond.at<uchar>(0,0)= 0;
+ diamond.at<uchar>(0,1)= 0;
+ diamond.at<uchar>(1,0)= 0;
+ diamond.at<uchar>(4,4)= 0;
+ diamond.at<uchar>(3,4)= 0;
+ diamond.at<uchar>(4,3)= 0;
+ diamond.at<uchar>(4,0)= 0;
+ diamond.at<uchar>(4,1)= 0;
+ diamond.at<uchar>(3,0)= 0;
+ diamond.at<uchar>(0,4)= 0;
+ diamond.at<uchar>(0,3)= 0;
+ diamond.at<uchar>(1,4)= 0;
+
+ // Erode with a diamond
+ cv::Mat result2;
+ cv::erode(result,result2,diamond);
+
+ // Display the result
+ cv::namedWindow("Eroded square with diamond");
+ cv::imshow("Eroded square with diamond",result2);
+
+ // Combine the images into one
+ cv::Mat final(100,300,CV_8U);
+ cv::Mat window= final(cv::Rect(0,0,100,100));
+ image.copyTo(window);
+ window= final(cv::Rect(100,0,100,100));
+ result.copyTo(window);
+ window= final(cv::Rect(200,0,100,100));
+ result2.copyTo(window);
+
+ // Display the combined result
+ cv::namedWindow("Combined");
+ cv::imshow("Combined",final);
+
+ // Save combined result
+ cv::imwrite("squares.bmp",final);
+
+ cv::waitKey();
+
+ return 0;
+}
/Chapter 05/morpho2.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 05/morphoFeatures.h
===================================================================
--- Chapter 05/morphoFeatures.h (nonexistent)
+++ Chapter 05/morphoFeatures.h (revision 3)
@@ -0,0 +1,142 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 5 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined MORPHOF
+#define MORPHOF
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+
+class MorphoFeatures {
+
+ private:
+
+ // threshold to produce binary image
+ int threshold;
+ // structuring elements used in corner detection
+ cv::Mat cross;
+ cv::Mat diamond;
+ cv::Mat square;
+ cv::Mat x;
+
+ void applyThreshold(cv::Mat& result) {
+
+ // Apply threshold on result
+ if (threshold>0)
+ cv::threshold(result, result, threshold, 255, cv::THRESH_BINARY_INV);
+ }
+
+ public:
+
+ MorphoFeatures() : threshold(-1), cross(5,5,CV_8U,cv::Scalar(0)),
+ diamond(5,5,CV_8U,cv::Scalar(1)),
+ square(5,5,CV_8U,cv::Scalar(1)),
+ x(5,5,CV_8U,cv::Scalar(0)){
+
+ // Creating the cross-shaped structuring element
+ for (int i=0; i<5; i++) {
+
+ cross.at<uchar>(2,i)= 1;
+ cross.at<uchar>(i,2)= 1;
+ }
+
+ // Creating the diamond-shaped structuring element
+ diamond.at<uchar>(0,0)= 0;
+ diamond.at<uchar>(0,1)= 0;
+ diamond.at<uchar>(1,0)= 0;
+ diamond.at<uchar>(4,4)= 0;
+ diamond.at<uchar>(3,4)= 0;
+ diamond.at<uchar>(4,3)= 0;
+ diamond.at<uchar>(4,0)= 0;
+ diamond.at<uchar>(4,1)= 0;
+ diamond.at<uchar>(3,0)= 0;
+ diamond.at<uchar>(0,4)= 0;
+ diamond.at<uchar>(0,3)= 0;
+ diamond.at<uchar>(1,4)= 0;
+
+ // Creating the x-shaped structuring element
+ for (int i=0; i<5; i++) {
+
+ x.at<uchar>(i,i)= 1;
+ x.at<uchar>(4-i,i)= 1;
+ }
+ }
+
+ void setThreshold(int t) {
+
+ threshold= t;
+ }
+
+ int getThreshold() const {
+
+ return threshold;
+ }
+
+ cv::Mat getEdges(const cv::Mat &image) {
+
+ // Get the gradient image
+ cv::Mat result;
+ cv::morphologyEx(image,result,cv::MORPH_GRADIENT,cv::Mat());
+
+ // Apply threshold to obtain a binary image
+ applyThreshold(result);
+
+ return result;
+ }
+
+ cv::Mat getCorners(const cv::Mat &image) {
+
+ cv::Mat result;
+
+ // Dilate with a cross
+ cv::dilate(image,result,cross);
+
+ // Erode with a diamond
+ cv::erode(result,result,diamond);
+
+ cv::Mat result2;
+ // Dilate with a X
+ cv::dilate(image,result2,x);
+
+ // Erode with a square
+ cv::erode(result2,result2,square);
+
+ // Corners are obtained by differencing
+ // the two closed images
+ cv::absdiff(result2,result,result);
+
+ // Apply threshold to obtain a binary image
+ applyThreshold(result);
+
+ return result;
+ }
+
+ void drawOnImage(const cv::Mat& binary, cv::Mat& image) {
+
+ cv::Mat_<uchar>::const_iterator it= binary.begin<uchar>();
+ cv::Mat_<uchar>::const_iterator itend= binary.end<uchar>();
+
+ // for each pixel
+ for (int i=0; it!= itend; ++it,++i) {
+ if (!*it)
+ cv::circle(image,cv::Point(i%image.step,i/image.step),5,cv::Scalar(255,0,0));
+ }
+ }
+};
+
+
+#endif
/Chapter 05/morphoFeatures.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 05/watershedSegmentation.h
===================================================================
--- Chapter 05/watershedSegmentation.h (nonexistent)
+++ Chapter 05/watershedSegmentation.h (revision 3)
@@ -0,0 +1,68 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 5 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined WATERSHS
+#define WATERSHS
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+
+class WatershedSegmenter {
+
+ private:
+
+ cv::Mat markers;
+
+ public:
+
+ void setMarkers(const cv::Mat& markerImage) {
+
+ // Convert to image of ints
+ markerImage.convertTo(markers,CV_32S);
+ }
+
+ cv::Mat process(const cv::Mat &image) {
+
+ // Apply watershed
+ cv::watershed(image,markers);
+
+ return markers;
+ }
+
+ // Return result in the form of an image
+ cv::Mat getSegmentation() {
+
+ cv::Mat tmp;
+ // all segment with label higher than 255
+ // will be assigned value 255
+ markers.convertTo(tmp,CV_8U);
+
+ return tmp;
+ }
+
+ // Return watershed in the form of an image
+ cv::Mat getWatersheds() {
+
+ cv::Mat tmp;
+ markers.convertTo(tmp,CV_8U,255,255);
+
+ return tmp;
+ }
+};
+
+
+#endif
/Chapter 05/watershedSegmentation.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 05/README.txt
===================================================================
--- Chapter 05/README.txt (nonexistent)
+++ Chapter 05/README.txt (revision 3)
@@ -0,0 +1,21 @@
+This directory contains material supporting chapter 5 of the cookbook:
+Computer Vision Programming using the OpenCV Library.
+by Robert Laganiere, Packt Publishing, 2011.
+
+File:
+ morphology.cpp
+correspond to Recipes:
+Eroding and Dilating Images using Morphological Filters
+Opening and Closing Images using Morphological Filters
+
+Files:
+ morpho2.cpp
+ morphoFeatures.h
+correspond to Recipe:
+Detecting edges and corners using morphological filters
+
+Files:
+ segment.cpp
+ watershedSegmentation.h
+correspond to Recipe:
+Segmenting images using watersheds
\ No newline at end of file
/Chapter 05/README.txt
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 06/derivatives.cpp
===================================================================
--- Chapter 06/derivatives.cpp (nonexistent)
+++ Chapter 06/derivatives.cpp (revision 3)
@@ -0,0 +1,181 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 6 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <iomanip>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include "laplacianZC.h"
+
+int main()
+{
+ // Read input image
+ cv::Mat image= cv::imread("../boldt.jpg",0);
+ if (!image.data)
+ return 0;
+
+ // Display the image
+ cv::namedWindow("Original Image");
+ cv::imshow("Original Image",image);
+
+ // Compute Sobel X derivative
+ cv::Mat sobelX;
+ cv::Sobel(image,sobelX,CV_8U,1,0,3,0.4,128);
+
+ // Display the image
+ cv::namedWindow("Sobel X Image");
+ cv::imshow("Sobel X Image",sobelX);
+
+ // Compute Sobel Y derivative
+ cv::Mat sobelY;
+ cv::Sobel(image,sobelY,CV_8U,0,1,3,0.4,128);
+
+ // Display the image
+ cv::namedWindow("Sobel Y Image");
+ cv::imshow("Sobel Y Image",sobelY);
+
+ // Compute norm of Sobel
+ cv::Sobel(image,sobelX,CV_16S,1,0);
+ cv::Sobel(image,sobelY,CV_16S,0,1);
+ cv::Mat sobel;
+ //compute the L1 norm
+ sobel= abs(sobelX)+abs(sobelY);
+
+ double sobmin, sobmax;
+ cv::minMaxLoc(sobel,&sobmin,&sobmax);
+ std::cout << "sobel value range: " << sobmin << " " << sobmax << std::endl;
+
+ // Print window pixel values
+ for (int i=0; i<12; i++) {
+ for (int j=0; j<12; j++)
+ std::cout << std::setw(5) << static_cast<int>(sobel.at<short>(i+135,j+362)) << " ";
+ std::cout << std::endl;
+ }
+ std::cout << std::endl;
+ std::cout << std::endl;
+ std::cout << std::endl;
+
+ // Conversion to 8-bit image
+ // sobelImage = -alpha*sobel + 255
+ cv::Mat sobelImage;
+ sobel.convertTo(sobelImage,CV_8U,-255./sobmax,255);
+
+ // Display the image
+ cv::namedWindow("Sobel Image");
+ cv::imshow("Sobel Image",sobelImage);
+
+ // Apply threshold to Sobel norm (low threshold value)
+ cv::Mat sobelThresholded;
+ cv::threshold(sobelImage, sobelThresholded, 225, 255, cv::THRESH_BINARY);
+
+ // Display the image
+ cv::namedWindow("Binary Sobel Image (low)");
+ cv::imshow("Binary Sobel Image (low)",sobelThresholded);
+
+ // Apply threshold to Sobel norm (high threshold value)
+ cv::threshold(sobelImage, sobelThresholded, 190, 255, cv::THRESH_BINARY);
+
+ // Display the image
+ cv::namedWindow("Binary Sobel Image (high)");
+ cv::imshow("Binary Sobel Image (high)",sobelThresholded);
+
+ // Compute Laplacian 3x3
+ cv::Mat laplace;
+ cv::Laplacian(image,laplace,CV_8U,1,1,128);
+
+ // Display the image
+ cv::namedWindow("Laplacian Image");
+ cv::imshow("Laplacian Image",laplace);
+
+ // Print window pixel values
+ for (int i=0; i<12; i++) {
+ for (int j=0; j<12; j++)
+ std::cout << std::setw(5) << static_cast<int>(laplace.at<uchar>(i+135,j+362))-128 << " ";
+ std::cout << std::endl;
+ }
+ std::cout << std::endl;
+ std::cout << std::endl;
+ std::cout << std::endl;
+
+ // Compute Laplacian 7x7
+ cv::Laplacian(image,laplace,CV_8U,7,0.01,128);
+
+ // Display the image
+ cv::namedWindow("Laplacian Image");
+ cv::imshow("Laplacian Image",laplace);
+
+ // Print window pixel values
+ for (int i=0; i<12; i++) {
+ for (int j=0; j<12; j++)
+ std::cout << std::setw(5) << static_cast<int>(laplace.at<uchar>(i+135,j+362))-128 << " ";
+ std::cout << std::endl;
+ }
+
+ // Extract small window
+ cv::Mat window(image,cv::Rect(362,135,12,12));
+ cv::namedWindow("Image window");
+ cv::imshow("Image window",window);
+ cv::imwrite("window.bmp",window);
+
+ // Compute Laplacian using LaplacianZC class
+ LaplacianZC laplacian;
+ laplacian.setAperture(7);
+ cv::Mat flap= laplacian.computeLaplacian(image);
+ double lapmin, lapmax;
+ cv::minMaxLoc(flap,&lapmin,&lapmax);
+ std::cout << "Laplacian value range=[" << lapmin << "," << lapmax << "]\n";
+ laplace= laplacian.getLaplacianImage();
+ cv::namedWindow("Laplacian Image (7x7)");
+ cv::imshow("Laplacian Image (7x7)",laplace);
+
+ // Print Laplacian values
+ std::cout << std::endl;
+ for (int i=0; i<12; i++) {
+ for (int j=0; j<12; j++)
+ std::cout << std::setw(5) << static_cast<int>(flap.at<float>(i+135,j+362)/100) << " ";
+ std::cout << std::endl;
+ }
+ std::cout << std::endl;
+
+ // Compute and display the zero-crossing points
+ cv::Mat zeros;
+ zeros= laplacian.getZeroCrossings(lapmax);
+ cv::namedWindow("Zero-crossings");
+ cv::imshow("Zero-crossings",zeros);
+
+ // Compute and display the zero-crossing points (Sobel version)
+ zeros= laplacian.getZeroCrossings();
+ zeros= laplacian.getZeroCrossingsWithSobel(50);
+ cv::namedWindow("Zero-crossings (2)");
+ cv::imshow("Zero-crossings (2)",zeros);
+
+ // Print window pixel values
+ for (int i=0; i<12; i++) {
+ for (int j=0; j<12; j++)
+ std::cout << std::setw(2) << static_cast<int>(zeros.at<uchar>(i+135,j+362)) << " ";
+ std::cout << std::endl;
+ }
+
+ // Display the image with window
+ cv::rectangle(image,cv::Point(362,135),cv::Point(374,147),cv::Scalar(255,255,255));
+ cv::namedWindow("Original Image with window");
+ cv::imshow("Original Image with window",image);
+
+ cv::waitKey();
+ return 0;
+}
/Chapter 06/derivatives.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 06/laplacianZC.h
===================================================================
--- Chapter 06/laplacianZC.h (nonexistent)
+++ Chapter 06/laplacianZC.h (revision 3)
@@ -0,0 +1,154 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 6 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined LAPLACEZC
+#define LAPLACEZC
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+
+class LaplacianZC {
+
+ private:
+
+ // original image
+ cv::Mat img;
+
+ // 32-bit float image containing the Laplacian
+ cv::Mat laplace;
+ // Aperture size of the laplacian kernel
+ int aperture;
+
+ public:
+
+ LaplacianZC() : aperture(3) {}
+
+ // Set the aperture size of the kernel
+ void setAperture(int a) {
+
+ aperture= a;
+ }
+
+ // Get the aperture size of the kernel
+ int getAperture() const {
+
+ return aperture;
+ }
+
+ // Compute the floating point Laplacian
+ cv::Mat computeLaplacian(const cv::Mat& image) {
+
+
+ // Compute Laplacian
+ cv::Laplacian(image,laplace,CV_32F,aperture);
+
+ // Keep local copy of the image
+ // (used for zero-crossings)
+ img= image.clone();
+
+ return laplace;
+ }
+
+ // Get the Laplacian result in 8-bit image
+ // zero corresponds to gray level 128
+ // if no scale is provided, then the max value will be
+ // scaled to intensity 255
+ // You must call computeLaplacian before calling this method
+ cv::Mat getLaplacianImage(double scale=-1.0) {
+
+ if (scale<0) {
+
+ double lapmin, lapmax;
+ cv::minMaxLoc(laplace,&lapmin,&lapmax);
+
+ scale= 127/ std::max(-lapmin,lapmax);
+ }
+
+ cv::Mat laplaceImage;
+ laplace.convertTo(laplaceImage,CV_8U,scale,128);
+
+ return laplaceImage;
+ }
+
+ // Get a binary image of the zero-crossings
+ // if the product of the two adjascent pixels is
+ // less than threshold then this zero-crossing will be ignored
+ cv::Mat getZeroCrossings(float threshold=1.0) {
+
+ // Create the iterators
+ cv::Mat_<float>::const_iterator it= laplace.begin<float>()+laplace.step1();
+ cv::Mat_<float>::const_iterator itend= laplace.end<float>();
+ cv::Mat_<float>::const_iterator itup= laplace.begin<float>();
+
+ // Binary image initialize to white
+ cv::Mat binary(laplace.size(),CV_8U,cv::Scalar(255));
+ cv::Mat_<uchar>::iterator itout= binary.begin<uchar>()+binary.step1();
+
+ // negate the input threshold value
+ threshold *= -1.0;
+
+ for ( ; it!= itend; ++it, ++itup, ++itout) {
+
+ // if the product of two adjascent pixel is negative
+ // then there is a sign change
+ if (*it * *(it-1) < threshold)
+ *itout= 0; // horizontal zero-crossing
+ else if (*it * *itup < threshold)
+ *itout= 0; // vertical zero-crossing
+ }
+
+ return binary;
+ }
+
+ // Get a binary image of the zero-crossings
+ // if the product of the two adjacent pixels is
+ // less than threshold then this zero-crossing will be ignored
+ cv::Mat getZeroCrossingsWithSobel(float threshold) {
+
+ cv::Mat sx;
+ cv::Sobel(img,sx,CV_32F,1,0,1);
+ cv::Mat sy;
+ cv::Sobel(img,sy,CV_32F,0,1,1);
+
+ // Create the iterators
+ cv::Mat_<float>::const_iterator it= laplace.begin<float>()+laplace.step1();
+ cv::Mat_<float>::const_iterator itend= laplace.end<float>();
+ cv::Mat_<float>::const_iterator itup= laplace.begin<float>();
+ cv::Mat_<float>::const_iterator itx= sx.begin<float>()+sx.step1();
+ cv::Mat_<float>::const_iterator ity= sy.begin<float>()+sy.step1();
+
+ // Binary image initialize to white
+ cv::Mat binary(laplace.size(),CV_8U,cv::Scalar(255));
+ cv::Mat_<uchar>::iterator itout= binary.begin<uchar>()+binary.step1();
+
+ for ( ; it!= itend; ++it, ++itup, ++itout, ++itx, ++ity) {
+
+ // if the product of two adjacent pixel is negative
+ // then there is a sign change
+ if (*it * *(it-1) < 0.0 && fabs(*ity) > threshold)
+ *itout= 0; // horizontal zero-crossing
+ else if (*it * *itup < 0.0 && fabs(*ity) > threshold)
+ *itout= 0; // vertical zero-crossing
+ }
+
+ return binary;
+ }
+
+};
+
+
+#endif
/Chapter 06/laplacianZC.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 06/filters.cpp
===================================================================
--- Chapter 06/filters.cpp (nonexistent)
+++ Chapter 06/filters.cpp (revision 3)
@@ -0,0 +1,135 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 6 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+int main()
+{
+ // Read input image
+ cv::Mat image= cv::imread("../boldt.jpg",0);
+ if (!image.data)
+ return 0;
+
+ // Display the image
+ cv::namedWindow("Original Image");
+ cv::imshow("Original Image",image);
+
+ // Blur the image
+ cv::Mat result;
+ cv::GaussianBlur(image,result,cv::Size(5,5),1.5);
+
+ // Display the blurred image
+ cv::namedWindow("Gaussian filtered Image");
+ cv::imshow("Gaussian filtered Image",result);
+
+ // Get the gaussian kernel (1.5)
+ cv::Mat gauss= cv::getGaussianKernel(9,1.5,CV_32F);
+
+ // Display kernel values
+ cv::Mat_<float>::const_iterator it= gauss.begin<float>();
+ cv::Mat_<float>::const_iterator itend= gauss.end<float>();
+ std::cout << "[";
+ for ( ; it!= itend; ++it) {
+ std::cout << *it << " ";
+ }
+ std::cout << "]" << std::endl;
+
+ // Get the gaussian kernel (0.5)
+ gauss= cv::getGaussianKernel(9,0.5,CV_32F);
+
+ // Display kernel values
+ it= gauss.begin<float>();
+ itend= gauss.end<float>();
+ std::cout << "[";
+ for ( ; it!= itend; ++it) {
+ std::cout << *it << " ";
+ }
+ std::cout << "]" << std::endl;
+
+ // Get the gaussian kernel (2.5)
+ gauss= cv::getGaussianKernel(9,2.5,CV_32F);
+
+ // Display kernel values
+ it= gauss.begin<float>();
+ itend= gauss.end<float>();
+ std::cout << "[";
+ for ( ; it!= itend; ++it) {
+ std::cout << *it << " ";
+ }
+ std::cout << "]" << std::endl;
+
+ // Get the Deriv kernel (2.5)
+ cv::Mat kx, ky;
+ cv::getDerivKernels(kx,ky,2,2,7,true);
+
+ // Display kernel values
+ cv::Mat_<float>::const_iterator kit= kx.begin<float>();
+ cv::Mat_<float>::const_iterator kitend= kx.end<float>();
+ std::cout << "[";
+ for ( ; kit!= kitend; ++kit) {
+ std::cout << *kit << " ";
+ }
+ std::cout << "]" << std::endl;
+
+ // Blur the image with a mean filter
+ cv::blur(image,result,cv::Size(5,5));
+
+ // Display the blurred image
+ cv::namedWindow("Mean filtered Image");
+ cv::imshow("Mean filtered Image",result);
+
+ // Read input image with salt&pepper noise
+ image= cv::imread("../salted.bmp",0);
+ if (!image.data)
+ return 0;
+
+ // Display the S&P image
+ cv::namedWindow("S&P Image");
+ cv::imshow("S&P Image",image);
+
+ // Blur the image with a mean filter
+ cv::blur(image,result,cv::Size(5,5));
+
+ // Display the blurred image
+ cv::namedWindow("Mean filtered S&P Image");
+ cv::imshow("Mean filtered S&P Image",result);
+
+ // Applying a median filter
+ cv::medianBlur(image,result,5);
+
+ // Display the blurred image
+ cv::namedWindow("Median filtered S&P Image");
+ cv::imshow("Median filtered S&P Image",result);
+
+ // Reduce by 4 the size of the image (the wrong way)
+ image= cv::imread("../boldt.jpg",0);
+ cv::Mat reduced(image.rows/2,image.cols/2,CV_8U);
+
+ for (int i=0; i<reduced.rows; i++)
+ for (int j=0; j<reduced.cols; j++)
+ reduced.at<uchar>(i,j)= image.at<uchar>(i*2,j*2);
+
+ // Display the reduced image
+ cv::namedWindow("Badly reduced Image");
+ cv::imshow("Badly reduced Image",reduced);
+
+ cv::waitKey();
+ return 0;
+}
/Chapter 06/filters.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 06/README.txt
===================================================================
--- Chapter 06/README.txt (nonexistent)
+++ Chapter 06/README.txt (revision 3)
@@ -0,0 +1,16 @@
+This directory contains material supporting chapter 6 of the cookbook:
+Computer Vision Programming using the OpenCV Library.
+by Robert Laganiere, Packt Publishing, 2011.
+
+File:
+ filters.cpp
+correspond to Recipes:
+Filtering Images using Low-pass Filters
+Filtering Images using a Median Filter
+
+Files:
+ dderivatives.cpp
+ laplacianZC.h
+correspond to Recipes:
+Applying Directional Filters to Detect Edges
+Computing the Laplacian of an Image
/Chapter 06/README.txt
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 07/blobs.cpp
===================================================================
--- Chapter 07/blobs.cpp (nonexistent)
+++ Chapter 07/blobs.cpp (revision 3)
@@ -0,0 +1,169 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 7 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <vector>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+int main()
+{
+ // Read input binary image
+ cv::Mat image= cv::imread("../binaryGroup.bmp",0);
+ if (!image.data)
+ return 0;
+
+ cv::namedWindow("Binary Image");
+ cv::imshow("Binary Image",image);
+
+ // Get the contours of the connected components
+ std::vector<std::vector<cv::Point>> contours;
+ cv::findContours(image,
+ contours, // a vector of contours
+ CV_RETR_EXTERNAL, // retrieve the external contours
+ CV_CHAIN_APPROX_NONE); // retrieve all pixels of each contours
+
+ // Print contours' length
+ std::cout << "Contours: " << contours.size() << std::endl;
+ std::vector<std::vector<cv::Point>>::const_iterator itContours= contours.begin();
+ for ( ; itContours!=contours.end(); ++itContours) {
+
+ std::cout << "Size: " << itContours->size() << std::endl;
+ }
+
+ // draw black contours on white image
+ cv::Mat result(image.size(),CV_8U,cv::Scalar(255));
+ cv::drawContours(result,contours,
+ -1, // draw all contours
+ cv::Scalar(0), // in black
+ 2); // with a thickness of 2
+
+ cv::namedWindow("Contours");
+ cv::imshow("Contours",result);
+
+ // Eliminate too short or too long contours
+ int cmin= 100; // minimum contour length
+ int cmax= 1000; // maximum contour length
+ std::vector<std::vector<cv::Point>>::const_iterator itc= contours.begin();
+ while (itc!=contours.end()) {
+
+ if (itc->size() < cmin || itc->size() > cmax)
+ itc= contours.erase(itc);
+ else
+ ++itc;
+ }
+
+ // draw contours on the original image
+ cv::Mat original= cv::imread("../group.jpg");
+ cv::drawContours(original,contours,
+ -1, // draw all contours
+ cv::Scalar(255,255,255), // in white
+ 2); // with a thickness of 2
+
+ cv::namedWindow("Contours on Animals");
+ cv::imshow("Contours on Animals",original);
+
+ // Let's now draw black contours on white image
+ result.setTo(cv::Scalar(255));
+ cv::drawContours(result,contours,
+ -1, // draw all contours
+ cv::Scalar(0), // in black
+ 1); // with a thickness of 1
+ image= cv::imread("../binaryGroup.bmp",0);
+
+ // testing the bounding box
+ cv::Rect r0= cv::boundingRect(cv::Mat(contours[0]));
+ cv::rectangle(result,r0,cv::Scalar(0),2);
+
+ // testing the enclosing circle
+ float radius;
+ cv::Point2f center;
+ cv::minEnclosingCircle(cv::Mat(contours[1]),center,radius);
+ cv::circle(result,cv::Point(center),static_cast<int>(radius),cv::Scalar(0),2);
+
+// cv::RotatedRect rrect= cv::fitEllipse(cv::Mat(contours[1]));
+// cv::ellipse(result,rrect,cv::Scalar(0),2);
+
+ // testing the approximate polygon
+ std::vector<cv::Point> poly;
+ cv::approxPolyDP(cv::Mat(contours[2]),poly,5,true);
+
+ std::cout << "Polygon size: " << poly.size() << std::endl;
+
+ // Iterate over each segment and draw it
+ std::vector<cv::Point>::const_iterator itp= poly.begin();
+ while (itp!=(poly.end()-1)) {
+ cv::line(result,*itp,*(itp+1),cv::Scalar(0),2);
+ ++itp;
+ }
+ // last point linked to first point
+ cv::line(result,*(poly.begin()),*(poly.end()-1),cv::Scalar(20),2);
+
+ // testing the convex hull
+ std::vector<cv::Point> hull;
+ cv::convexHull(cv::Mat(contours[3]),hull);
+
+ // Iterate over each segment and draw it
+ std::vector<cv::Point>::const_iterator it= hull.begin();
+ while (it!=(hull.end()-1)) {
+ cv::line(result,*it,*(it+1),cv::Scalar(0),2);
+ ++it;
+ }
+ // last point linked to first point
+ cv::line(result,*(hull.begin()),*(hull.end()-1),cv::Scalar(20),2);
+
+ // testing the moments
+
+ // iterate over all contours
+ itc= contours.begin();
+ while (itc!=contours.end()) {
+
+ // compute all moments
+ cv::Moments mom= cv::moments(cv::Mat(*itc++));
+
+ // draw mass center
+ cv::circle(result,
+ // position of mass center converted to integer
+ cv::Point(mom.m10/mom.m00,mom.m01/mom.m00),
+ 2,cv::Scalar(0),2); // draw black dot
+ }
+
+ cv::namedWindow("Some Shape descriptors");
+ cv::imshow("Some Shape descriptors",result);
+
+ // New call to findContours but with CV_RETR_LIST flag
+ image= cv::imread("../binaryGroup.bmp",0);
+
+ // Get the contours of the connected components
+ cv::findContours(image,
+ contours, // a vector of contours
+ CV_RETR_LIST, // retrieve the external and internal contours
+ CV_CHAIN_APPROX_NONE); // retrieve all pixels of each contours
+
+ // draw black contours on white image
+ result.setTo(cv::Scalar(255));
+ cv::drawContours(result,contours,
+ -1, // draw all contours
+ cv::Scalar(0), // in black
+ 2); // with a thickness of 2
+ cv::namedWindow("All Contours");
+ cv::imshow("All Contours",result);
+
+ cv::waitKey();
+ return 0;
+}
\ No newline at end of file
/Chapter 07/blobs.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 07/edgedetector.h
===================================================================
--- Chapter 07/edgedetector.h (nonexistent)
+++ Chapter 07/edgedetector.h (revision 3)
@@ -0,0 +1,121 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 6 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined SOBELEDGES
+#define SOBELEDGES
+
+#define PI 3.1415926
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+
+class EdgeDetector {
+
+ private:
+
+ // original image
+ cv::Mat img;
+
+ // 16-bit signed int image
+ cv::Mat sobel;
+
+ // Aperture size of the Sobel kernel
+ int aperture;
+
+ // Sobel magnitude
+ cv::Mat sobelMagnitude;
+
+ // Sobel orientation
+ cv::Mat sobelOrientation;
+
+ public:
+
+ EdgeDetector() : aperture(3) {}
+
+ // Set the aperture size of the kernel
+ void setAperture(int a) {
+
+ aperture= a;
+ }
+
+ // Get the aperture size of the kernel
+ int getAperture() const {
+
+ return aperture;
+ }
+
+ // Compute the Sobel
+ void computeSobel(const cv::Mat& image, cv::Mat &sobelX=cv::Mat(), cv::Mat &sobelY=cv::Mat()) {
+
+ // Compute Sobel
+ cv::Sobel(image,sobelX,CV_32F,1,0,aperture);
+ cv::Sobel(image,sobelY,CV_32F,0,1,aperture);
+
+ // Compute magnitude and orientation
+ cv::cartToPolar(sobelX,sobelY,sobelMagnitude,sobelOrientation);
+ }
+
+ // Get Sobel magnitude
+ // Make a copy if called more than once
+ cv::Mat getMagnitude() {
+
+ return sobelMagnitude;
+ }
+
+ // Get Sobel orientation
+ // Make a copy if called more than once
+ cv::Mat getOrientation() {
+
+ return sobelOrientation;
+ }
+
+ // Get a thresholded binary map
+ cv::Mat getBinaryMap(double threshold) {
+
+ cv::Mat bin;
+ cv::threshold(sobelMagnitude,bin,threshold,255,cv::THRESH_BINARY_INV);
+
+ return bin;
+ }
+
+ // Get a CV_8U image of the Sobel
+ cv::Mat getSobelImage() {
+
+ cv::Mat bin;
+
+ double minval, maxval;
+ cv::minMaxLoc(sobelMagnitude,&minval,&maxval);
+ sobelMagnitude.convertTo(bin,CV_8U,255/maxval);
+
+ return bin;
+ }
+
+ // Get a CV_8U image of the Sobel orientation
+ // 1 gray-level = 2 degrees
+ cv::Mat getSobelOrientationImage() {
+
+ cv::Mat bin;
+
+ sobelOrientation.convertTo(bin,CV_8U,90/PI);
+
+ return bin;
+ }
+
+};
+
+
+#endif
/Chapter 07/edgedetector.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 07/linefinder.h
===================================================================
--- Chapter 07/linefinder.h (nonexistent)
+++ Chapter 07/linefinder.h (revision 3)
@@ -0,0 +1,157 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 7 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined LINEF
+#define LINEF
+
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#define PI 3.1415926
+
+class LineFinder {
+
+ private:
+
+ // original image
+ cv::Mat img;
+
+ // vector containing the end points
+ // of the detected lines
+ std::vector<cv::Vec4i> lines;
+
+ // accumulator resolution parameters
+ double deltaRho;
+ double deltaTheta;
+
+ // minimum number of votes that a line
+ // must receive before being considered
+ int minVote;
+
+ // min length for a line
+ double minLength;
+
+ // max allowed gap along the line
+ double maxGap;
+
+ public:
+
+ // Default accumulator resolution is 1 pixel by 1 degree
+ // no gap, no mimimum length
+ LineFinder() : deltaRho(1), deltaTheta(PI/180), minVote(10), minLength(0.), maxGap(0.) {}
+
+ // Set the resolution of the accumulator
+ void setAccResolution(double dRho, double dTheta) {
+
+ deltaRho= dRho;
+ deltaTheta= dTheta;
+ }
+
+ // Set the minimum number of votes
+ void setMinVote(int minv) {
+
+ minVote= minv;
+ }
+
+ // Set line length and gap
+ void setLineLengthAndGap(double length, double gap) {
+
+ minLength= length;
+ maxGap= gap;
+ }
+
+ // Apply probabilistic Hough Transform
+ std::vector<cv::Vec4i> findLines(cv::Mat& binary) {
+
+ lines.clear();
+ cv::HoughLinesP(binary,lines,deltaRho,deltaTheta,minVote, minLength, maxGap);
+
+ return lines;
+ }
+
+ // Draw the detected lines on an image
+ void drawDetectedLines(cv::Mat &image, cv::Scalar color=cv::Scalar(255,255,255)) {
+
+ // Draw the lines
+ std::vector<cv::Vec4i>::const_iterator it2= lines.begin();
+
+ while (it2!=lines.end()) {
+
+ cv::Point pt1((*it2)[0],(*it2)[1]);
+ cv::Point pt2((*it2)[2],(*it2)[3]);
+
+ cv::line( image, pt1, pt2, color);
+
+ ++it2;
+ }
+ }
+
+ // Eliminates lines that do not have an orientation equals to
+ // the ones specified in the input matrix of orientations
+ // At least the given percentage of pixels on the line must
+ // be within plus or minus delta of the corresponding orientation
+ std::vector<cv::Vec4i> removeLinesOfInconsistentOrientations(
+ const cv::Mat &orientations, double percentage, double delta) {
+
+ std::vector<cv::Vec4i>::iterator it= lines.begin();
+
+ // check all lines
+ while (it!=lines.end()) {
+
+ // end points
+ int x1= (*it)[0];
+ int y1= (*it)[1];
+ int x2= (*it)[2];
+ int y2= (*it)[3];
+
+ // line orientation + 90o to get the parallel line
+ double ori1= atan2(static_cast<double>(y1-y2),static_cast<double>(x1-x2))+PI/2;
+ if (ori1>PI) ori1= ori1-2*PI;
+
+ double ori2= atan2(static_cast<double>(y2-y1),static_cast<double>(x2-x1))+PI/2;
+ if (ori2>PI) ori2= ori2-2*PI;
+
+ // for all points on the line
+ cv::LineIterator lit(orientations,cv::Point(x1,y1),cv::Point(x2,y2));
+ int i,count=0;
+ for(i = 0, count=0; i < lit.count; i++, ++lit) {
+
+ float ori= *(reinterpret_cast<float *>(*lit));
+
+ // is line orientation similar to gradient orientation ?
+ if (std::min(fabs(ori-ori1),fabs(ori-ori2))<delta)
+ count++;
+
+ }
+
+ double consistency= count/static_cast<double>(i);
+
+ // set to zero lines of inconsistent orientation
+ if (consistency < percentage) {
+
+ (*it)[0]=(*it)[1]=(*it)[2]=(*it)[3]=0;
+
+ }
+
+ ++it;
+ }
+
+ return lines;
+ }
+};
+
+
+#endif
/Chapter 07/linefinder.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 07/README.txt
===================================================================
--- Chapter 07/README.txt (nonexistent)
+++ Chapter 07/README.txt (revision 3)
@@ -0,0 +1,18 @@
+This directory contains material supporting chapter 7 of the cookbook:
+Computer Vision Programming using the OpenCV Library.
+by Robert Laganiere, Packt Publishing, 2011.
+
+Files:
+ edgedetector.h
+ linefinder.h
+ contours.cpp
+correspond to Recipes:
+Detecting Image Contours with the Canny Operator
+Detecting Lines in Images with the Hough Transform
+Fitting a Line to a Set of Points
+
+File:
+ blobs.cpp
+correspond to Recipes:
+Extracting the ComponentsÂ’ Contours
+Computing ComponentsÂ’ Shape Descriptors
/Chapter 07/README.txt
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 07/contours.cpp
===================================================================
--- Chapter 07/contours.cpp (nonexistent)
+++ Chapter 07/contours.cpp (revision 3)
@@ -0,0 +1,277 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 7 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <vector>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+
+#include "linefinder.h"
+#include "edgedetector.h"
+
+#define PI 3.1415926
+
+int main()
+{
+ // Read input image
+ cv::Mat image= cv::imread("../road.jpg",0);
+ if (!image.data)
+ return 0;
+
+ // Display the image
+ cv::namedWindow("Original Image");
+ cv::imshow("Original Image",image);
+
+ // Compute Sobel
+ EdgeDetector ed;
+ ed.computeSobel(image);
+
+ // Display the Sobel orientation
+ cv::namedWindow("Sobel (orientation)");
+ cv::imshow("Sobel (orientation)",ed.getSobelOrientationImage());
+ cv::imwrite("ori.bmp",ed.getSobelOrientationImage());
+
+ // Display the Sobel low threshold
+ cv::namedWindow("Sobel (low threshold)");
+ cv::imshow("Sobel (low threshold)",ed.getBinaryMap(125));
+
+ // Display the Sobel high threshold
+ cv::namedWindow("Sobel (high threshold)");
+ cv::imshow("Sobel (high threshold)",ed.getBinaryMap(350));
+
+ // Apply Canny algorithm
+ cv::Mat contours;
+ cv::Canny(image,contours,125,350);
+ cv::Mat contoursInv;
+ cv::threshold(contours,contoursInv,128,255,cv::THRESH_BINARY_INV);
+
+ // Display the image of contours
+ cv::namedWindow("Canny Contours");
+ cv::imshow("Canny Contours",contoursInv);
+
+ // Create a test image
+ cv::Mat test(200,200,CV_8U,cv::Scalar(0));
+ cv::line(test,cv::Point(100,0),cv::Point(200,200),cv::Scalar(255));
+ cv::line(test,cv::Point(0,50),cv::Point(200,200),cv::Scalar(255));
+ cv::line(test,cv::Point(0,200),cv::Point(200,0),cv::Scalar(255));
+ cv::line(test,cv::Point(200,0),cv::Point(0,200),cv::Scalar(255));
+ cv::line(test,cv::Point(100,0),cv::Point(100,200),cv::Scalar(255));
+ cv::line(test,cv::Point(0,100),cv::Point(200,100),cv::Scalar(255));
+
+ // Display the test image
+ cv::namedWindow("Test Image");
+ cv::imshow("Test Image",test);
+ cv::imwrite("test.bmp",test);
+
+ // Hough tranform for line detection
+ std::vector<cv::Vec2f> lines;
+ cv::HoughLines(contours,lines,1,PI/180,60);
+
+ // Draw the lines
+ cv::Mat result(contours.rows,contours.cols,CV_8U,cv::Scalar(255));
+ image.copyTo(result);
+
+ std::cout << "Lines detected: " << lines.size() << std::endl;
+
+ std::vector<cv::Vec2f>::const_iterator it= lines.begin();
+ while (it!=lines.end()) {
+
+ float rho= (*it)[0]; // first element is distance rho
+ float theta= (*it)[1]; // second element is angle theta
+
+ if (theta < PI/4. || theta > 3.*PI/4.) { // ~vertical line
+
+ // point of intersection of the line with first row
+ cv::Point pt1(rho/cos(theta),0);
+ // point of intersection of the line with last row
+ cv::Point pt2((rho-result.rows*sin(theta))/cos(theta),result.rows);
+ // draw a white line
+ cv::line( result, pt1, pt2, cv::Scalar(255), 1);
+
+ } else { // ~horizontal line
+
+ // point of intersection of the line with first column
+ cv::Point pt1(0,rho/sin(theta));
+ // point of intersection of the line with last column
+ cv::Point pt2(result.cols,(rho-result.cols*cos(theta))/sin(theta));
+ // draw a white line
+ cv::line( result, pt1, pt2, cv::Scalar(255), 1);
+ }
+
+ std::cout << "line: (" << rho << "," << theta << ")\n";
+
+ ++it;
+ }
+
+ // Display the detected line image
+ cv::namedWindow("Detected Lines with Hough");
+ cv::imshow("Detected Lines with Hough",result);
+
+ // Create LineFinder instance
+ LineFinder ld;
+
+ // Set probabilistic Hough parameters
+ ld.setLineLengthAndGap(100,20);
+ ld.setMinVote(80);
+
+ // Detect lines
+ std::vector<cv::Vec4i> li= ld.findLines(contours);
+ ld.drawDetectedLines(image);
+ cv::namedWindow("Detected Lines with HoughP");
+ cv::imshow("Detected Lines with HoughP",image);
+
+ std::vector<cv::Vec4i>::const_iterator it2= li.begin();
+ while (it2!=li.end()) {
+
+ std::cout << "(" << (*it2)[0] << ","<< (*it2)[1]<< ")-("
+ << (*it2)[2]<< "," << (*it2)[3] << ")" <<std::endl;
+
+ ++it2;
+ }
+
+ // Display one line
+ image= cv::imread("../road.jpg",0);
+ int n=0;
+ cv::line(image, cv::Point(li[n][0],li[n][1]),cv::Point(li[n][2],li[n][3]),cv::Scalar(255),5);
+ cv::namedWindow("One line of the Image");
+ cv::imshow("One line of the Image",image);
+
+ // Extract the contour pixels of the first detected line
+ cv::Mat oneline(image.size(),CV_8U,cv::Scalar(0));
+ cv::line(oneline, cv::Point(li[n][0],li[n][1]),cv::Point(li[n][2],li[n][3]),cv::Scalar(255),5);
+ cv::bitwise_and(contours,oneline,oneline);
+ cv::Mat onelineInv;
+ cv::threshold(oneline,onelineInv,128,255,cv::THRESH_BINARY_INV);
+ cv::namedWindow("One line");
+ cv::imshow("One line",onelineInv);
+
+ std::vector<cv::Point> points;
+
+ // Iterate over the pixels to obtain all point positions
+ for( int y = 0; y < oneline.rows; y++ ) {
+
+ uchar* rowPtr = oneline.ptr<uchar>(y);
+
+ for( int x = 0; x < oneline.cols; x++ ) {
+
+ // if on a contour
+ if (rowPtr[x]) {
+
+ points.push_back(cv::Point(x,y));
+ }
+ }
+ }
+
+ // find the best fitting line
+ cv::Vec4f line;
+ cv::fitLine(cv::Mat(points),line,CV_DIST_L2,0,0.01,0.01);
+
+ std::cout << "line: (" << line[0] << "," << line[1] << ")(" << line[2] << "," << line[3] << ")\n";
+
+ int x0= line[2];
+ int y0= line[3];
+ int x1= x0-200*line[0];
+ int y1= y0-200*line[1];
+ image= cv::imread("../road.jpg",0);
+ cv::line(image,cv::Point(x0,y0),cv::Point(x1,y1),cv::Scalar(0),3);
+ cv::namedWindow("Estimated line");
+ cv::imshow("Estimated line",image);
+
+ // eliminate inconsistent lines
+ ld.removeLinesOfInconsistentOrientations(ed.getOrientation(),0.4,0.1);
+
+ // Display the detected line image
+ image= cv::imread("../road.jpg",0);
+ ld.drawDetectedLines(image);
+ cv::namedWindow("Detected Lines (2)");
+ cv::imshow("Detected Lines (2)",image);
+
+ // Create a Hough accumulator
+ cv::Mat acc(200,180,CV_8U,cv::Scalar(0));
+
+ // Choose a point
+ int x=50, y=30;
+
+ // loop over all angles
+ for (int i=0; i<180; i++) {
+
+ double theta= i*PI/180.;
+
+ // find corresponding rho value
+ double rho= x*cos(theta)+y*sin(theta);
+ int j= static_cast<int>(rho+100.5);
+
+ std::cout << i << "," << j << std::endl;
+
+ // increment accumulator
+ acc.at<uchar>(j,i)++;
+ }
+
+ cv::imwrite("hough1.bmp",acc*100);
+
+ // Choose a second point
+ x=30, y=10;
+
+ // loop over all angles
+ for (int i=0; i<180; i++) {
+
+ double theta= i*PI/180.;
+ double rho= x*cos(theta)+y*sin(theta);
+ int j= static_cast<int>(rho+100.5);
+
+ acc.at<uchar>(j,i)++;
+ }
+
+ cv::namedWindow("Hough Accumulator");
+ cv::imshow("Hough Accumulator",acc*100);
+ cv::imwrite("hough2.bmp",acc*100);
+
+ // Detect circles
+ image= cv::imread("../chariot.jpg",0);
+ cv::GaussianBlur(image,image,cv::Size(5,5),1.5);
+ std::vector<cv::Vec3f> circles;
+ cv::HoughCircles(image, circles, CV_HOUGH_GRADIENT,
+ 2, // accumulator resolution (size of the image / 2)
+ 50, // minimum distance between two circles
+ 200, // Canny high threshold
+ 100, // minimum number of votes
+ 25, 100); // min and max radius
+
+ std::cout << "Circles: " << circles.size() << std::endl;
+
+ // Draw the circles
+ image= cv::imread("../chariot.jpg",0);
+ std::vector<cv::Vec3f>::const_iterator itc= circles.begin();
+
+ while (itc!=circles.end()) {
+
+ cv::circle(image,
+ cv::Point((*itc)[0], (*itc)[1]), // circle centre
+ (*itc)[2], // circle radius
+ cv::Scalar(255), // color
+ 2); // thickness
+
+ ++itc;
+ }
+
+ cv::namedWindow("Detected Circles");
+ cv::imshow("Detected Circles",image);
+
+ cv::waitKey();
+ return 0;
+}
\ No newline at end of file
/Chapter 07/contours.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 08/tracking.cpp
===================================================================
--- Chapter 08/tracking.cpp (nonexistent)
+++ Chapter 08/tracking.cpp (revision 3)
@@ -0,0 +1,108 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 8 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <vector>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/features2d/features2d.hpp>
+
+int main()
+{
+ // Read input images
+ cv::Mat image1= cv::imread("../church01.jpg",0);
+ cv::Mat image2= cv::imread("../church02.jpg",0);
+ if (!image1.data || !image2.data)
+ return 0;
+
+ // Display the images
+ cv::namedWindow("Right Image");
+ cv::imshow("Right Image",image1);
+ cv::namedWindow("Left Image");
+ cv::imshow("Left Image",image2);
+
+ // vector of keypoints
+ std::vector<cv::KeyPoint> keypoints1;
+ std::vector<cv::KeyPoint> keypoints2;
+
+ // Construction of the SURF feature detector
+ cv::SurfFeatureDetector surf(3000);
+
+ // Detection of the SURF features
+ surf.detect(image1,keypoints1);
+ surf.detect(image2,keypoints2);
+
+ std::cout << "Number of SURF points (1): " << keypoints1.size() << std::endl;
+ std::cout << "Number of SURF points (2): " << keypoints2.size() << std::endl;
+
+ // Draw the kepoints
+ cv::Mat imageKP;
+ cv::drawKeypoints(image1,keypoints1,imageKP,cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
+ cv::namedWindow("Right SURF Features");
+ cv::imshow("Right SURF Features",imageKP);
+ cv::drawKeypoints(image2,keypoints2,imageKP,cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
+ cv::namedWindow("Left SURF Features");
+ cv::imshow("Left SURF Features",imageKP);
+
+ // Construction of the SURF descriptor extractor
+ cv::SurfDescriptorExtractor surfDesc;
+
+ // Extraction of the SURF descriptors
+ cv::Mat descriptors1, descriptors2;
+ surfDesc.compute(image1,keypoints1,descriptors1);
+ surfDesc.compute(image2,keypoints2,descriptors2);
+
+ std::cout << "descriptor matrix size: " << descriptors1.rows << " by " << descriptors1.cols << std::endl;
+
+ // Construction of the matcher
+ cv::BruteForceMatcher<cv::L2<float>> matcher;
+
+ // Match the two image descriptors
+ std::vector<cv::DMatch> matches;
+ matcher.match(descriptors1,descriptors2, matches);
+
+ std::cout << "Number of matched points: " << matches.size() << std::endl;
+
+ std::nth_element(matches.begin(), // initial position
+ matches.begin()+24, // position of the sorted element
+ matches.end()); // end position
+ // remove all elements after the 25th
+ matches.erase(matches.begin()+25, matches.end());
+
+ cv::Mat imageMatches;
+ cv::drawMatches(image1,keypoints1, // 1st image and its keypoints
+ image2,keypoints2, // 2nd image and its keypoints
+ matches, // the matches
+ imageMatches, // the image produced
+ cv::Scalar(255,255,255)); // color of the lines
+ cv::namedWindow("Matches");
+ cv::imshow("Matches",imageMatches);
+
+ cv::waitKey();
+ return 0;
+
+ int size=7;
+ cv::Mat imaf1;
+ image1.convertTo(imaf1,CV_32F);
+
+ cv::Mat imaf2;
+ image2.convertTo(imaf2,CV_32F);
+
+ cv::waitKey();
+ return 0;
+}
\ No newline at end of file
/Chapter 08/tracking.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 08/harrisDetector.h
===================================================================
--- Chapter 08/harrisDetector.h (nonexistent)
+++ Chapter 08/harrisDetector.h (revision 3)
@@ -0,0 +1,146 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 8 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#if !defined HARRISD
+#define HARRISD
+
+#include <vector>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/features2d/features2d.hpp>
+
+class HarrisDetector {
+
+ private:
+
+ // 32-bit float image of corner strength
+ cv::Mat cornerStrength;
+ // 32-bit float image of thresholded corners
+ cv::Mat cornerTh;
+ // image of local maxima (internal)
+ cv::Mat localMax;
+ // size of neighbourhood for derivatives smoothing
+ int neighbourhood;
+ // aperture for gradient computation
+ int aperture;
+ // Harris parameter
+ double k;
+ // maximum strength for threshold computation
+ double maxStrength;
+ // calculated threshold (internal)
+ double threshold;
+ // size of neighbourhood for non-max suppression
+ int nonMaxSize;
+ // kernel for non-max suppression
+ cv::Mat kernel;
+
+ public:
+
+ HarrisDetector() : neighbourhood(3), aperture(3), k(0.1), maxStrength(0.0), threshold(0.01), nonMaxSize(3) {
+
+ setLocalMaxWindowSize(nonMaxSize);
+ }
+
+ // Create kernel used in non-maxima suppression
+ void setLocalMaxWindowSize(int size) {
+
+ nonMaxSize= size;
+ kernel.create(nonMaxSize,nonMaxSize,CV_8U);
+ }
+
+ // Compute Harris corners
+ void detect(const cv::Mat& image) {
+
+ // Harris computation
+ cv::cornerHarris(image,cornerStrength,
+ neighbourhood,// neighborhood size
+ aperture, // aperture size
+ k); // Harris parameter
+
+ // internal threshold computation
+ double minStrength; // not used
+ cv::minMaxLoc(cornerStrength,&minStrength,&maxStrength);
+
+ // local maxima detection
+ cv::Mat dilated; // temporary image
+ cv::dilate(cornerStrength,dilated,cv::Mat());
+ cv::compare(cornerStrength,dilated,localMax,cv::CMP_EQ);
+ }
+
+ // Get the corner map from the computed Harris values
+ cv::Mat getCornerMap(double qualityLevel) {
+
+ cv::Mat cornerMap;
+
+ // thresholding the corner strength
+ threshold= qualityLevel*maxStrength;
+ cv::threshold(cornerStrength,cornerTh,threshold,255,cv::THRESH_BINARY);
+
+ // convert to 8-bit image
+ cornerTh.convertTo(cornerMap,CV_8U);
+
+ // non-maxima suppression
+ cv::bitwise_and(cornerMap,localMax,cornerMap);
+
+ return cornerMap;
+ }
+
+ // Get the feature points vector from the computed Harris values
+ void getCorners(std::vector<cv::Point> &points, double qualityLevel) {
+
+ // Get the corner map
+ cv::Mat cornerMap= getCornerMap(qualityLevel);
+ // Get the corners
+ getCorners(points, cornerMap);
+ }
+
+ // Get the feature points vector from the computed corner map
+ void getCorners(std::vector<cv::Point> &points, const cv::Mat& cornerMap) {
+
+ // Iterate over the pixels to obtain all feature points
+ for( int y = 0; y < cornerMap.rows; y++ ) {
+
+ const uchar* rowPtr = cornerMap.ptr<uchar>(y);
+
+ for( int x = 0; x < cornerMap.cols; x++ ) {
+
+ // if it is a feature point
+ if (rowPtr[x]) {
+
+ points.push_back(cv::Point(x,y));
+ }
+ }
+ }
+ }
+
+ // Draw circles at feature point locations on an image
+ void drawOnImage(cv::Mat &image, const std::vector<cv::Point> &points, cv::Scalar color= cv::Scalar(255,255,255), int radius=3, int thickness=2) {
+
+ std::vector<cv::Point>::const_iterator it= points.begin();
+
+ // for all corners
+ while (it!=points.end()) {
+
+ // draw a circle at each corner location
+ cv::circle(image,*it,radius,color,thickness);
+ ++it;
+ }
+ }
+};
+
+#endif
/Chapter 08/harrisDetector.h
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 08/README.txt
===================================================================
--- Chapter 08/README.txt (nonexistent)
+++ Chapter 08/README.txt (revision 3)
@@ -0,0 +1,16 @@
+This directory contains material supporting chapter 8 of the cookbook:
+Computer Vision Programming using the OpenCV Library.
+by Robert Laganiere, Packt Publishing, 2011.
+
+Files:
+ harrisDetector.h
+ interestPoints.cpp
+correspond to Recipes:
+Detecting Harris Corners
+Detecting Fast Features
+Detecting the Scale-Invariant SURF Features
+
+File:
+ blobs.cpp
+correspond to Recipe:
+Describing SURF Features
\ No newline at end of file
/Chapter 08/README.txt
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: Chapter 08/interestPoints.cpp
===================================================================
--- Chapter 08/interestPoints.cpp (nonexistent)
+++ Chapter 08/interestPoints.cpp (revision 3)
@@ -0,0 +1,184 @@
+/*------------------------------------------------------------------------------------------*\
+ This file contains material supporting chapter 8 of the cookbook:
+ Computer Vision Programming using the OpenCV Library.
+ by Robert Laganiere, Packt Publishing, 2011.
+
+ This program is free software; permission is hereby granted to use, copy, modify,
+ and distribute this source code, or portions thereof, for any purpose, without fee,
+ subject to the restriction that the copyright notice may not be removed
+ or altered from any source or altered source distribution.
+ The software is released on an as-is basis and without any warranties of any kind.
+ In particular, the software is not guaranteed to be fault-tolerant or free from failure.
+ The author disclaims all warranties with regard to this software, any use,
+ and any consequent failure, is purely the responsibility of the user.
+
+ Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
+\*------------------------------------------------------------------------------------------*/
+
+#include <iostream>
+#include <vector>
+#include <opencv2/core/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/features2d/features2d.hpp>
+
+#include "harrisDetector.h"
+
+int main()
+{
+ // Read input image
+ cv::Mat image= cv::imread("../church01.jpg",0);
+ if (!image.data)
+ return 0;
+
+ // Display the image
+ cv::namedWindow("Original Image");
+ cv::imshow("Original Image",image);
+
+ // Detect Harris Corners
+ cv::Mat cornerStrength;
+ cv::cornerHarris(image,cornerStrength,
+ 3, // neighborhood size
+ 3, // aperture size
+ 0.01); // Harris parameter
+
+ // threshold the corner strengths
+ cv::Mat harrisCorners;
+ double threshold= 0.0001;
+ cv::threshold(cornerStrength,harrisCorners,
+ threshold,255,cv::THRESH_BINARY_INV);
+
+ // Display the corners
+ cv::namedWindow("Harris Corner Map");
+ cv::imshow("Harris Corner Map",harrisCorners);
+
+ // Create Harris detector instance
+ HarrisDetector harris;
+ // Compute Harris values
+ harris.detect(image);
+ // Detect Harris corners
+ std::vector<cv::Point> pts;
+ harris.getCorners(pts,0.01);
+ // Draw Harris corners
+ harris.drawOnImage(image,pts);
+
+ // Display the corners
+ cv::namedWindow("Harris Corners");
+ cv::imshow("Harris Corners",image);
+
+ // Read input image
+ image= cv::imread("../church01.jpg",0);
+
+ // Compute good features to track
+ std::vector<cv::Point2f> corners;
+ cv::goodFeaturesToTrack(image,corners,
+ 500, // maximum number of corners to be returned
+ 0.01, // quality level
+ 10); // minimum allowed distance between points
+
+ // for all corners
+ std::vector<cv::Point2f>::const_iterator it= corners.begin();
+ while (it!=corners.end()) {
+
+ // draw a circle at each corner location
+ cv::circle(image,*it,3,cv::Scalar(255,255,255),2);
+ ++it;
+ }
+
+ // Display the corners
+ cv::namedWindow("Good Features to Track");
+ cv::imshow("Good Features to Track",image);
+
+ // Read input image
+ image= cv::imread("../church01.jpg",0);
+
+ // vector of keypoints
+ std::vector<cv::KeyPoint> keypoints;
+ // Construction of the Good Feature to Track detector
+ cv::GoodFeaturesToTrackDetector gftt(
+ 500, // maximum number of corners to be returned
+ 0.01, // quality level
+ 10); // minimum allowed distance between points
+ // point detection using FeatureDetector method
+ gftt.detect(image,keypoints);
+
+ cv::drawKeypoints(image, // original image
+ keypoints, // vector of keypoints
+ image, // the resulting image
+ cv::Scalar(255,255,255), // color of the points
+ cv::DrawMatchesFlags::DRAW_OVER_OUTIMG); //drawing flag
+
+ // Display the corners
+ cv::namedWindow("Good Features to Track Detector");
+ cv::imshow("Good Features to Track Detector",image);
+
+ // Read input image
+ image= cv::imread("../church01.jpg",0);
+
+ keypoints.clear();
+ cv::FastFeatureDetector fast(40);
+ fast.detect(image,keypoints);
+
+ cv::drawKeypoints(image,keypoints,image,cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_OVER_OUTIMG);
+
+ // Display the corners
+ cv::namedWindow("FAST Features");
+ cv::imshow("FAST Features",image);
+
+ // Read input image
+ image= cv::imread("../church03.jpg",0);
+
+ keypoints.clear();
+ // Construct the SURF feature detector object
+ cv::SurfFeatureDetector surf(2500);
+ // Detect the SURF features
+ surf.detect(image,keypoints);
+
+ cv::Mat featureImage;
+ cv::drawKeypoints(image,keypoints,featureImage,cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
+
+ // Display the corners
+ cv::namedWindow("SURF Features");
+ cv::imshow("SURF Features",featureImage);
+
+ // Read input image
+ image= cv::imread("../church01.jpg",0);
+
+ keypoints.clear();
+ // Construct the SURF feature detector object
+ cv::SiftFeatureDetector sift(
+ 0.03, // feature threshold
+ 10.); // threshold to reduce
+ // sensitivity to lines
+
+ // Detect the SURF features
+ sift.detect(image,keypoints);
+
+ cv::drawKeypoints(image,keypoints,featureImage,cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
+
+ // Display the corners
+ cv::namedWindow("SIFT Features");
+ cv::imshow("SIFT Features",featureImage);
+
+ // Read input image
+ image= cv::imread("../church01.jpg",0);
+
+ keypoints.clear();
+
+ cv::MserFeatureDetector mser;
+ mser.detect(image,keypoints);
+
+ // Draw the keypoints with scale and orientation information
+ cv::drawKeypoints(image, // original image
+ keypoints, // vector of keypoints
+ featureImage, // the resulting image
+ cv::Scalar(255,255,255), // color of the points
+ cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS); //drawing flag
+
+ // Display the corners
+ cv::namedWindow("MSER Features");
+ cv::imshow("MSER Features",featureImage);
+
+ cv::waitKey();
+ return 0;
+}
\ No newline at end of file
/Chapter 08/interestPoints.cpp
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property