Professional Documents
Culture Documents
OpenCV DIY
1.0
2006/3/13
1.1
2006/7/21-8/2
1.2
2006/8/17
1.3
2007/3/6
1.4
2007/3/11
6.6
6.7
OpenCV trap
bug
Editor
Personal Website
http://www.tintinpiano.com/
http://euler-amon.blogspot.com/
-1-
OpenCV DIY
1
2
3
3.1
3.2
3.3
4
4.1
4.2
4.3
5
5.1
OpenCV ................................................................................................................................................. 3
OpenCV libray Download && Install .................................................................................. 3
VC 6.0 OpenCV............................................................................................................. 4
Environment configuration ........................................................................................ 4
OpenCVDLL ................................................................................. 6
.h ............................................................................................................................. 6
.Net 2005 VC++OpenCV ............................................................................................ 7
Environment configuration ........................................................................................ 7
OpenCVDLL ................................................................................. 9
.h ............................................................................................................................. 9
.............................................................................................................................................. 10
openCVOptical Flow ...................................................................................................... 10
5.2
OpenCV Reference Manual ................................................................................................................... 10
5.3
OpenCV ........................................................................................................................... 10
6 .................................................................................................................................. 11
6.1
(BMPJPEG)LoadImage ....................................................................... 11
6.2
Gaussian Blur ...................................................................................................................... 11
6.3
Pixel ...................................................................................................................... 11
6.4
AVICaptureAVI ............................................................................................. 11
6.5
IplImageimageunsigned char?........................................... 13
6.6
AX=B(SVD)(Stack) ......................................................................... 13
6.7
AX=B(SVD)(Heap).......................................................................... 14
6.8
EigenValueEigenVector .................................................................................................................. 16
7 OpenCVOpenCVTrapBug ......................................................................... 18
7.1
cvSolve.......................................................................................................................................... 18
7.2
cvThreshold ................................................................................................................................. 18
-2-
OpenCV DIY
1 OpenCV
OpenCVIntel
paperOpenCV
! OpenCVCode
(Eigen Value)
(MeanMedianVariance)OpenCV
opencv-winbeta5
OpenCV
-3-
OpenCV DIY
3 VC 6.0 OpenCV
3.1 Environment configuration
I.
ALT + F7 LINK
cv.lib highgui.lib cxcore.lib
-4-
OpenCV DIY
http://www.site.uottawa.ca/~laganier/tutorial/opencv+directshow/cvision.htm
-5-
OpenCV DIY
3.3 .h
OpenCV library.h .cpp .h
#include <cv.h>
#include <highgui.h>
#include <cxcore.h>
OpenCV
-6-
OpenCV DIY
Link lib
menu [Project]Property Linker Input Additional
Dependencies libcv.lib highgui.lib cxcore.lib
[] Debug Release
II. Include
menu [Tools]Options Projects and Solutions VC++ Directories
Show directories for Include files
C:\Program Files\openCV\otherlibs\highgui
C:\Program Files\openCV\cv\include
C:\Program Files\openCV\cvaux\include
C:\Program Files\openCV\cxcore\include
-7-
OpenCV DIY
C:\Program Files\openCV\bin
III. Lib
menu [Tools]Options Projects and Solutions VC++ Directories
Show directories for Library files
C:\Program Files\openCV\lib
C:\Program Files\openCV\bin
-8-
OpenCV DIY
4.3 .h
OpenCV library.h .cpp .h
#include <cv.h>
#include <highgui.h>
#include <cxcore.h>
OpenCV
-9-
OpenCV DIY
5
5.1 openCV Optical Flow
http://ai.stanford.edu/~dstavens/cs223b/stavens_opencv_optical_flow.pdf
5.3 OpenCV
C:\Program Files\OpenCV\samples\c OpenCV
(.c )(.exe)contour.c
contour.exe
contour.c
- 10 -
OpenCV DIY
! DLL
cv097.dll cxcore097.dll highgui097.dll C:\Program
Files\OpenCV\bin
6
6.1 (BMPJPEG) LoadImage
6.2 Gaussian Blur
Gaussian button button
void COpenCVView::OnBUTTONGaussianSmooth()
{
if(ifLoadFile)
{
// IPL_DEPTH_8U unsigned char , 3 3 channel
// cv_smoothed_image size cv_color_image
IplImage* cv_smoothed_image =
cvCreateImage( cvGetSize(cv_color_image), IPL_DEPTH_8U , 3 );
// Guassian Smooth, Window Size 5
cvSmooth(cv_color_image, cv_smoothed_image, CV_GAUSSIAN, 5 , 5);
// windowcv_smoothed_image
cvNamedWindow("Smoothed Image", 1 );
cvShowImage("Smoothed Image", cv_smoothed_image);
// cv_gray_image
cvReleaseImage(&cv_smoothed_image);
}
else
MessageBox("Load Image File First!");
}
6.3 Pixel
// (Threshold Image)
for( int i=0; i<imgHeight; i++)
for( int j=0; j<imgWidth; j++)
{
// img
intensity = cvRound(cvGetReal2D(img, i, j);
if(intensity > 255)
cvSetReal2D(cv_gray, i, j, 255);
else if(intensity < 0)
cvSetReal2D(cv_gray, i, j, 0);
else
cvSetReal2D(cv_gray, i, j, intensity);
}
- 11 -
OpenCV DIY
IplImage* image = 0;
if(!cvGrabFrame(capture)){
// capture a frame
printf("Could not grab a frame\n\7");
exit(0);
}
image = cvRetrieveFrame(capture);
frameH (Height)
frameW (Width)
fps FrameRate
numFrames frame
int
int
int
int
frameH
frameW
fps
numFrames
=
=
=
=
(int)
(int)
(int)
(int)
cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
// Grab Frame
if(!cvGrabFrame(capture)){
// capture a frame
printf("Could not grab a frame\n\7");
exit(0);
}
img = cvRetrieveFrame(capture);
- 12 -
OpenCV DIY
A= 4 5 6 B= 2
1
7 8 9
OpenCV AX=B X ?
double va[] = {
1, 2, 3,
4, 5, 6,
7, 8, 9,
};
double vb[] = {3, 2, 1};
double vx[3];
CvMat cvA, cvB, cvX;
- 13 -
OpenCV DIY
// va Initialize cvA 3 x 3
cvInitMatHeader(&cvA, 3, 3, CV_64FC1, va);
// vb Initialize cvB 3 x 1
cvInitMatHeader(&cvB, 3, 1, CV_64FC1, vb);
// vx Initialize cvX 3 x 1
cvInitMatHeader(&cvX, 3, 1, CV_64FC1, vx);
// cvX (cvA cvX = cvB)
//CV_SVD SVD CV_LU LU
cvSolve(&cvA, &cvB, &cvX, CV_SVD);
// cvX
//cvX 3 X 1
//cvGetReal2D(&cvX, row, column);
double x[3];
x[0] = cvGetReal2D(&cvX, 0, 0);
x[1] = cvGetReal2D(&cvX, 1, 0);
x[2] = cvGetReal2D(&cvX, 2, 0);
OpenCV DIY
y = e->Y;
tempPoint = Point(x,y);
testPoints->Add(tempPoint);
OpenCV DIY
6.8 EigenValueEigenVector
Matrix/vector operations
CvMat* A = cvCreateMat(3,3,CV_32FC1);
CvMat* E = cvCreateMat(3,3,CV_32FC1);
CvMat* l = cvCreateMat(3,1,CV_32FC1);
OpenCV DIY
double first_eigenvector[3];
eigenvector [0] = cvGetReal2D(&cvE, 0, 0);
eigenvector [1] = cvGetReal2D(&cvE, 0, 1);
eigenvector [2] = cvGetReal2D(&cvE, 0, 2);
// 2 EigenValue
double second_eigenvalue = cvGetReal2D(&cvX, 1 ,0);
// 2 EigenValue EigenVector
double second_eigenvector[3];
second_eigenvector [0] = cvGetReal2D(&cvE, 1, 0);
second_eigenvector [1] = cvGetReal2D(&cvE, 1, 1);
second_eigenvector [2] = cvGetReal2D(&cvE, 1, 2);
- 17 -
OpenCV DIY
OpenCV
7.2 cvThreshold
cvThreshold CV_THRESH_BINARY
CV_THRESH_BINARY_INV OpenCV
Bug
- 18 -