int main(int argc, char *argv[]){// qInstallMessageHandler(myMessageOutput); QCoreApplication app(argc, argv); // Load the configuration file QString configFileName=searchConfigFile(); QSettings* listenerSettings=new QSettings(configFileName, QSettings::IniFormat, &app); listenerSettings->beginGroup("listener"); // Start the HTTP server new HttpListener(listenerSettings, new RequestMapper(&app), &app); return app.exec();}
void RequestMapper::service(HttpRequest& request, HttpResponse& response) { QByteArray path=request.getPath(); qDebug("RequestMapper: path=%s",path.data()); if (path=="/stop") { StopController().service(request, response); } else if (path=="/start") { StartController().service(request, response); } else if(path=="/data") { DataController().service(request, response); } else { response.setStatus(404,"Not found"); response.write("The URL is wrong, no such document.",true); } qDebug("RequestMapper: finished request");}
void StartController::service(HttpRequest &request, HttpResponse &response) { QJsonObject json; cameraID = 0; newCameraID = 0; QByteArray url = request.getParameter("url"); QByteArray minArea = request.getParameter("minArea"); QByteArray maxArea = request.getParameter("maxArea"); QByteArray startx = request.getParameter("x0"); QByteArray starty = request.getParameter("y0"); QByteArray endx = request.getParameter("x1"); QByteArray endy = request.getParameter("y1"); dbthread = new QThread; impthread = new QThread; worker = new DbWriteWorker(); worker->setInterval(60); worker->moveToThread(dbthread); impworker = new ImageProcessingWorker(0, QString::fromUtf8(startx).toInt(), QString::fromUtf8(starty).toInt(), QString::fromUtf8(endx).toInt(), QString::fromUtf8(endy).toInt(), QString::fromUtf8(minArea).toInt(), QString::fromUtf8(maxArea).toInt(), 1, QString::fromUtf8(url)); impworker->moveToThread(impthread); // Соединяем сигнал started потока, со слотом process "рабочего" класса, т.е. начинается выполнение нужной работы. connect(dbthread, SIGNAL(started()), worker, SLOT(process())); connect(impthread, SIGNAL(started()), impworker, SLOT(process())); // По завершению выходим из потока, и удаляем рабочий класс connect(worker, SIGNAL(finished()), dbthread, SLOT(quit())); connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater())); connect(impworker, SIGNAL(finished()), impthread, SLOT(quit())); connect(impworker, SIGNAL(finished()), impworker, SLOT(deleteLater())); // Удаляем поток, после выполнения операции connect(dbthread, SIGNAL(finished()), dbthread, SLOT(deleteLater())); connect(impthread, SIGNAL(finished()), impthread, SLOT(deleteLater())); connect(impworker, SIGNAL(sendCounters(int,int, int)), worker, SLOT(waitForDB(int,int,int))); connect(worker, SIGNAL(getDataSignal()), impworker, SLOT(prepareCounters())); dbthread->start(); impthread->start();
while(1) { isRead = capture.read(imgFrame2); blobProcess(imgFrame1, imgFrame2, frameCount); imgFrame2Copy = imgFrame2.clone(); // get another copy of frame 2 since we changed the previous frame 2 copy in the processing above drawBlobInfoOnImage(blobs, imgFrame2Copy); bool blnAtLeastOneBlobCrossedTheLine = checkIfBlobsCrossedTheLine(blobs); if (blnAtLeastOneBlobCrossedTheLine == true) { cv::line(imgFrame2Copy, crossingLine[0], crossingLine[1], SCALAR_GREEN, 2); } else { cv::line(imgFrame2Copy, crossingLine[0], crossingLine[1], SCALAR_RED, 2); } drawCarCountOnImage(countAB, countBA, imgFrame2Copy); if(isDebug) cv::imshow("imgFrame2Copy", imgFrame2Copy); writer.write(imgFrame2Copy); imgFrame1 = imgFrame2.clone(); // move frame 1 up to where frame 2 is capture.read(imgFrame2); blobsPrev.clear(); for(int i = 0; i < blobs.size(); i++) blobsPrev.push_back(blobs[i]); blnFirstFrame = false; frameCount++; if(procToKill == cameraID) break; QThread::msleep(80); }
QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(prepareCounters())); timer->start(5000);
void ImageProcessingWorker::prepareCounters(){ qDebug() << "ImageProcessingWorker::prepareCounters send counters"; emit sendCounters(cameraID, countAB, countBA);}