Example #1
0
HRESULT CVCAConfigure::DoLoad( DWORD dwEngId )
{
	// Now assign all libvca structs to internal jobbies
	VCA5_APP_ENGINE_CONFIG *pCfg = &(m_EngineConfig[dwEngId]);

	LoadZones( dwEngId, &(pCfg->Zones) );
	LoadRules( dwEngId, &(pCfg->Rules) );
	LoadCounters( dwEngId, &(pCfg->Counters) );
	LoadCalibration( dwEngId, &(pCfg->CalibInfo) );
	LoadObjects( dwEngId, &(pCfg->ClsObjects) );
	LoadTamper( dwEngId, &(pCfg->TamperInfo) );
	LoadSceneChange( dwEngId, &(pCfg->SceneChangeInfo) );
	LoadAdvanced( dwEngId, &(pCfg->AdvInfo) );
	LoadFunction( dwEngId, &(pCfg->ulFunction) );

//	UnSquishIds( pCfg );


	return S_OK;
}
Example #2
0
int _tmain(int argc, _TCHAR* argv[])
{
	/*

	Начальная инициализация параметров. этот 
	код требуется запустить один раз. 

	TVAInitParams params;
	memcpy(&params.Camera, &g_camera, sizeof(TVACamera));
	params.NumZones = 0;
	params.EventSens = 0.5;
	params.EventTimeSens = 1000;
	SaveInitParams("params.xml", &params);
	*/
	// инициализация зон наблюдения. 
	for (int i = 0; i < C_MAX_OBJECTS; i++)
	{
		g_contours[i].IsRect = false;
		g_contours[i].NumPoints = C_MAX_POINTS;
		g_contours[i].Points = (TVAPoint*)malloc(C_MAX_POINTS*sizeof(TVAPoint));
	}
	
	cvInitFont(&g_font, CV_FONT_HERSHEY_PLAIN,1, 1);

	CvCapture* capture = NULL;
	if (argc < 2)
		capture = cvCaptureFromCAM(0);
	else
		capture = cvCaptureFromFile(argv[1]);
	

	if (capture == NULL)
	{
		printf("%s\n", "Cannot open camera.");
		return -1;
	}

    double fps = cvGetCaptureProperty ( // Получаем частоту кадров
        capture,
        CV_CAP_PROP_FPS
    );

    CvSize size = cvSize( // Получаем размер
       (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH),
       (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT)
    );
	g_mask = cvCreateImage(size, IPL_DEPTH_8U, 1);
	CvVideoWriter* writer = NULL;
	cvNamedWindow(_MODULE_);
	cvSetMouseCallback(_MODULE_, on_mouse);

	/*
		Цикл получения и обработки изображения. 
	*/
	for (;;) 
	{
		IplImage* frame = NULL;
		frame = cvQueryFrame(capture);
		if (!frame)
			break;
		/*
		 отрисовка прямоугольников
		*/
		for (int i = 0; i < g_rects_count; i++)
		{
			CvPoint p1 = cvPoint(g_rects[i].x, g_rects[i].y);
			CvPoint p2 = cvPoint(p1.x + g_rects[i].width, p1.y + g_rects[i].height);
			
			cvRectangle(frame, p1, p2, CV_RGB(255,0,0));
		}

		/*
			Отрисовка зон наблюдения. 
		*/
		for (int i = 0; i < g_contours_count; i++)
		{
			if (g_contours[i].NumPoints > 0)
			{
				for (int j = 1; j < g_contours[i].NumPoints; j++)
				{
					CvPoint p1 = cvPoint((int)g_contours[i].Points[j-1].X, (int)g_contours[i].Points[j-1].Y);
					CvPoint p2 = cvPoint((int)g_contours[i].Points[j].X, (int)g_contours[i].Points[j].Y);
					cvLine(frame, p1,p2, CV_RGB(255,0,0));
				}
				CvPoint p1 = cvPoint((int)g_contours[i].Points[g_contours[i].NumPoints-1].X, (int)g_contours[i].Points[g_contours[i].NumPoints-1].Y);
				CvPoint p2 = cvPoint((int)g_contours[i].Points[0].X, (int)g_contours[i].Points[0].Y);
				cvLine(frame, p1,p2, CV_RGB(255,0,0));			
			}
		}

		/*
			Отображение полученного изображения в окне. 
		*/
		ProcessFrame(frame);
		if (g_grid_visible)
			DrawGrid(frame);
		DrawStatus(frame);
		cvShowImage(_MODULE_, frame);
		/*
			Запись фрейма
		*/
		if (g_record_video)
			cvWriteFrame( writer, frame );

		/*
			Анализ клавиатуры
		*/
		bool state = g_set_rects || g_set_contours || g_set_zones;
		int c;
		c = cvWaitKey(10);
		if ((char)c == 27)
			break;

		if ((char)c == 's')
		{
			cvSaveImage("out.png", frame);
		}
		else if ((char)c == 'l')
		{
			if (!state)
				LoadRects(size.width, size.height);
		}
		else if ((char)c == 'g')
		{
			if (!state)
				LoadContours(size.width, size.height);
		}
		else if ((char)c == 'k')
		{
			if (!state)
				LoadZones(size.width, size.height);
		}
		else if ((char)c == 'r')
   		{
			if (g_record_video)
			{
			    // завершаем запись на диск
				cvReleaseVideoWriter( &writer );
				writer = NULL;
				g_record_video = false;
				printf("Stop recording.\n");
			}
			else
			{
				// открываем файл для записи и связываем с ним 
				// переменную writer
				writer = cvCreateVideoWriter("out.avi",CV_FOURCC('D','I','V','X'), fps, size );

				if (writer == NULL)
				{
					printf("%s\n", "Cannot create writer.");
				}
				else
				{
					g_record_video = true;
					printf("Start recording.\n");

				}
			}
		}
		else if ((char)c == 't')
		{
			if (g_set_rects)
			{
				SaveRects(size.width, size.height);
				if (!g_set_zones)
				{
					g_rects_count = 0;
					ClearMask(g_mask);
				}
				g_set_rects = false;
			}
			else if (!g_set_contours)
			{
				g_set_rects = true;
			}
		}
		else if ((char)c == 'c')
		{
			
			if (g_set_contours)
			{
				SaveContours(size.width, size.height);		
				if (!g_set_zones)
				{
					g_contours_count = 0;
					ClearMask(g_mask);
				}
				g_set_contours = false;
				g_open_contour = false;
			}
			else if (!g_set_rects)
			{
				g_set_contours = true;
			}
		}
		else if ((char)c == 'z')
		{
			if (g_set_zones)
			{
				SaveZones(size.width, size.height);
				g_set_zones = false;
				g_contours_count = 0;
				g_rects_count = 0;
				ClearMask(g_mask);
			}
			else if (!g_set_rects && !g_set_contours)
			{
				g_set_zones = true;
			}
		}
		else if ((char)c == 'w')
		{
			g_grid_visible = !g_grid_visible;
		}
	}

	cvReleaseVideoWriter( &writer );
	cvDestroyWindow(_MODULE_);
	cvReleaseCapture(&capture);
	cvReleaseImage(&g_mask);
	// освобождение памяти 
	for (int i = 0; i < C_MAX_OBJECTS; i++)
	{
		free(g_contours[i].Points);
	}

	return 0;
}