場景
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供灌陽網(wǎng)站建設(shè)、灌陽做網(wǎng)站、灌陽網(wǎng)站設(shè)計、灌陽網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、灌陽企業(yè)網(wǎng)站模板建站服務(wù),10多年灌陽做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
嘗試使用直方圖對圖像進行增強,然后使用二值化函數(shù),分割出車輛的輪廓,顯然這個在應(yīng)對道路和車輛顏色相近的情況下,即使不是相近,依舊沒有達到任何的效果
代碼
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include
using namespace cv;
using namespace std;
Mat srcImg;
void on_trackbar(int pos)
{
Mat contourImg ;
srcImg.copyTo(contourImg);
Mat graysrcImg = Mat::zeros(srcImg.rows, srcImg.cols, CV_8UC3);
threshold(srcImg, graysrcImg, pos, 255, 3);
vector
vector
Mat dst = Mat::zeros(srcImg.rows, srcImg.cols, CV_8UC3);
findContours(graysrcImg, contours,hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
if( !contours.empty() && !hierarchy.empty() )
{
int idx = 0;
for( ; idx >= 0; idx = hierarchy[idx][0] )
{
if (contourArea(contours[idx]) < 500000) continue;
Scalar color( (rand()&255), (rand()&255), (rand()&255) );
drawContours( contourImg, contours, idx, Scalar(255, 0, 0), CV_FILLED, 8, hierarchy );
}
}
imshow( "FindContour", contourImg );
}
int main()
{
const char* srcImgFile = "D:/20170601092226.png";
srcImg = imread(srcImgFile);
if (srcImg.empty()) return -1;
Mat p_w_picpathRGB[3];
split(srcImg, p_w_picpathRGB);
for (int i = 0; i < 3; i++)
{
equalizeHist(p_w_picpathRGB[i], p_w_picpathRGB[i]);
}
merge(p_w_picpathRGB, 3, srcImg);
imshow("直方圖均衡化圖像增強效果", srcImg);
cvtColor( srcImg, srcImg, CV_RGB2GRAY );
namedWindow("srcImg", 1);
imshow("srcImg", srcImg);
int nThreshold = 0;
namedWindow("FindContour", 1);
cvCreateTrackbar("bar", "FindContour", &nThreshold, 254, on_trackbar);
on_trackbar(1);
waitKey(0);
return 0;
}