Computer Vision - Experiment 15 - Fast corner point detection experiments on video

计算机视觉 - 实验十五 对视频的快速角点检测实验

Computer Vision - Experiment 15 - Fast corner point detection experiments on video

Experimental objectives and requirements

  Understand the basic principle of corner point detection; master the code writing method to implement corner point detection.

Experiment content

   (i) New project .

   (ii) Configure OpenCV in VS2015.

   (iii) Opening video files using the VideoCapture class;

   (iv) Reading a frame from a video;

   (v) Convert the grayscale map and detect the corner points.

   (vi) traverse each point, plot it, and display the corner points in the original image.

Experimental apparatus, equipment

  A computer with Windows 7 operating system and Visual Studio 2015 installed.

Experimental principle

   (i) Corner point detection is a - method used in computer vision systems to obtain image features. A corner point is usually defined as the intersection of two edges, and more strictly speaking, the local neighborhood of a corner point should have two different regions with different directions of the boundary. In practice, most of the so-called corner detection methods detect image points with specific features, not just “corner points”. These feature points have specific coordinates in the image and have certain mathematical characteristics, such as local maximum or minimum grayscale;

   (ii) Corner points are used extensively to solve a range of problems such as object recognition, image recognition, image matching, visual tracking, and 3D reconstruction. Instead of looking at the whole picture, we select certain special points and then analyze them locally and purposefully. This method is of practical value if a sufficient number of such points can be detected, while they are well differentiated and stable features can be pinpointed;

   (iii) A very important evaluation criterion for corner point detection methods is their ability to detect the same or similar features in multiple images and to cope with image changes such as lighting changes, image rotation, etc. The Shi-Tomasi algorithm is an improvement of the Harris algorithm,This experiment shows that for the same target in a video by playing a video, the Shi- Tomasi algorithm has a strong robustness for the corner points obtained for the same target in the video.

Experimental steps

   (i) Create a Visual Studio 2015 console program;

   (ii) Configure OpenCV in Visual Studio 2015;

   (iii) Call the open function of the VideoCapture class to open the video;

   (iv) Call the “»” method of the VideoCapture class to read a frame of the video;

   (v) call the cvtColor function to convert the grayscale map and call the goodFeaturesToTrack function to detect the corner points.

   (vi) traverse each point and call circle to plot the corner points in the original image.

Experimental notes

   (i) The method of configuring OpenCV in VS after completing the installation of OpenCV;

   (ii) The functions and usage of the VideoCapture class;

   (iii) The functions and usage of the cvtColor function;

   (iv) The functions and usage of the goodFeaturesToTrack function.

Experimental results

   (i) Experimental code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//------------------------------【头文件、命名空间包含部分】----------------------------
//		描述:包含程序所使用的头文件和命名空间
//-------------------------------------------------------------------------------------
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/features2d/features2d.hpp"
#include <iostream>
#include <list>
#include <vector>
using namespace std;
using namespace cv;
//---------------------------------【help( )函数】--------------------------------------
//		 描述:输出一些帮助信息
//-----------------------------------------------------------------------------------

int Harris(Mat &img)
{
	Mat grayImage;
	//转换灰度图
	cvtColor(img, grayImage, CV_BGR2GRAY);

	//开始进行角点检测  
	vector<Point2f> dstPoint2f;
	goodFeaturesToTrack(grayImage, dstPoint2f, 200, 0.01, 10, Mat(), 3);

	//遍历每个点,进行绘制,便于显示  
	//Mat dstImage;
	//img.copyTo(dstImage);
	for (int i = 0; i < (int)dstPoint2f.size(); i++)
	{
		circle(img, dstPoint2f[i], 3, Scalar(0,0,255), 2, 8);
	}
	return 0;
}
//---------------------------【main( )函数】--------------------------------------------
//		描述:控制台应用程序的入口函数,我们的程序从这里开始
//-------------------------------------------------------------------------------------
int main()
{
	VideoCapture capture;
	capture.open("1.avi");
	if (!capture.isOpened())
	{
		cout << "capture device " << " failed to open!" << endl;
		return 1;
	}
	Mat frame;
	Mat gray;
	for (;;)
	{
		capture >> frame;
		if (frame.empty())
			break;
		
		int h = frame.rows;
		int w = frame.cols;
		Harris(frame);
		imshow("frame", frame);
		waitKey(3);  //延时30ms
	}
	return 0;
}

   (ii) Show results

Fast corner point detection experiments on video 1

Fast corner point detection experiments on video 2

Fast corner point detection experiments on video 3

Fast corner point detection experiments on video 4

Fast corner point detection experiments on video 5

Experiment summary

  The main content of this experiment is to understand the basic principle of corner point detection; master the code writing method to implement corner point detection. Create a new project; configure OpenCV in VS2015; open a video file using the VideoCapture class; read a frame from the video; convert the grayscale map and detect the corner points; traverse each point, draw, and display the corner points in the original map.

Built with Hugo
Theme Stack designed by Jimmy