Учет и контроль реализации обработки информации на примере ООО "ЭККО-РОС"

Дипломная работа - Компьютеры, программирование

Другие дипломы по предмету Компьютеры, программирование




"highgui.h"

#include "CameraFactory.h"

#include "WorkingThread.h"

#include "..\\CoreDll\\pcount.h"

#include "Resources.h"

#include namespace System;namespace System::Threading;namespace System::Drawing;namespace System::Drawing::Imaging;namespace System::Runtime::InteropServices;namespace System::IO;namespace System::Xml;namespace System::Windows::Forms;namespace PeopleCounterService;namespace PeopleCounterFunctions;namespace ClientLibrary;

#include "definitions.h"

#define INITIALCAMIDX 0

#define TrackBarName "Entrance"

#define WinName "Camera View"Value = INITIALCAMIDX;ValuePrev = INITIALCAMIDX;MaxEntrances = 0;OnMouse(int event, int x, int y, int flags, void* param)

{

if (event == CV_EVENT_LBUTTONDOWN)

{(Value != MaxEntrances-1)++;= 0;(WinName);

}(event == CV_EVENT_RBUTTONDOWN)

{(Value != 0) -;= MaxEntrances - 1;(WinName);

}

} ^tmpArray, IplImage *tmpImg)

{(_image == NULL)

{

return nullptr;

}

IplImage *image = tmpImg;

if (image == NULL ||

image->width != width || image->height != height ||

image->depth != _image->depth || image->nChannels != _image->nChannels ||

image->origin != _image->origin)

{

image = cvCreateImage(cvSize(width, height), _image->depth, _image->nChannels);

image->origin = _image->origin;

}

cvResize(_image, image, CV_INTER_CUBIC );

if (image->nChannels * image->depth != 24)

{

//TODO: Write error log and exit

}

if (!strcmp(image->channelSeq, "RGB"))

{

cvCvtColor( image, image, CV_RGB2BGR );

}

if (image->origin)

{

cvFlip(image, image, 0);

image->origin = 0;

}

array^ data = tmpArray;

if (data == nullptr || data->Length != image->imageSize)

{

data = gcnew arrayimageSize);

}

GCHandle handleOfArray = GCHandle::Alloc(data, GCHandleType::Pinned);

char *dstData = reinterpret_cast(Marshal::UnsafeAddrOfPinnedArrayElement(data, 0).ToPointer());

memcpy_s(dstData, image->imageSize, image->imageData, image->imageSize);

handleOfArray.Free();

if (image != tmpImg)

{

cvReleaseImage(&image);

image = NULL;

}

return data;

}^ PackImage(const IplImage *_image, int width, int height)

{

return PackImage(_image, width, height, nullptr, NULL);

}::WorkingThread(StatisticsServer ^_statisticsServer, int cameraIndex, bool isTest)

{

m_IsTest = isTest;::SetCurrentThreadCulture(Thread::CurrentThread);

m_isTimeToExit = false;

m_CamIdx = cameraIndex;

m_IplFrame = NULL;

StatisticsThread ^stat = gcnew StatisticsThread;

if (stat->LoadStatisticsMethod(cameraIndex))

{

dayReport = gcnew StringBuilder(stat->GetDayStatistics());

dayReportOut = gcnew StringBuilder(stat->GetDayStatisticsOut());

}

else

{

dayReport = gcnew StringBuilder("");

dayReportOut = gcnew StringBuilder("");

}

currentDay = DateTime::Now.Date;

statisticsServer = _statisticsServer;

statisticsServer->SetDayStatisticsDelegate(gcnew GetDayStatistics(this, &WorkingThread::GetDayStatisticsMethod), cameraIndex);

statisticsServer->RegisterGetCurrentCameraImageDelegate(gcnew GetCurrentCameraImageDelegate(this, &WorkingThread::GetCurrentCameraImage), m_CamIdx);

bool isSwitched = Convert::ToBoolean (XmlFunctions::GetCameraXML Parameter("/IsSwitched", m_CamIdx));

InitializeCounters(isSwitched);

m_params = new PCountModelParams;

if (Utilities::LoadPCountParameters((Int64)(m_params), cameraIndex))

{

m_counter = new PCount(*m_params, cameraIndex);

m_drawer = new PCountDrawer(*m_params, isSwitched);

}

else

{

m_counter = new PCount(cameraIndex);

m_drawer = new PCountDrawer(isSwitched);

}

m_IplFrame = NULL;

try

{

m_Camera = CameraFactory::Create(m_CamIdx);

m_VideoWriter.ReadParameters(m_CamIdx);

#if SONAR_ENABLED_SonarDataWriter.ReadParameters(m_CamIdx);

#endif

}

catch(Exception^ e)

{

Log::UpdateDevLog("Error: cant read parameters of cam. " + e->Message);

}

m_LastTimeClientUpdatted = DateTime::MinValue;

//TODO: better to load from settings

m_minUpdatePeriod = TimeSpan(0,0,0,0,200);

tmpImg = 0;

frameLock = gcnew Object;

}::~WorkingThread()

{

if (m_params != NULL)

{

delete m_params;

m_params = NULL;

}

if (m_counter != NULL)

{

delete m_counter;

m_counter = NULL;

}

if (tmpImg != NULL)

{

delete tmpImg;

tmpImg = NULL;

}

}WorkingThread::SafeStartWorking()

{

try

{

StartWorking();

}

catch(Exception ^e)

{

Log::UpdateDevLog("Error in start working function. " + e->Message);

System::Diagnostics::Process::GetCurrentProcess()->Kill();

}

}WorkingThread::SendReportIfNeeded()

{

//Check date is the same as on the last iteration

DateTime^ startReportTime;

DateTime^ endReportTime;

DateTime^ curTime;

bool reportTime = false;

DateTime now = DateTime::Now;

//If it is time to send a report (IsItTimeToSendReport) OR

//save statistics to dat folder (currentDay->CompareTo(now->Date))

if ((reportTime = ReportWorker::IsItTimeToSendReport(startReportTime, endReportTime, curTime)) ||

CompareTo(now.Date))">currentDay->CompareTo(now.Date))

{

StatisticsThread^ stats = gcnew StatisticsThread;

//Block access to dayReport/Out

Monitor::Enter(this);

stats->SetDayStatistics(dayReport->ToString(), dayReportOut->ToString(), currentDay);

//save statistics to dat file every day

CompareTo(now.Date))">if (currentDay->CompareTo(now.Date))

{

stats->m_camIndex = m_CamIdx;

stats->SaveStatistics();

m_LastTimeReportSent = now;

//TODO: check the saving succeed

StatisticsThread ^stat = gcnew StatisticsThread;

if (stat->LoadStatisticsMethod(m_CamIdx))

{

dayReport = gcnew StringBuilder(stat->GetDayStatistics());

dayReportOut = gcnew StringBuilder(stat->GetDayStatisticsOut());

}

else

{

dayReport = gcnew StringBuilder("");

dayReportOut = gcnew StringBuilder("");

}

}

Monitor::Exit(this);

CompareTo(now.Date))">if (currentDay->CompareTo(now.Date))

{

currentDay = now.Date;

}

if (reportTime && endReportTime->CompareTo(startReportTime) > 0 && m_CamIdx == 0)

{

int number = Utilities::GetNumberOfEntrances();

array(number);

array(number);

array(number);

for (int i = 0; i < number; i++)

{

reportArchiveFiles[i] = ResourcesDepository::GetString("ArchiveFolderInProgramFiles") // Users backup folder

+ XmlFunctions::GetXMLParameter("/CounterParameters/ShopID")

+ "-"

+ (i+1).ToString()

+ "__"

+ DateStringConverter::GetCurrentFormattedTimeForFilename(startReportTime)

+ "__"

+ DateStringConverter::GetCurrentFormattedTimeForFilename(endReportTime)

+ ".dat";

reportReadyToSendFiles[i] = ResourcesDepository::GetString ("ReadyToSend FolderInProgramFiles") // This folder contains reports are going to send

+ XmlFunctions::GetXMLParameter("/CounterParameters/ShopID")

+ "-"

+ (i+1).ToString()

+ "__"

+ DateStringConverter::GetCurrentFormattedTimeForFilename(startReportTime)

+ "__"

+ DateStringConverter::GetCurrentFormattedTimeForFilename(endReportTime)

+ ".dat";[i] = ResourcesDepository::GetString("Ready ToIndexFolderInProgramFiles") // This folder contains reports are going to index (cache)

+ XmlFunctions::GetXMLParameter("/CounterParameters/ShopID")

+ "-"

+ (i+1).ToString()

+ "__"

+ DateStringConverter::GetCurrentFormattedTimeForFilename(startReportTime)

+ "__"

+ DateStringConverter::GetCurrentFormattedTimeForFilename(endReportTime)

+ ".dat";

}

try

{

//Make sure the directories exist::CreateDirectory(ResourcesDepository::GetString("ArchiveFolderInProgramFiles")); ::CreateDirectory(ResourcesDepository::GetString("ReadyToSendFolderInProgramFiles")); ::CreateDirectory(ResourcesDepository::GetString("ReadyToIndexFolderInProgramFiles"));

stats->SetReportInterval(star