resize函数缩小图片的尺寸 车辆检测
場景
????使用resize函數縮小圖片的尺寸,希望能夠減少車輛上不相干的顏色,例如車牌,例如車鏡,或者是出租車的車頂,希望屏蔽相關的細節,從而描繪出車輛的輪廓,最終沒有達到任何的效果,contour沒有實現連通性的閉合
代碼
#include <string>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main(int argc, char* argv[])
{
? int resize_height = 256;
? int resize_width = 256;
? cv::Mat src = cv::imread("D:/20170601092226.png", 0);
? Size srcSize = src.size();
? resize_height = srcSize.height/5;
? resize_width ?= srcSize.width/5;
? cv::Mat dst;
? imshow("src", src);
? cv::resize(src, dst, cv::Size(resize_width, resize_height), 0, 0, cv::INTER_LINEAR);
? imshow("dst", dst);
? Mat image;?
? threshold(dst, dst, 100, 255, CV_THRESH_BINARY);
? GaussianBlur(dst,image,Size(3,3),0); ?
? Canny(image,image,100,250); ?
? imshow("Canny Image",image); ?
? vector<vector<Point>> contours; ?
? vector<Vec4i> hierarchy; ?
? findContours(image,contours,hierarchy,RETR_EXTERNAL, CHAIN_APPROX_SIMPLE); ?
? Mat imageContours=Mat::zeros(image.size(),CV_8UC1); ?
? for(int i=0;i<contours.size();i++) ?
? { ?
? ? if (contourArea(contours[i]) < 50) ?continue;
? ? drawContours(imageContours,contours,i,Scalar(255),1,8,hierarchy);
? ? Rect r0= boundingRect(Mat(contours[i]));//boundingRect獲取這個外接矩形
? ? rectangle(dst,r0,Scalar(255,255,0),2);
? } ?
? imshow("Contours Image",imageContours); ?
? cv::waitKey(0);
? return 0;
}
? ? 本文轉自fengyuzaitu 51CTO博客,原文鏈接:http://blog.51cto.com/fengyuzaitu/1892603,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的resize函数缩小图片的尺寸 车辆检测的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: yum 安装服务出现报错收集
- 下一篇: 最近的状态很不好,需要调整