opencv教程(五)行驶车辆识别c++
Blob.h
#ifndef BLOB_H //先测试BLOB_H是否被宏定义过
#define BLOB_H //如果x没有被宏定义过,定义x,并编译程序段
#include<opencv2/core/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
class Blob{
public:
vector<Point> currentContour;
Rect currentBoundingRect;
double dblCurrentDiagonalSize;
double dblCurrentAspectRatio;
bool blnStillBeingTracked;
Blob(vector<Point> contour);
};
#endif
Blob::Blob(vector<Point> contour){
currentContour = contour;
//boundingRect()方法计算点集的边界矩阵
currentBoundingRect = cv::boundingRect(currentContour);
dblCurrentAspectRatio = (float)currentBoundingRect.width / (float)currentBoundingRect.height;
dblCurrentDiagonalSize = sqrt(pow(currentBoundingRect.width, 2) + pow(currentBoundingRect.height, 2));
blnStillBeingTracked = true;
}
main.cpp
#include "blob.h"