Replaced threading with forking. Performance is significantly improved

This commit is contained in:
Matt Hill
2014-07-03 12:16:42 -04:00
parent a5d0b1c073
commit 0c0a424b3b

View File

@@ -161,23 +161,36 @@ int main( int argc, const char** argv )
LOG4CPLUS_INFO(logger, "Using: " << imageFolder << " for storing valid plate images"); LOG4CPLUS_INFO(logger, "Using: " << imageFolder << " for storing valid plate images");
pid_t pid;
for (int i = 0; i < stream_urls.size(); i++) for (int i = 0; i < stream_urls.size(); i++)
{ {
CaptureThreadData* tdata = new CaptureThreadData(); pid = fork();
tdata->stream_url = stream_urls[i]; if (pid == (pid_t) 0)
tdata->camera_id = i + 1; {
tdata->config_file = configFile; // This is the child process, kick off the capture data and upload threads
tdata->output_image_folder = imageFolder; CaptureThreadData* tdata = new CaptureThreadData();
tdata->country_code = country; tdata->stream_url = stream_urls[i];
tdata->site_id = site_id; tdata->camera_id = i + 1;
tdata->config_file = configFile;
tdata->output_image_folder = imageFolder;
tdata->country_code = country;
tdata->site_id = site_id;
tthread::thread* t = new tthread::thread(streamRecognitionThread, (void*) tdata); tthread::thread* thread_recognize = new tthread::thread(streamRecognitionThread, (void*) tdata);
// Kick off the data upload thread
UploadThreadData* udata = new UploadThreadData();
udata->upload_url = upload_url;
tthread::thread* thread_upload = new tthread::thread(dataUploadThread, (void*) udata );
break;
}
// Parent process will continue and spawn more children
} }
// Kick off the data upload thread
UploadThreadData* udata = new UploadThreadData();
udata->upload_url = upload_url;
tthread::thread* t = new tthread::thread(dataUploadThread, (void*) udata );
while (daemon_active) while (daemon_active)
{ {
@@ -225,6 +238,10 @@ void streamRecognitionThread(void* arg)
getTime(&endTime); getTime(&endTime);
double totalProcessingTime = diffclock(startTime, endTime); double totalProcessingTime = diffclock(startTime, endTime);
std::stringstream ss;
ss << "Processed frame in: " << totalProcessingTime << " ms.";
LOG4CPLUS_INFO(logger, ss.str());
if (results.size() > 0) if (results.size() > 0)
{ {
// Create a UUID for the image // Create a UUID for the image