赞
踩
全局变量
Mat matrix;
Point2f center;
Mat frame;
float scale = 0.25;
bool flag = false;
主函数
int main() { frame = imread("celiang.jpg"); resize(frame, frame, Size(0,0), scale, scale, INTER_LINEAR); imshow("original", frame); int thres[] = { 50,255 }; Mat out; Point2f a4; getcontours(frame, thres,out,a4); //A4纸的长度为210,宽度为297 double a4_width = 210; double a4_height = 297; int scale = 3; Point2f mart; int th[] = { 50,255 }; getcontours_2(out, th,mart); if (flag) { int wid = round(mart.x / a4.x * a4_width); int hei = round(mart.y / a4.y * a4_height); string w = to_string(wid)+"cm"; putText(out, w, Point(center.x, center.y - 50), FONT_HERSHEY_SCRIPT_COMPLEX, 1, Scalar(0, 0, 255), 1); string h = to_string(hei)+"cm"; putText(out, h, Point(center.x - 70, center.y + hei ), FONT_HERSHEY_SCRIPT_COMPLEX, 1, Scalar(0, 0, 255), 1); } imshow("test", out); waitKey(0); return 0; }
参照物识别
void getcontours(Mat img, const int arr[],Mat& out,Point2f& ob,int minarea=1000*scale)
{
Mat imggray;
cvtColor(img,imggray, COLOR_BGR2GRAY);
Mat imggauss;
GaussianBlur(imggray
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。