opencv学习日记——单目照相

代码

#include<opencv2/opencv.hpp>
#include <iostream>
#include<string>

using namespace std;
using namespace cv;





int main()
{
	int i = 0;

		Mat frame1;

//		VideoCapture capture(0);	
		//if (!capture.isOpened()) return 0;

		while(1)

		{

//			capture >> frame1;
//			imshow("pic", frame1);

			Mat frame1 = imread("0.jpg");
			Mat dst1;
			inRange(frame1, Scalar(30, 30, 130), Scalar(82, 79, 209), dst1);
			Mat element = getStructuringElement(MORPH_RECT, Size(3, 3));
			morphologyEx(dst1, dst1, MORPH_OPEN, element);//开运算
			morphologyEx(dst1, dst1, MORPH_CLOSE, element);//闭运算


			vector<vector<Point>>contours1;
			//	imshow("pic", dst1);
			//	waitKey(0);
			findContours(dst1, contours1, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point(0, 0));
			vector<Rect> boundRect1(contours1.size());  //包围点集的最小矩形vector
//			if (contours1.size() == 0) waitKey(0);
			for (int i = 0; i < contours1.size(); i++)
			{
				boundRect1[i] = boundingRect(Mat(contours1[i]));
				cout << boundRect1[i].x << "	" << boundRect1[i].y << endl << boundRect1[i].x << "	" << boundRect1[i].y + boundRect1[i].height << endl;
				cout << boundRect1[i].x + boundRect1[i].width << "	" << boundRect1[i].y << endl;
				boundRect1[i] = boundingRect(Mat(contours1[i])); //计算并返回包围轮廓点集的最小矩形
				rectangle(frame1 , boundRect1[i].tl(), boundRect1[i].br(), Scalar(190, 50, 0), 2, 8, 0);
			}
			drawContours(frame1, contours1, -1, Scalar(255, 0, 0), 10);

			imshow("srcpic", frame1);
			waitKey(0);

//			char a = waitKey(30);
			
/*			if (a == 's')
			{
				string Img_Name =  to_string(i++) + ".jpg";
				imwrite(Img_Name, frame1);
			}
			
			if (a == 'q') break;
*/			
		}
		return 0;
}

分析

主要是设一个Videocapture

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值