随机生成负样本

//生成负样本
int main()
{
	//----------------in file------------------//
	char *file("D:\\s3\\%d.bmp");
	char inpath[200] = { 0 };                 

	srand((unsigned)time(NULL));

	for (int i = 4; i <=4; i++)
	{
		
		int m = rand() % 10 + 2000;   //在循环第一张找个随机点
		int n = rand() % 10 + 10;

		sprintf(inpath, file, i);     //加载原图路径
		Mat src = imread(inpath, 0);  //原图  
		int cout = 0;
		for (; cout != 1200000 || m>2000 && m<40000;)
		{
			cout++;
			m = m + 10;
			/*if ( m>21016 && m<23552 || m>31256 && m<33792 )
			{
				continue;
			}*/
			if (m > src.cols - 40 && n < 620 )
			{
				m = rand() % 10 + 2000;   //在循环第一张找个随机点
				 n = n+ 10;
				 //continue;
			}
			int width = rand() % 25 + 15;
			int height = rand() % 25 + 15;
			Rect ROI = Rect(m, n, width, height);
			//	std::cout << ROI.x << "," << ROI.y << std::endl;
			//保存负样本
			static int iPoint = 0;
			Mat T;
			src(ROI).copyTo(T);
			char output[100] = { 0 };
			sprintf_s(output, "负样本5\\%d.bmp", ++iPoint);
			imwrite(output, T);
			std::cout << i << "===" << iPoint << std::endl;
		}
		cv::imshow("src0", src);
		cv::waitKey(1000);
	}
	std::cout << endl;

	return 0;
}

你可能感兴趣的:(Opencv)