#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/cv.h>
using namespace cv;
using namespace std;
int main(int argc, char **argv)
{
Mat frame,GrayFrame,resFrame,RoiImg;
VideoCapture cap0(0);
cap0 >> frame;
//随机播种
cv::RNG rng(time(0));
while (cap0.isOpened())
{
cap0 >> frame;
//调整图像尺寸
resize(srcImg, resFrame, cv::Size(100, 100));
//彩色图转灰度图
cvtColor(frame, GrayFrame, CV_BGR2GRAY);
//获取图片某一区域的图像
cv::Rect rt;
rt.x = 0;
rt.y = 0;
rt.width = GrayFrame.cols;
rt.height = GrayFrame.rows;
RoiImg = Gray(rt);
Point pt1, pt2;
pt1.x = 0;
pt1.y = 0;
pt2.x = 100;
pt2.y = 100;
//随机显示颜色
line(frame, pt1, pt2, cv::Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)), 2, CV_AA);
imshow("frame", frame);
waitKey(1);
}
system("pause");
return 0;
}
opencv读摄像头_随机显示线段颜色
最新推荐文章于 2024-07-12 14:43:51 发布