opencv图像操作——轮廓周围绘制矩形
时间:2023-02-01 09:30:00
基于RDP实现算法的目的是减少多边形轮廓点。
流程:
首先,将图像变成二值图像
找到轮廓,找到图像轮廓
通过相关API在轮廓点找到最小的矩形和圆,旋转矩形和椭圆
绘制他们
代码如下:
#include #include using namespace std; using namespace cv; Mat src, dst, gray_src; int threshold_value = 100; int threshold_max = 255; const char* output_title = "result image"; const char* trackbar_title = "Threshold Value"; void Contours_Callback(int, void*); RNG rng(12345); int main(int argc, char** argv) { src = imread("1.png"); //D:\\sougou\\image\\2.jpg 9.jpg if (!src.data) { printf("could not load image...\n"); return -1; } char input_image[] = "input image"; namedWindow(input_image, WINDOW_AUTOSIZE); namedWindow(output_title, WINDOW_AUTOSIZE); imshow(input_image, src); cvtColor(src, gray_src, CV_BGR2GRAY); //imshow("gray image