void configBG(Picture &BG, VideoCapture &camera1, int threshholdPixelChange, int threshholdPixelsChanged, int threshholdFramesChanged, int lroi)
{
	Picture test1;
	Picture test2;
	test1.initialize(camera1);
	test2.initialize(camera1);

	double framesUnchangeged = 0;
	while(true)
	{
		test1.refresh(camera1);
		waitKey(30);
		test2.refresh(camera1);
		double pixelChange = 0;
		double pixelsChanged = 0;
		

		for(int x = 0; x < test1.width; x++)
		{
			for(int y = 0; y < test1.height; y++)
			{
				pixelChange = 0;
				if(test1.pixelR[x][y] - test2.pixelR[x][y] > 0)
					pixelChange += test1.pixelR[x][y] - test2.pixelR[x][y];
				else
					pixelChange += test2.pixelR[x][y] - test1.pixelR[x][y];

				if(test1.pixelG[x][y] - test2.pixelG[x][y] > 0)
					pixelChange += test1.pixelG[x][y] - test2.pixelG[x][y];
				else
					pixelChange += test2.pixelG[x][y] - test1.pixelG[x][y];

				if(test1.pixelB[x][y] - test2.pixelB[x][y] > 0)
					pixelChange += test1.pixelB[x][y] - test2.pixelB[x][y];
				else
					pixelChange += test2.pixelB[x][y] - test1.pixelB[x][y];
				if(pixelChange > threshholdPixelChange)
					pixelsChanged++;
				//cout << pixelChange << endl;

			}
		}
		cout << pixelsChanged << endl;
		if(pixelsChanged < threshholdPixelsChanged)
			framesUnchangeged++;
		else
			framesUnchangeged = 0;

		if(framesUnchangeged >= threshholdFramesChanged)
		{
			//BG.refresh(camera1);
			//for(int x = 0; x < BG.width; x++)
			//{
			//	BG.pixelR[x][lroi] = 255;
			//	BG.pixelG[x][lroi] = 0;
			//	BG.pixelB[x][lroi] = 0;
			//}
			BG.refresh(camera1);
			int brightestYProduct = 0;
			for(int x = 0; x < BG.width; x++)
			{
				int brightestVal = 0;
				for(int y = 0; y < BG.height; y++)
				{
					if(BG.pixelR[x][y] > brightestVal)
					{
						brightestVal = BG.pixelR[x][y];
						brightestYatX[x] = y;
					}
				}
				BG.pixelR[x][brightestYatX[x]] = 255;
				BG.pixelG[x][brightestYatX[x]] = 0;
				BG.pixelB[x][brightestYatX[x]] = 0;
				brightestYProduct += brightestYatX[x];
			}
			startHeightOfROI = brightestYProduct/BG.width + BG.height*((float)procentOfTheScreenUsed/100)/4;

			if(startHeightOfROI > BG.height-1)
				startHeightOfROI = BG.height-1;
			/*cout << startHeightOfROI;
			cout << BG.height-1;
			cin >> startHeightOfROI;*/
			//BG.output("Window for control");
			BG.refresh(camera1);
			
			
			return;
		}
		//pixelChange /= test1.width;
		//pixelChange /= test1.height;
		//cout << pixelChange << endl;

		//		if(!((test1.pixelB[x][y] - test2.pixelB[x][y] > threshhold || test1.pixelB[x][y] - test2.pixelB[x][y] < -1*threshhold)
		//			|| (test1.pixelR[x][y] - test2.pixelR[x][y] > threshhold || test1.pixelR[x][y] - test2.pixelR[x][y] < -1*threshhold)
		//			|| (test1.pixelG[x][y] - test2.pixelG[x][y] > threshhold || test1.pixelG[x][y] - test2.pixelG[x][y] < -1*threshhold)))
		//		{
		//			picturesWithoutChanges = 1;
		//		}
		//	}
		//}
		//if(picturesWithoutChanges == 1)
		//{
		//	BG.refresh(camera1);
		//	return;

		//}

		////return 0;
	}
}