OpenCV画矩形框
作者:互联网
画一个矩形框和一个矩形填充块
效果如图所示:
#include<iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
//#ifdef _WIN32
using namespace cv;
#define OPENCV
int main()
{
double f[16];
int rect_position[16384] = {20,30,40,50};
int h, w;
#ifdef OPENCV
Mat mat_img = Mat::zeros(128, 128, CV_8UC3);//无符号三通道
//Mat mat_img = Mat::zeros(128, 128, CV_8U);//无符号单通道
//Mat mat_img = imread("1-resize.jpg");
for (int i = 80; i < 120; i++)
for (int j = 80; j < 120; j++)
{
mat_img.at<Vec3b>(i,j)[0] = 0;
mat_img.at<Vec3b>(i,j)[1] = 0;
mat_img.at<Vec3b>(i,j)[2] = 255;
//mat_img.at<uchar>(i, j) = 255;//对应CV_8U
}
//cv::cvtColor(mat_img, mat_img, CV_BGR2GRAY);
h = rect_position[3] - rect_position[1] + 1;
w = rect_position[2] - rect_position[0] + 1;
rectangle(mat_img, Rect(rect_position[0], rect_position[1], w, h), Scalar(0, 255, 0));
namedWindow("fig");
imshow("fig",mat_img);
waitKey(0);
destroyAllWindows();
#endif
return 0;
}
标签:mat,img,int,矩形框,OpenCV,position,include,rect 来源: https://blog.csdn.net/alansss/article/details/119190900