资源简介
机器视觉小实验,数米粒
代码片段和文件信息
#include
#include
#include
using namespace cv;
using namespace std;
int pi_gray(Mat& srcMat &dst);
int pi_threshold(Mat& srcMat& dstint thre);
int pi_findconnectArea(Mat srcvector > &contours);
int pi_drawFill(Mat input vector > contours Mat &output);
int pi_Strengh(Mat &input Mat &output);
int pi_IRthreshold(Mat& srcMat& dst);//迭代阈值化
int pi_Mthreshold(Mat& srcMat& dst);//均值阈值化
int pi_OSTUthreshold(Mat& srcMat& dst);//大律法阈值
int pi_FindpointsCenter(vector pointsPoint ¢er);
int pi_FillContour(vector > contoursint indexvector &outpint size);
int main()
{
Mat im=imread(“F:rice1.gif“CV_LOAD_IMAGE_COLOR);
imshow(“pedro-src“im);
Mat pi;
pi_gray(impi);
imshow(“pedro-gray“pi);
Mat stren;
pi_Strengh(pistren);
imshow(“pedro-strengh“stren);
Mat pic_thre;
pi_IRthreshold(strenpic_thre);
imshow(“pedro-threIR“pic_thre);
Mat mean;
pi_Mthreshold(strenmean);
imshow(“pedro-threM“mean);
Mat ostu;
pi_OSTUthreshold(strenostu);
imshow(“pedro-ostu“ostu);
Mat element=getStructuringElement(MORPH_RECTSize(33));
erode(pic_threpic_threelementPoint(-1-1)1);
vector > contours;
findContours(pic_threcontoursCV_RETR_CCOMP CV_CHAIN_APPROX_NONE);
double cA=contourArea(contours[0]);
int index=0;
Mat draw_img(pic_thre.rowspic_thre.colsCV_8UC3Scalar(255255255));
vector > contours_fill;
for(size_t i=0; i {
vector po;
pi_FillContour(contoursipo1);
contours_fill.push_back(po);
}
for(size_t i=0; i {
drawContours(draw_imgcontours_filliScalar(000)1);
if(contourArea(contours_fill[i])>cA)
{
cA=contourArea(contours_fill[i]);
index=i;
}
}
drawContours(draw_imgcontours_fillindexScalar(02550)2);
for (int i=0; i < contours_fill.size(); i++)
{
vector points=contours_fill[i];
Point center;
pi_FindpointsCenter(pointscenter);
cv::circle(draw_imgcenter2Scalar(00255)2);
}
imshow(“pedro-drawing“draw_img);
vector Ar;
Ar=contours_fill[index];
Rect rect=boundingRect(Ar);
Point br=rect.br();
cout<<“the plot is:(“< cout<<“the size of contour is:“< cout<<“the Area is:“< waitKey(0);
return 0;
}
int pi_Strengh(Mat &input Mat &output)
{
if(input.empty())
{
cout<<“pic empty!“< return -1;
}
Mat pic_in=input.clone();
Mat erode_pic;
Mat element=getStructuringElement(MORPH_RECTSize(55));
erode(pic_ine
- 上一篇:c语言常见英语词汇
- 下一篇:基于单片机的光立方控制系统.doc
评论
共有 条评论