#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
int bSums(Mat src)
{
int counter = 0;
//迭代器访问像素点
Mat_::iterator it = src.begin();
Mat_::iterator itend = src.end();
for (; it!=itend; ++it)
{
if((*it)>0) counter+=1;//二值化后,像素点是0或者255
}
return counter;
}
vector Flip(Mat &img)
{
int rows=img.rows;
int cols=img.cols;
vector vec;
vector abs;
vector vec_i;
int k=0;
for(int i=10; i5)
{
abs.push_back(i);
}
if(i+15>cols)
{
break;
}
k=k+1;
}
return abs;
}
void roi(Mat src,int x1,int y1,int x2,int y2,int d)
{
// Mat temp(src(Rect(x1,y1-d,x2,y2+d)));;
// rectangle(src, (x1,y1),(x2,y2), Scalar(0, 255, 0), 2);
Rect roi = Rect(Point(x1, y1), Point(x2, y2));
Mat roiImg = src(roi);
imshow(“new”,roiImg);
waitKey(0);
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// static int num=0;
// static int right;
// static int left;
// vector sequence;
// vector eq;
// vector point1;
// vector point2;
Mat src1 = imread( "/home/zyx/Downloads/626900593.jpg" );
// Mat result;
// threshold(src1, result, 80, 255.0, THRESH_TOZERO);
// sequence=Flip(src1);
// sequence.erase(sequence.begin());
// //访问该vector的值的时候,也是直接访问即可
// for(vector::iterator it=sequence.begin();it!=sequence.end();it++)
// {
// int a=*(it-1);
// int b=*it;
// if(b-a>10)
// {
// eq.push_back(b);
// }
// }
// for(int i=0;i
// int static right,left;
// //cout<
// right=eq[i];
// }else{
// left=eq[i];
// cout<
// }
// }
// imshow(“二值化图像”, result);
// waitKey(0);
roi(src1,0,0,800,430,10);
cout<
return a.exec();
}
#include
#include
#include
#include
#include
IplImage* src=0;
void on_mouse( int event, int x, int y, int flags, void* ustc)
{
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5, 0, 1, CV_AA);//字体结构初始化
if((event == CV_EVENT_LBUTTONDOWN)&&(flags))//鼠标左键按下事件发生
{
CvPoint pt = cvPoint(x,y);//获取当前点的横纵坐标值
char temp[16];
sprintf(temp,"(%d,%d)",pt.x,pt.y);//打印当前坐标值
printf("( %d, %d) ",pt.x,pt.y);
cvPutText(src,temp, pt, &font, cvScalar(255, 255, 255, 0)); //在图像中打印当前坐标值
cvCircle( src, pt, 2,cvScalar(255,0,0,0) ,CV_FILLED, CV_AA, 0 );//在在图像当前坐标点下画圆
cvShowImage( "src", src );
}
}
int main()
{
src = cvLoadImage("/home/zyx/Downloads/626900593.jpg",1); //读入图像
cvNamedWindow("src",1);//新建窗口
cvSetMouseCallback( "src", on_mouse, 0 ); //注册鼠标相应回调函数
cvShowImage("src",src);
cvWaitKey(0);
cvDestroyAllWindows();//销毁所有窗口
cvReleaseImage(&src);//释放图像数据
return 0;
}