opencv(3) 通过ROI感兴趣区域来裁剪图像

xiaoxiao2021-02-28  10

ROI感兴趣区域 //1:图像的列的起点,宽2:行的起点,即高,(100(列),100(行),3:(300,300),即从(100,100)开始,向左和向下各300步 cv::Rect rect(100,100,300,300); #include<stdio.h> #include <opencv2/core.hpp> #include <opencv2/imgcodecs.hpp> #include <opencv2/highgui.hpp> using namespace cv; void PrintMs(const char *text = "") { static long long last = 0; long long cur = getTickCount(); if (last == 0) { last = cur; return; } long long ms = 0; ms = ((double)(cur - last) / getTickFrequency()) * 1000; if (*text != 0) { printf("%s = %dms\n ", text, ms); } last = getTickCount(); } int main(int argc, char *argv) { Mat src = imread("lena.jpg"); Rect rect(100, 100, 200, 200); Mat roi = src(rect); namedWindow("Lena"); namedWindow("ROI"); imshow("Lena", src); imshow("ROI", roi); waitKey(0); return 0; }

转载请注明原文地址: https://www.6miu.com/read-2400255.html

最新回复(0)