#include"opencv2\opencv.hpp"
#include"cv.h"
#include
#include
#include"iostream"
#include"fstream"
#include
#include"highgui.h"
#include"cxcore.h"
#include"time.h"
#include"math.h"
//==============
#include"opencv2/imgproc.hpp"
#include"opencv2/highgui.hpp"
#include"opencv2/ml.hpp"
#include"opencv2/objdetect.hpp"
#include"string"
#include"stdlib.h"
using namespace cv;
using namespace std;
//======add==
void Contours1(Mat &image)
{
threshold(image,image,65,255,THRESH_BINARY);
vector
findContours(image,contours,1,CHAIN_APPROX_SIMPLE);
Mat result = Mat::zeros(image.size(),CV_8UC1);
if (!contours.empty())
{
drawContours(result,contours,-1,Scalar(255),2);
imshow("处理图",result);
imwrite("F:\\1\\模板0920_14_erzhi.png", result);
}
}
void Contours2(Mat &image)
{
Mat img1 = Mat::zeros(image.size(),CV_8UC1);
//threshold(image,img1,45,255,THRESH_BINARY);
threshold(image,img1,60,255,THRESH_OTSU);
vector
vector
findContours(img1,contours,hierarchy,CV_RETR_CCOMP,CHAIN_APPROX_SIMPLE);
Mat dst = Mat::zeros(image.size(),CV_8UC1);
if (!contours.empty() && !hierarchy.empty())
{
for (int i = 0; i < contours.size(); i++)
{
for (int j = 0; j < contours[i].size(); j++)
{
Point p = Point(contours[i][j].x,contours[i][j].y);
dst.at
}
drawContours(img1,contours,i,Scalar(255),1,8,hierarchy);
}
}
imshow("处理图",dst);
imwrite("F:\\continue_picture\\1126_sharpen_thresold.jpg", dst);
}
void Contours3(Mat &image)
{
Mat img;
GaussianBlur(image,img,Size(3,3),0);
Canny(img,img,40,45);
vector
vector
findContours(img,contours,hierarchy,CV_RETR_CCOMP,CHAIN_APPROX_SIMPLE);
Mat dst = Mat::zeros(img.size(),CV_8UC1);
if (!contours.empty() && !hierarchy.empty())
{
for (int i = 0; i < contours.size(); i++)
{
for (int j = 0; j < contours[i].size(); j++)
{
Point p = Point(contours[i][j].x,contours[i][j].y);
dst.at
}
drawContours(img,contours,i,Scalar(255),1,8,hierarchy);
}
}
imshow("处理图", dst);
imwrite("F:\\1\\模板0920_16_canny_contours_2.png", dst);
}
void Contours4(Mat &img)
{
int threshval = 65;
//cvtColor(img,img,CV_RGB2GRAY);
Mat bw = (threshval < 128) ? (img < threshval) : (img > threshval);
vector
findContours(bw,contours,1,CHAIN_APPROX_SIMPLE);
Mat result = Mat::zeros(img.size(),CV_8UC1);
if (!contours.empty())
{
drawContours(result,contours,-1,Scalar(255),2);
imshow("处理图", result);
imwrite("F:\\1\\模板0920_16_erzhi_contours.png", result);
}
}
//=========add====
int main()
{
string fileName, grayFile;
string str1, str2;
int k = 74;
for (int i =k; i <=k+9; i++)
{
stringstream ss1, ss2;
Mat srcImage, grayImage;
ss1 << i;
ss2 << i;
ss1 >> str1;
ss2 >> str2;
// advance\\no
// back\\no
fileName = "F:\\image_save\\advance\\no1\\src_image\\" + str1 + ".jpg"; //advance back
cout << "fileName: " << fileName << endl;
//fileName = "F:\\chenjun\\33\\0.jpg";
srcImage = imread(fileName);
namedWindow("tu");
imshow("tu ", srcImage);
//srcImage 为原始图像
cv::Rect SrcImgROI = cv::Rect(212,98,395,283);
cv::Mat SrcROIImg = srcImage(SrcImgROI);
cv::imshow("ROI",SrcROIImg);
string fileNames= "F:\\image_save\\advance\\no1\\" + str1 + ".jpg"; //advance back
imwrite(fileNames,SrcROIImg);
////================
//imshow("gray ",dst);//grayImage dst
//cout << "str2:" << str2 << endl;
//string fi = "F:\\continue_image_15\\binary\\" + str1 + "threshold_edge.jpg";
//imwrite(fi,dst);//grayImage dst
// //string grayFile_2 = "F\\chenjun\\sa\\" + str2 + ".jpg";
// //cout << "grayFile2: " << grayFile_2 << endl;
// //imwrite("F:\\chenjun\\sa\\3.jpg", grayImage);
waitKey();
destroyAllWindows();
cout << "3333" << endl;
waitKey();
}
cin.get();
return 0;
}