// [ref] ${IVT_HOME}/examples/ParticleFilterDemo/src/main.cpp
void particle_filter_example()
{
	const int NUMBER_OF_PARTICLES = 200;
	const int width = 400;
	const int height = 300;

	CByteImage image(width, height, CByteImage::eGrayScale);
	CByteImage color(width, height, CByteImage::eRGB24);

	MyRegion region;
	int k = 40;

#ifdef TRACK_3D
	double result_configuration[DIMENSION_3D];
	CParticleFilter3D particle_filter(NUMBER_OF_PARTICLES, width, height, k);
#else
	double result_configuration[DIMENSION_2D];
	CParticleFilter2D particle_filter(NUMBER_OF_PARTICLES, width, height, k);
#endif

	// gui
	CApplicationHandlerInterface *pApplicationHandler = CreateApplicationHandler();
	pApplicationHandler->Reset();

	CMainWindowInterface *pMainWindow = CreateMainWindow(0, 0, width, height, "Particle Filter Demo");
	WIDGET_HANDLE pImageWidget = pMainWindow->AddImage(0, 0, width, height);

	pMainWindow->Show();

	for (int i = 0; i < 600; ++i)
	{
		unsigned int t = get_timer_value(true);

		local::SimulateMovement(&image);

		particle_filter.SetImage(&image);
		particle_filter.ParticleFilter(result_configuration);

#ifdef TRACK_3D
		k = int(result_configuration[2] + 0.5);
#endif

		region.min_x = int(result_configuration[0] - k + 0.5);
		region.min_y = int(result_configuration[1] - k + 0.5);
		region.max_x = int(result_configuration[0] + k + 0.5);
		region.max_y = int(result_configuration[1] + k + 0.5);

		ImageProcessor::ConvertImage(&image, &color);
		PrimitivesDrawer::DrawRegion(&color, region, 255, 0, 0, 2);

		pMainWindow->SetImage(pImageWidget, &color);

		if (pApplicationHandler->ProcessEventsAndGetExit())
			break;

		while (get_timer_value() - t < 1000000.0 / 30);
	}

	delete pMainWindow;
	delete pApplicationHandler;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: junaidnaseer/ivt
	int Run()
	{
		const int width = 640;
		const int height = 480;
		const int nPixels = width * height;
		
		m_pImage = new CByteImage(width, height, CByteImage::eRGB24);
		ImageProcessor::Zero(m_pImage);
		
		// create an application handler
		CApplicationHandlerInterface *pApplicationHandler = CreateApplicationHandler();
		pApplicationHandler->Reset();
		
		// create a window with many widgets
		m_pMainWindow = CreateMainWindow(0, 0, width + 440, height, "HSV to RGB Converter");
		m_pMainWindow->SetEventCallback(this);
		
		m_pImageWidget = m_pMainWindow->AddImage(0, 0, width, height);
		
		m_pLCD_H = m_pMainWindow->AddTextEdit(width + 50 , 230, 100, 50, "0");
		m_pLCD_S = m_pMainWindow->AddTextEdit(width + 160, 230, 100, 50, "0");
		m_pLCD_V = m_pMainWindow->AddTextEdit(width + 270, 230, 100, 50, "0");
		
		m_pLCD_R = m_pMainWindow->AddTextEdit(width + 50 , 290, 100, 50, "0");
		m_pLCD_G = m_pMainWindow->AddTextEdit(width + 160, 290, 100, 50, "0");
		m_pLCD_B = m_pMainWindow->AddTextEdit(width + 270, 290, 100, 50, "0");
		
		m_pSliderH = m_pMainWindow->AddSlider(width + 40, 20, 380, 20, 0, 359, 36, 0);
		m_pSliderS = m_pMainWindow->AddSlider(width + 40, 50, 380, 20, 0, 255, 25, 0);
		m_pSliderV = m_pMainWindow->AddSlider(width + 40, 80, 380, 20, 0, 255, 25, 0);
		
		m_pSliderR = m_pMainWindow->AddSlider(width + 40, 120, 380, 20, 0, 255, 25, 0);
		m_pSliderG = m_pMainWindow->AddSlider(width + 40, 150, 380, 20, 0, 255, 25, 0);
		m_pSliderB = m_pMainWindow->AddSlider(width + 40, 180, 380, 20, 0, 255, 25, 0);
		
		WIDGET_HANDLE pLabelH = m_pMainWindow->AddLabel(width + 20, 20, 10, 20, "H");
		WIDGET_HANDLE pLabelS = m_pMainWindow->AddLabel(width + 20, 50, 10, 20, "S");
		WIDGET_HANDLE pLabelV = m_pMainWindow->AddLabel(width + 20, 80, 10, 20, "V");
		
		WIDGET_HANDLE pLabelR = m_pMainWindow->AddLabel(width + 20, 120, 10, 20, "R");
		WIDGET_HANDLE pLabelG = m_pMainWindow->AddLabel(width + 20, 150, 10, 20, "G");
		WIDGET_HANDLE pLabelB = m_pMainWindow->AddLabel(width + 20, 180, 10, 20, "B");
		
		WIDGET_HANDLE pLabelHSV = m_pMainWindow->AddLabel(width + 20, 245, 30, 20, "HSV");
		WIDGET_HANDLE pLabelRGB = m_pMainWindow->AddLabel(width + 20, 305, 30, 20, "RGB");
		
		m_pMainWindow->Show();
		
		m_pMainWindow->SetImage(m_pImageWidget, m_pImage);
	
		// main loop
		for (int i = 0;; i++)
		{
			if (pApplicationHandler->ProcessEventsAndGetExit())
				break;
		}
		
		delete m_pMainWindow;
		delete pApplicationHandler;
		
		delete m_pImage;
		
		return 0;
	}
コード例 #3
0
ファイル: main.cpp プロジェクト: junaidnaseer/ivt
	// init application and run
	int Run()
	{
		CBitmapCapture capture(DEMO_IMAGE);

		// open camera
		if (!capture.OpenCamera())
		{
			printf("error: could not open camera\n");
			return 1;
		}
		
		const int width = capture.GetWidth();
		const int height = capture.GetHeight();

		// create temp image for the image processing
		CByteImage image(width, height, capture.GetType());
		CByteImage grayImage(width, height, CByteImage::eGrayScale);
		CByteImage tempImage(width, height, CByteImage::eGrayScale);
		CByteImage visualizationImage(width, height, CByteImage::eRGB24);
		CByteImage *pImage = &image;


		// create an application handler
		CApplicationHandlerInterface *pApplicationHandler = CreateApplicationHandler();
		pApplicationHandler->Reset();
		
		// create a main window
		m_pMainWindow = CreateMainWindow(0, 0, width, height + 190, "Hough Line Detection Demo");

		// events are sent to this class, hence this class needs to have the CMainWindowEventInterface
		m_pMainWindow->SetEventCallback(this);

		// create an image widget to display a window
		WIDGET_HANDLE pImageWidget = m_pMainWindow->AddImage(0, 190, width, height);

		// add a label and a slider for the low threshold
		WIDGET_HANDLE pLabelCannyLow = m_pMainWindow->AddLabel(15, 15, 200, 30, "Canny low threshold: 0");
		m_pSliderCannyLow = m_pMainWindow->AddSlider(15, 30, 200, 40, 0, 1020, 102, m_nCannyLowThreshold);

		// add a label and a slider for the high threshold
		WIDGET_HANDLE pLabelCannyHigh = m_pMainWindow->AddLabel(15, 70, 200, 30, "Canny high threshold: 0");
		m_pSliderCannyHigh = m_pMainWindow->AddSlider(15, 85, 200, 40, 0, 1020, 102, m_nCannyHighThreshold);
		
		// add a label and a slider for the number of lines to extract
		WIDGET_HANDLE pLabelLines = m_pMainWindow->AddLabel(260, 15, 200, 30, "Circles to extract: 0 lines");
		m_pSliderLinesToExtract = m_pMainWindow->AddSlider(260, 30, 200, 40, 0, 30, 5, m_nCirclesToExtract);
		
		// add labels/sliders for specifying the radius interval of interest
		WIDGET_HANDLE pLabelMinRadius = m_pMainWindow->AddLabel(260, 70, 200, 30, "Min radius: 0");
		m_pSliderMinRadius = m_pMainWindow->AddSlider(260, 85, 200, 40, 1, 200, 5, m_nMinRadius);
		WIDGET_HANDLE pLabelMaxRadius = m_pMainWindow->AddLabel(260, 125, 200, 30, "Max radius: 0");
		m_pSliderMaxRadius = m_pMainWindow->AddSlider(260, 140, 200, 40, 1, 200, 5, m_nMaxRadius);
		
		// add a button to toggle between the original image and the processed one
		m_pButton = m_pMainWindow->AddButton(510, 80, 110, 35, "Show Edges");

		// add a labels to display processing stats
		WIDGET_HANDLE pLabelMS = m_pMainWindow->AddLabel(560, 15, 70, 20, "0 ms");
		WIDGET_HANDLE pLabelFPS = m_pMainWindow->AddLabel(560, 45, 70, 20, "0 fps");

		// make the window visible
		m_pMainWindow->Show();
		

		char buffer[1024];
		
		CVec3dArray resultListCircles(50);
		CDynamicArrayTemplate<int> resultHits(50);
		CVec2dArray edgePoints(10000), edgeDirections(10000);
		
		// main loop
		while (!pApplicationHandler->ProcessEventsAndGetExit())
		{
			if (!capture.CaptureImage(&pImage))
				break;
			
			// this is for visualization purposes only
			ImageProcessor::ConvertImage(pImage, &visualizationImage);
			
			get_timer_value(true);
			
			// convert input image to grayscale image
			ImageProcessor::ConvertImage(&image, &tempImage, true);
			
			// smooth image
			ImageProcessor::GaussianSmooth3x3(&tempImage, &grayImage);

			// detect edges with Canny edge detector
			ImageProcessor::Canny(&grayImage, edgePoints, edgeDirections, m_nCannyLowThreshold, m_nCannyHighThreshold);
			
			// detect lines with Hough transform
			ImageProcessor::HoughTransformCircles(edgePoints, edgeDirections, width, height, m_nMinRadius, m_nMaxRadius, m_nCirclesToExtract, 1, resultListCircles, resultHits, &visualizationImage);

			const unsigned int t = get_timer_value();
			
			// display the speed stats
			sprintf(buffer, "%2.2f ms", t / 1000.0f);
			m_pMainWindow->SetText(pLabelMS, buffer);
			sprintf(buffer, "%3.2f fps", 1000000.0f / t);
			m_pMainWindow->SetText(pLabelFPS, buffer);
			sprintf(buffer, "Canny low threshold: %i", m_nCannyLowThreshold);
			m_pMainWindow->SetText(pLabelCannyLow, buffer);
			sprintf(buffer, "Canny high threshold: %i", m_nCannyHighThreshold);
			m_pMainWindow->SetText(pLabelCannyHigh, buffer);
			sprintf(buffer, "Min radius: %i", m_nMinRadius);
			m_pMainWindow->SetText(pLabelMinRadius, buffer);
			sprintf(buffer, "Max radius: %i", m_nMaxRadius);
			m_pMainWindow->SetText(pLabelMaxRadius, buffer);
			sprintf(buffer, "Circles to extract: %i", m_nCirclesToExtract);
			m_pMainWindow->SetText(pLabelLines, buffer);

			// display either the original image or the processed image
			if (m_bShowEdges)
			{
				ImageProcessor::Canny(&grayImage, &grayImage, m_nCannyLowThreshold, m_nCannyHighThreshold);
				m_pMainWindow->SetImage(pImageWidget, &grayImage);
			}
			else
				m_pMainWindow->SetImage(pImageWidget, &visualizationImage);
		}
		
		delete m_pMainWindow;
		delete pApplicationHandler;
		
		return 0;
	}