多线程图像处理opencv

效率从130s降到39s

#include <iostream>  
#include<fstream>
#include <stdio.h>
#include <stdlib.h>

#define WIN32_LEAN_AND_MEAN
#include<windows.h>
#include <shellapi.h>
#include <atlstr.h>
#include<io.h>
#include <direct.h>

#include<WinSock2.h>  
#include <Ws2tcpip.h>
#include <string>
#include<vector>
//#include<ctime>
#include<assert.h>

#include <pthread.h>
#include <assert.h>
#include <opencv2/opencv.hpp>

#include"CParseIniFile.h"

#define THREAD_NUMS 4

using namespace std;
using namespace cv;
vector<vector<string>> p;

typedef struct _LocalPoint
{
	int x1;
	int y1;

} M_LocalPoint;

typedef struct _TextPoint
{
	int x1;
	int y1;
	int x2;
	int y2;
} M_TextPoint;

typedef struct _rectangle
{
	int x;
	int y;
	int width;
	int height;
} M_rectangle;

const int W = 10;
const int H = 10;
const int WIDTH = 20;
const int HEIGHT = 20;
const int V = 5;
const int spaceInt = 3;

M_LocalPoint mlp;

float k;

float threshold_value = 0;

float pixel_Value = 0;

struct paramThread

{

	int start;

	int end;

	int h;
	
	int w;


	uchar* fdata;

	uchar* cdata;

};


//将图像大小一致
const char* ImageSame(Mat f1, Mat c1, int X1, int Y1, int X2, int Y2, M_TextPoint m_temp)
{

	/*Mat finishImage = imread("D:/Image/0625/F_3_1.jpg");
	Mat clientImage = imread("D:/Image/0625/C_3_1.jpg");*/
	Mat finishImage = f1;
	Mat clientImage = c1;
	if (!clientImage.data && !finishImage.data)
	{
		return "failer";
	}
	else
	{
		int a = Y2;
		int b = Y1;
		int c = X2;
		int d = X1;
		Mat temp;
		Mat client_temp;
		// Mat img_result;
		double ScreenY = abs(a - b);
		double ScreenX = abs(c - d);
		//四种情况 根据坐标关系 调整图像大小一致
		if (a >= b && c >= d)
		{
			//cout << "111" << endl;
			//坐标变换
			/*Crop_X = m_temp.x1;
			Crop_Y = m_temp.y1;
			Crop_X1 = m_temp.x2;
			Crop_Y1 = m_temp.y2;*/
			mlp.x1 = 0;
			mlp.y1 = 0;
			// temp = finishImage(Rect(0, 0,clientImage.cols-ScreenX,clientImage.rows-ScreenY));
			//第一种情况
			if (clientImage.rows - ScreenY >= finishImage.rows && clientImage.cols - ScreenX <= finishImage.cols)
			{
				//cout << "1" << endl;
				temp = finishImage(Rect(0, 0, clientImage.cols - ScreenX, finishImage.rows));
				client_temp = clientImage(Rect(ScreenX, ScreenY, temp.cols, temp.rows));
				//imwrite("./jarod_demo/1.png", client_temp);
			}//第二种情况
			else if (clientImage.rows - ScreenY >= finishImage.rows && clientImage.cols - ScreenX >= finishImage.cols)
			{
				//cout << "2" << endl;
				temp = finishImage(Rect(0, 0, finishImage.cols, finishImage.rows));
				client_temp = clientImage(Rect(ScreenX, ScreenY, temp.cols, temp.rows));
				//imwrite("./jarod_demo/1.png", client_temp);
			}//第三种情况
			else if (clientImage.rows - ScreenY <= finishImage.rows && clientImage.cols - ScreenX >= finishImage.cols)
			{
				//cout << "3" << endl;
				temp = finishImage(Rect(0, 0, finishImage.cols, clientImage.rows - ScreenY));
				client_temp = clientImage(Rect(ScreenX, ScreenY, temp.cols, temp.rows));
				//imwrite("./jarod_demo/1.png", client_temp);

			}//第四种情况
			else if (clientImage.rows - ScreenY <= finishImage.rows && clientImage.cols - ScreenX <= finishImage.cols)
			{
				//cout << "4" << endl;
				temp = finishImage(Rect(0, 0, finishImage.cols - ScreenX, finishImage.rows - ScreenY));
				client_temp = clientImage(Rect(ScreenX, ScreenY, temp.cols, temp.rows));
				//imwrite("./jarod_demo/1.png", client_temp);
			}
		}
		if (a <= b && c >= d)
		{
			//cout << "222" << endl;
			//坐标变换
			/*Crop_X = m_temp.x1;
			Crop_Y = m_temp.y1 - ScreenY;
			Crop_X1 = m_temp.x2;
			Crop_Y1 = m_temp.y2 - ScreenY;*/
			mlp.x1 = 0;
			mlp.x1 = ScreenY;
			// temp=finishImage(Rect(0,ScreenY,clientImage.cols-ScreenX,clientImage.rows));
			//第一种情况
			if (finishImage.rows - ScreenY >= clientImage.rows && clientImage.cols - ScreenX <= finishImage.cols)
			{
				temp = finishImage(Rect(0, ScreenY, clientImage.cols - ScreenX, clientImage.rows));
				client_temp = clientImage(Rect(ScreenX, 0, temp.cols, temp.rows));
				//imwrite("./jarod_demo/1.png", client_temp);
			}//第二种情况
			else if (finishImage.rows - ScreenY >= clientImage.rows && clientImage.cols - ScreenX >= finishImage.cols)
			{
				temp = finishImage(Rect(0, ScreenY, finishImage.cols, clientImage.rows));
				client_temp = clientImage(Rect(ScreenX, 0, temp.cols, temp.rows));
				//imwrite("./jarod_demo/1.png", client_temp);
			}//第三种情况
			else if (finishImage.rows - ScreenY < clientImage.rows && clientImage.cols - ScreenX > finishImage.cols)
			{
				temp = finishImage(Rect(0, ScreenY, finishImage.cols, finishImage.rows - ScreenY));
				client_temp = clientImage(Rect(ScreenX, 0, temp.cols, temp.rows));
				//imwrite("./jarod_demo/1.png", client_temp);
			}//第四种情况
			else if (finishImage.rows - ScreenY < clientImage.rows && clientImage.cols - ScreenX < finishImage.cols)
			{
				temp = finishImage(Rect(0, ScreenY, clientImage.cols - ScreenX, finishImage.rows - ScreenY));
				client_temp = clientImage(Rect(ScreenX, 0, temp.cols, temp.rows));
				//imwrite("./jarod_demo/1.png", client_temp);
			}
		}
		if (a <= b && c <= d)
		{
			//cout << "333" << endl;
			//变换坐标
			/*Crop_X = m_temp.x1 - ScreenX;
			Crop_Y = m_temp.y1 - ScreenY;
			Crop_X1 = m_temp.x2 - ScreenX;
			Crop_Y1 = m_temp.y2 - ScreenY;*/
			mlp.x1 = ScreenX;
			mlp.y1 = ScreenY;
			//temp=finishImage(Rect(ScreenX,ScreenY,clientImage.cols,clientImage.rows));
			//第一种情况
			if (finishImage.rows - ScreenY >= clientImage.rows && finishImage.cols - ScreenX <= clientImage.cols)
			{
				temp = finishImage(Rect(ScreenX, ScreenY, finishImage.cols - ScreenX, clientImage.rows));
				client_temp = clientImage(Rect(0, 0, temp.cols, temp.rows));
				//	cv::rectangle(client_temp, Point(1639 - ScreenX, 259 - ScreenY), Point(1992 - ScreenX, 292 - ScreenY), Scalar(255, 0, 0), 1, 8, 0);
				//	cv::rectangle(temp, Point(1639 - ScreenX, 259 - ScreenY), Point(1992 - ScreenX, 292 - ScreenY), Scalar(255, 0, 0), 1, 8, 0);
				//	Mat c1 = client_temp(Rect(1639 - ScreenX, 259 - ScreenY, 1992 - 1639, 292 - 259));
				//	Mat f1 = temp(Rect(1639 - ScreenX, 259 - ScreenY, 1992 - 1639, 292 - 259));
				//	M_rectangle m1;
				//	MatchTemplate(client_temp,f1,m1, 1639 - ScreenX, 259 - ScreenY);

					//imwrite("111.jpg", f1);
					//imshow("c1",c1);
					//imshow("f1",f1);

					//Mat df;
					//bitwise_xor(c1,f1,df);
					//medianBlur(df,df,11);
					//absdiff(c1,f1,df);
					//imshow("dif",df);
					//waitKey(0);
					//cout << "success" << endl;
					//imwrite("./jarod_demo/1.png", client_temp);
			}//第二种情况
			else if (finishImage.rows - ScreenY >= clientImage.rows && finishImage.cols - ScreenX >= clientImage.cols)
			{
				temp = finishImage(Rect(ScreenX, ScreenY, clientImage.cols, clientImage.rows));
				client_temp = clientImage(Rect(0, 0, temp.cols, temp.rows));

				//imwrite("./jarod_demo/1.png", client_temp);
			}//第三种情况
			else if (finishImage.rows - ScreenY >= clientImage.rows && finishImage.cols - ScreenX <= clientImage.cols)
			{
				temp = finishImage(Rect(ScreenX, ScreenY, finishImage.cols - ScreenX, clientImage.rows));
				client_temp = clientImage(Rect(0, 0, temp.cols, temp.rows));

				//imwrite("./jarod_demo/1.png", client_temp);
			}//第四种情况
			else if (finishImage.rows - ScreenY <= clientImage.rows && finishImage.cols - ScreenX <= clientImage.cols)
			{
				temp = finishImage(Rect(ScreenX, ScreenY, finishImage.cols - ScreenX, finishImage.rows - ScreenY));
				client_temp = clientImage(Rect(0, 0, temp.cols, temp.rows));
				//	imwrite("./jarod_demo/1.png", client_temp);
			}
		}
		if (a >= b && c <= d)
		{
			//	cout << "444" << endl;
				//变换坐标
				/*Crop_X = m_temp.x1 - ScreenX;
				Crop_Y = m_temp.y1;
				Crop_X1 = m_temp.x2 - ScreenX;
				Crop_Y1 = m_temp.y2;*/
			mlp.x1 = ScreenX;
			mlp.y1 = 0;
			//	cout << "a >= b && c <= d" << endl;
			//temp=finishImage(Rect(0,ScreenY,clientImage.cols,clientImage.rows-ScreenY));
			//第一种情况
			if (clientImage.rows - ScreenY >= finishImage.rows && finishImage.cols - ScreenX <= clientImage.cols)
			{
				temp = finishImage(Rect(ScreenX, 0, finishImage.cols - ScreenX, finishImage.rows));
				client_temp = clientImage(Rect(0, ScreenY, temp.cols, temp.rows));
				//imwrite("./jarod_demo/1.png", client_temp);
			}//第二种情况
			else if (clientImage.rows - ScreenY >= finishImage.rows && finishImage.cols - ScreenX >= clientImage.cols)
			{
				temp = finishImage(Rect(ScreenX, 0, clientImage.cols, finishImage.rows));
				client_temp = clientImage(Rect(0, ScreenY, temp.cols, temp.rows));
				//imwrite("./jarod_demo/1.png", client_temp);
			}//第三种情况
			else if (clientImage.rows - ScreenY <= finishImage.rows && finishImage.cols - ScreenX <= clientImage.cols)
			{
				temp = finishImage(Rect(ScreenX, 0, finishImage.cols - ScreenX, clientImage.rows - ScreenY));
				client_temp = clientImage(Rect(0, ScreenY, temp.cols, temp.rows));
				//imwrite("./jarod_demo/1.png", client_temp);
			}//第四种情况
			else if (clientImage.rows - ScreenY <= finishImage.rows && finishImage.cols - ScreenX >= clientImage.cols)
			{
				temp = finishImage(Rect(ScreenX, 0, clientImage.cols, clientImage.rows - ScreenY));
				client_temp = clientImage(Rect(0, ScreenY, temp.cols, temp.rows));
				//imwrite("./jarod_demo/1.png", client_temp);
			}
		}
		imwrite("clien.jpg", client_temp);

		imwrite("finish.jpg", temp);

		return "success";
	}
}

double DisImage(Mat d, Mat b)
{
	Mat SrcImage = d;
	Mat SrcImage1 = b;
	cvtColor(SrcImage, SrcImage, COLOR_BGR2GRAY);
	adaptiveThreshold(SrcImage, SrcImage, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 11, 5);//自动阈值分割,邻域均值
																								 //threshold(SrcImage, SrcImage, 150, 255, CV_THRESH_BINARY_INV);
																								 //imshow("SrcImage", SrcImage);
	cvtColor(SrcImage1, SrcImage1, COLOR_BGR2GRAY);
	adaptiveThreshold(SrcImage1, SrcImage1, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 11, 5);//自动阈值分割,邻域均值
																								   //threshold(SrcImage1, SrcImage1, 150, 255, CV_THRESH_BINARY_INV);
																								   //imshow("SrcImage1", SrcImage1);
	Mat  xnot;
	bitwise_xor(SrcImage, SrcImage1, xnot);
	medianBlur(xnot, xnot, 5);
	//imshow("xnot", xnot);
	//waitKey(0);
	double similar = (1.0 - (double)countNonZero(xnot) / (SrcImage.rows * SrcImage.cols));
	return similar;
}

Mat MatchTemplate(Mat SrcImage, Mat ImageTemplate, M_rectangle& m_rectangle, int Start_X, int Start_Y)
{
	bool m_flage = false;
	Mat g_shrinkImage;
	Mat g_resultImage;
	Mat g_srcImage, srcImage;
	Mat m_temp;
	Mat borderResult;
	double start, stop, durationTime;
	double minValue, maxValue;
	Point minLocation, maxLocation, matchLocation;
	Mat g_templateImage1 = ImageTemplate;

	Point startPoint1(Start_X, Start_Y);
	g_srcImage = SrcImage;
	if (!g_srcImage.data && !g_templateImage1.data)
	{
		return ImageTemplate;
	}
	else
	{
		g_srcImage.copyTo(srcImage);
		int resultImage_rows = srcImage.rows;
		int resultImage_cols = srcImage.cols;
		g_resultImage.create(resultImage_rows, resultImage_cols, CV_32FC1);
		int shrink_g_srcImage_rows = g_templateImage1.rows + 2 * HEIGHT;
		int shrink_g_srcImage_cols = g_templateImage1.cols + 2 * WIDTH;
		int  tempY = startPoint1.y - HEIGHT;
		int  tempX = startPoint1.x - WIDTH;
		//第1种情况
		if (tempX <= 0 && tempY >= 0)
		{
			cout << 11 << endl;
			m_flage = true;
			int ROI_rows = g_templateImage1.rows + 2 * W;
			int ROI_cols = g_templateImage1.cols + 2 * H;
			copyMakeBorder(srcImage, borderResult, HEIGHT, HEIGHT, WIDTH, WIDTH, BORDER_CONSTANT, Scalar(255, 255, 255));
			Rect rect(startPoint1.x + (WIDTH - W), startPoint1.y + (HEIGHT - H), ROI_cols, ROI_rows);
			rect &= Rect(0, 0, borderResult.cols, borderResult.rows);
			g_shrinkImage = borderResult(rect);
			//imwrite("g_shrinkImage.tif", g_shrinkImage);
		}
		//第2种情况
		else if (tempX >= 0 && tempY < 0)
		{
			cout << 22 << endl;
			m_flage = true;
			int ROI_rows = g_templateImage1.rows + 2 * W;
			int ROI_cols = g_templateImage1.cols + 2 * H;
			copyMakeBorder(srcImage, borderResult, HEIGHT, HEIGHT, WIDTH, WIDTH, BORDER_CONSTANT, Scalar(255, 255, 255));
			Rect rect(startPoint1.x + WIDTH - W, startPoint1.y + HEIGHT - H, ROI_cols, ROI_rows);
			rect &= Rect(0, 0, borderResult.cols, borderResult.rows);
			g_shrinkImage = borderResult(rect);
			//imwrite("g_shrinkImage.tif", g_shrinkImage);
		}
		//第3种情况
		else if (tempX <= 0 && tempY <= 0)
		{
			cout << 33 << endl;
			m_flage = true;
			int ROI_rows = g_templateImage1.rows + 2 * W;
			int ROI_cols = g_templateImage1.cols + 2 * H;
			copyMakeBorder(srcImage, borderResult, HEIGHT, HEIGHT, WIDTH, WIDTH, BORDER_CONSTANT, Scalar(255, 255, 255));
			Rect rect(Start_X + WIDTH - W, Start_Y + HEIGHT - H, ROI_cols, ROI_rows);
			rect &= Rect(0, 0, borderResult.cols, borderResult.rows);
			g_shrinkImage = borderResult(rect);
			//imwrite("g_shrinkImage.tif", g_shrinkImage);
		}
		//第4种情况
		else if (tempX >= 0 && tempY >= 0)
		{
			m_flage = true;
			int ROI_rows = g_templateImage1.rows + 2 * W;
			int ROI_cols = g_templateImage1.cols + 2 * H;
			copyMakeBorder(srcImage, borderResult, HEIGHT, HEIGHT, 0, 0, BORDER_CONSTANT, Scalar(255, 255, 255));
			Rect rect(Start_X - W, Start_Y + HEIGHT - H, ROI_cols, ROI_rows);
			rect &= Rect(0, 0, borderResult.cols, borderResult.rows);
			g_shrinkImage = borderResult(rect);
			//imwrite("g_shrinkImage.tif", g_shrinkImage);
		}
		Mat gaussi;
		GaussianBlur(~g_shrinkImage, gaussi, Size(5, 5), 3, 3);
		Mat mask;
		cv::subtract(~g_shrinkImage, gaussi, mask);

		Mat imageEnhance;
		cv::add(~g_shrinkImage, 5 * mask, imageEnhance);
		Mat dst1;
		copyMakeBorder(~imageEnhance, dst1, V, V, V, V, BORDER_CONSTANT, Scalar(255, 255, 255));
		//imwrite(saveName, dst1);
		if (g_templateImage1.rows > g_shrinkImage.rows || g_templateImage1.cols > g_shrinkImage.cols)
		{
			return ImageTemplate;
		}
		else
		{
			matchTemplate(dst1, g_templateImage1, g_resultImage, TM_CCOEFF);//匹配结果存放在g_resultImage,大小和g_srcImage相同
		}
		normalize(g_resultImage, g_resultImage, 0, 1, NORM_MINMAX, -1, Mat());
		minMaxLoc(g_resultImage, &minValue, &maxValue, &minLocation, &maxLocation, Mat());
		matchLocation = maxLocation;
		if (m_flage)
		{
			m_rectangle.x = Start_X + matchLocation.x - W - V;
			m_rectangle.y = Start_Y + matchLocation.y - H - V;
			if (m_rectangle.x < 0)
			{
				m_rectangle.x = 0;
			}
			if (m_rectangle.y < 0)
			{
				m_rectangle.y = 0;
			}
			if (g_templateImage1.cols >= srcImage.cols - m_rectangle.x)
			{
				g_templateImage1.cols = srcImage.cols - m_rectangle.x;
			}
			else if (g_templateImage1.rows >= srcImage.rows - m_rectangle.y)
			{
				g_templateImage1.rows = srcImage.rows - m_rectangle.y;
			}
		}
		else
		{
			return ImageTemplate;
		}
		m_rectangle.width = g_templateImage1.cols;
		m_rectangle.height = g_templateImage1.rows;
		m_temp = g_srcImage(Rect(m_rectangle.x, m_rectangle.y, m_rectangle.width, m_rectangle.height));

		//imwrite(save, m_temp);
		return m_temp;
	}
}

void* threadProcess(void* args) {



	pthread_t myid = pthread_self();

	paramThread* para = (paramThread*)args;

	int start = para->start;

	int end = para->end;

	//cout << "end:::" << end << endl;

	int w = para->w;

	int h = para->h;

	cv::Mat FinshImage(h, w, CV_8UC3, (uchar*)para->fdata);

	cv::Mat clientImage(h, w, CV_8UC3, (uchar*)para->cdata);
    
	for (int i = start; i<end; i++)
	{
		Point a;
		Point b;
		a.x = round(stoi(p[i][1]) * k) - 2 - mlp.x1;
		a.y = round(stoi(p[i][2]) * k) - 4 - mlp.y1;
		b.x = round(stoi(p[i][3]) * k) - 2 - mlp.x1;
		b.y = round(stoi(p[i][4]) * k) - 2 - mlp.y1;

		Rect rect(a.x, a.y, b.x - a.x, b.y - a.y);
		rect &= Rect(0, 0, FinshImage.cols, FinshImage.rows);
		Mat f1 = FinshImage(rect);

		if (f1.empty())
		{
			cout << "filer" << endl;
			continue;
		}
		else
		{
			M_rectangle m1;
			Mat c_2 = MatchTemplate(clientImage, f1, m1, rect.x, rect.y);
			double m = DisImage(f1, c_2);
			if (m < pixel_Value)
			{
				Mat i1;
				Mat i2;
				cvtColor(f1, i1, COLOR_BGR2GRAY);
				cvtColor(c_2, i2, COLOR_BGR2GRAY);
				const double C1 = 6.5025, C2 = 58.5225;
				int d = CV_32F;
				Mat I1, I2;
				i1.convertTo(I1, d);//将CV_8U转成CV_32F
				i2.convertTo(I2, d);
				Mat I2_2 = I2.mul(I2);//y^2
				Mat I1_2 = I1.mul(I1);//x^2
				Mat I1_I2 = I1.mul(I2);//x*y
				Mat mu1, mu2;
				GaussianBlur(I1, mu1, Size(11, 11), 1.5); //u_x
				GaussianBlur(I2, mu2, Size(11, 11), 1.5); //u_y
				Mat mu1_2 = mu1.mul(mu1); //u_x^2
				Mat mu2_2 = mu2.mul(mu2); //u_y^2
				Mat mu1_mu2 = mu1.mul(mu2); //u_y*u_x
				Mat sigma1_2, sigma2_2, sigma12;
				GaussianBlur(I1_2, sigma1_2, Size(11, 11), 1.5);
				sigma1_2 -= mu1_2;
				GaussianBlur(I2_2, sigma2_2, Size(11, 11), 1.5);
				sigma2_2 -= mu2_2;
				GaussianBlur(I1_I2, sigma12, Size(11, 11), 1.5);
				sigma12 -= mu1_mu2;
				Mat t1, t2, t3;
				t1 = 2 * mu1_mu2 + C1;
				t2 = 2 * sigma12 + C2;
				t3 = t1.mul(t2);
				t1 = mu1_2 + mu2_2 + C1;
				t2 = sigma1_2 + sigma2_2 + C2;
				t1 = t1.mul(t2);
				Mat ssim_map;
				divide(t3, t1, ssim_map);
				Scalar mssim = mean(ssim_map);
				//cout << mssim[0] << endl;
				if (mssim[0] >= threshold_value)
				{
					continue;
				}
				else if (mssim[0] > threshold_value - 0.2 && mssim[0] < threshold_value)
				{
					Mat temp = ssim_map * 255;
					Mat I1;
					temp.convertTo(I1, CV_8U);
					threshold(I1, I1, 0, 255, THRESH_BINARY_INV | THRESH_OTSU);
					medianBlur(I1, I1, 11);
					vector<vector<Point>> contours;
					vector<Vec4i> hierarchy;
					findContours(I1, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point(0, 0));
					vector<Rect> boundRect(contours.size());
					for (int i = 0; i < contours.size(); i++)
					{
						boundRect[i] = boundingRect(Mat(contours[i]));
						if (contourArea(contours[i]) > 300 && contourArea(contours[i]) < 2000)
						{
							Point a1;
							Point b1;
							a1.x = a.x + boundRect[i].tl().x;
							a1.y = a.y + boundRect[i].tl().y;
							b1.x = a.x + boundRect[i].br().x;
							b1.y = a.y + boundRect[i].br().y;

							//标记不一样的地方
							int cPointR, cPointG, cPointB;
							for (int row = a1.y; row < b1.y; row++)
							{
								for (int col =a1.x; col < b1.x; col++)
								{
									cPointB = (int)FinshImage.at<Vec3b>(row, col)[0];
									cPointG = (int)FinshImage.at<Vec3b>(row, col)[1];
									cPointR = (int)FinshImage.at<Vec3b>(row, col)[2];
									if (cPointB < 200 && cPointR < 200 && cPointG < 200)
									{
										FinshImage.at<Vec3b>(row, col)[0] = 0;
										FinshImage.at<Vec3b>(row, col)[1] = 0;
										FinshImage.at<Vec3b>(row, col)[2] = 255;
									}
								}
							}
						//	rectangle(FinshImage, a1, b1, Scalar(0, 0, 255), 1, 8, 0);

							//rectangle(fImage, boundRect[i].tl(), boundRect[i].br(), (0, 0, 255), 1, 8, 0);
						}
					}
					continue;
				}
				else
				{
					//cout << mssim[0] << endl;
					Point al;
					Point br;
					al.x = a.x;
					al.y = a.y;
					br.x = b.x;
					br.y = b.y;
					//标记不同的地方
					int cPointR, cPointG, cPointB;
					for (int row = al.y; row < br.y; row++)
					{
						for (int col = al.x; col < br.x; col++)
						{
							cPointB = (int)FinshImage.at<Vec3b>(row, col)[0];
							cPointG = (int)FinshImage.at<Vec3b>(row, col)[1];
							cPointR = (int)FinshImage.at<Vec3b>(row, col)[2];
							if (cPointB < 200 && cPointR < 200 && cPointG < 200)
							{
								FinshImage.at<Vec3b>(row, col)[0] = 0;
								FinshImage.at<Vec3b>(row, col)[1] = 0;
								FinshImage.at<Vec3b>(row, col)[2] = 255;
							}
						}
					}
					//rectangle(FinshImage, al, br, Scalar(0, 0, 255), 1, 8, 0);
				}
			}
			else
			{
				continue;
			}
		}
	}
	pthread_exit(NULL);

	return NULL;

}
cv::Mat catImage(vector<vector<Mat>> v, int type) {
	Mat temp1,dest,mm;
	temp1 = v[0][0];
	for (int i = 1; i < THREAD_NUMS; i++)
	{
		bitwise_or(temp1,v[i][0], mm);
		temp1 = mm;
	}
	return temp1;
}
#if 1
int main()
{
	system("chcp 65001");
	clock_t start = clock();

	k = 0.711;

	Mat FImage = imread("F_3.jpg");

	Mat CImage = imread("C_3.jpg");

    resize(FImage, FImage, Size(), k, k);

	M_TextPoint m_Point1;
	m_Point1.x1 = 0;
	m_Point1.y1 = 0;
	m_Point1.x2 = 0;
	m_Point1.y2 = 0;
	ImageSame(FImage, CImage, 218, 235, 324, 301, m_Point1);

	Mat fimage = imread("finish.jpg");
	Mat cimage = imread("clien.jpg");

	vector<vector<Mat>> v;
	for (int i = 0; i < THREAD_NUMS; i++)
	{
		vector<Mat> m;
		m.push_back(fimage);
		m.push_back(cimage);
		v.push_back(m);
	}
	map<string, string>fname;
	CParseIniFile config;
	bool flage = config.ReadConfig("config.ini", fname, "COMMOND");
	if (flage)
	{
		pixel_Value = stod(fname["Pixel_threshold"]);
		threshold_value = stod(fname["SSIM_threshold"]);
	}
	else
	{
		pixel_Value = 0.95;
		threshold_value = 0.75;
		//	min_value =0.6;
	}


	string file = "zuobiao.txt";

	ifstream infile;

	infile.open(file.data());   //将文件流对象与文件连接起来 

	assert(infile.is_open());   //若失败,则输出错误消息,并终止程序运行 
	string s, tmp;
	
	
	//读取txt文本内容
	while (getline(infile, s))
	{
		//vector<int> m;
		vector<string> data;
		stringstream input(s);
		while (getline(input, tmp, ',')) data.push_back(tmp);
		p.push_back(data);
	//	cout << s << endl;
	}

	cout << "success" << endl;
  
//	vector<cv::Mat> v = splitImage(image2, THREAD_NUMS, type);

	int type = (p.size() / THREAD_NUMS);
	pthread_t pt[THREAD_NUMS];	//创建THREAD_NUMS个子线程
	paramThread args[THREAD_NUMS];
    //#pragma omp parallel 
	for (size_t i = 0; i < THREAD_NUMS; i++)
	{
		args[i].start = i* type;

		args[i].end= (i+1)*type;

		args[i].h = v[i][0].rows;

		args[i].w = v[i][0].cols;

		args[i].fdata = v[i][0].data;

		args[i].cdata = v[i][1].data;

		pthread_create(&pt[i], NULL, &threadProcess, (void*)(&args[i]));
	}
	//cout << p.size() << endl;
	for (size_t i = 0; i < THREAD_NUMS; i++)
	{
		pthread_join(pt[i], NULL);
	}
	cv::Mat dest = catImage(v, type);
	imwrite("dst.jpg", dest);
	clock_t end = clock();

	cout << "time : " << ((double)end - start) / CLOCKS_PER_SEC << "s\n";
	return 0;
}
#endif


  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值