计算图像的直⽅图,求峰值点程序步骤:
1.输⼊图像
2.灰度化
3.计算直⽅图
4.求峰值点
#include "../LaneDetecte_SRC/detector_lane.hpp"
#include "../common_src/unity.hpp"
#include "../common_src/common_func.hpp"
#include <chrono>
#include <thread>
#include <opencv2/opencv.hpp>
int main()
{
for(int z = 1;z<100;z++)盖字组词
{
std::string leftName = cv::format(ROOT_DIR"/data%d/left%d.png",1,z);
cv::Mat left,leftG;
left = cv::imread(leftName);
cv::Rect rect(ws - 200 , ls, 200);
cv::Mat half_left(left, rect);
cv::cvtColor(half_left,leftG,cv::COLOR_BGR2GRAY);
cv::namedWindow( "leftG", 1);
cv::imshow( "leftG", leftG);
int Channels[] = { 0 };
cv::Mat hist;
int nHistSize[] = { 256 };
float range[] = { 0, 255 };
捉刀const float* fHistRanges[] = { range };
cv::calcHist(&leftG, 1, Channels, cv::Mat(), hist, 1, nHistSize, fHistRanges, true, fal);
// 创建直⽅图画布
int nHistWidth = 800;
政治片int nHistHeight = 600;
int nBinWidth = cvRound((double)nHistWidth / nHistSize[0]);
cv::Mat matHistImage(nHistHeight, nHistWidth, CV_8UC3, cv::Scalar(255, 255, 255));
// 直⽅图归⼀化
cv::normalize(hist, hist, 0.0, ws, cv::NORM_MINMAX, -1, cv::Mat());
std::cout<<nHistSize[0]<<std::endl;
//画值⽅图
for (int i = 1; i < nHistSize[0]; i++)
{
line(matHistImage,
cv::Point(nBinWidth * (i - 1), nHistHeight - cvRound(hist.at<float>(i - 1))),
cv::Point(nBinWidth * (i), nHistHeight - cvRound(hist.at<float>(i))),
cv::Scalar(255, 0, 0),
2,
8,
0);
//std::cout<<i<<" : "<<hist.at<float>(i)<<std::endl;
}
std::vector<int> indexes;
cv::Mat test = leftG.clone();
int w = 20;
描写风景bool flag;
//求峰值点
for(int i = 0;i<=255;i++)
{
flag = true;
for(int j = i-w;j<i+w;j++)
{
if(j>0 && i<=255 )
{
if(hist.at<float>(i)<hist.at<float>(j) || hist.at<float>(i)==0)
{
flag = fal;
怎么注册香港公司break;
}
}
}
if(flag)
{
if(indexes.size()>0)
反托拉斯{
if(abs(indexes[indexes.size()-1]-i)>5)
{
indexes.push_back(i);
}
}
el if(indexes.size() == 0)
{
indexes.push_back(i);
}
}
}
for(int i = 0;i<indexes.size();i++)
std::cout<<"**********: "<<indexes[i]<<std::endl;
int vw = 20;
//阈值分割
if(indexes.size()>0)
三只蝴蝶教案
{
for(int y = 0;y&ws;y++)
{
for(int x = 0;x&ls;x++)
{
if(test.at<uchar>(y,x)>indexes[0]-vw && test.at<uchar>(y,x)<indexes[0]+vw) {
test.at<uchar>(y,x) = 0;
}
}
imshow("test", test);
}
}
// 显⽰直⽅图
imshow("histogram", matHistImage);
奢侈的反义词cv::waitKey(0); }
return 0;
}