Exemplo n.º 1
0
void MainWindow::processFrameAndUpdateGUI(){
    webCam.read(matImgOriginal);

    if(matImgOriginal.empty()==true) return;

    cv::inRange(matImgOriginal, cv::Scalar(0, 0.175), cv::Scalar(100, 100, 256), matImgProcessed);
    cv::GaussianBlur(matImgProcessed,matImgProcessed,cv::Size(9,9),1.5);
    cv::HoughCircles(matImgProcessed,vecCircles,CV_HOUGH_GRADIENT,2,matImgProcessed.rows/4,100,50,10,400);

     for(itrCircles =vecCircles.begin();itrCircles !=vecCircles.end();itrCircles++)
       {
           ui->Radius->appendPlainText(QString("X: ")+ QString::number((*itrCircles)[0]).rightJustified(4, ' ') +
           QString("Y: ")+ QString::number((*itrCircles)[1]).rightJustified(4, ' ') +
           QString("Radius: ")+ QString::number((*itrCircles)[2], 'f', 3).rightJustified(7,' '));

           cv::circle(matImgOriginal, cv::Point((int)(*itrCircles)[0], (int)(*itrCircles)[1]), 3, cv::Scalar(0,255,0), CV_FILLED);
           cv::circle(matImgOriginal, cv::Point((int)(*itrCircles)[0], (int)(*itrCircles)[1]), (int)(*itrCircles)[2], cv::Scalar(0,255,0), 3);
     }

     cv::cvtColor(matImgOriginal, matImgOriginal, CV_BGR2RGB);

     QImage qimgOriginal((uchar*)matImgOriginal.data, matImgOriginal.cols, matImgOriginal.rows, matImgOriginal.step, QImage::Format_RGB888);
     QImage qimgProcessed((uchar*)matImgProcessed.data, matImgProcessed.cols, matImgProcessed.rows, matImgProcessed.step, QImage::Format_Indexed8);

     ui->Original->setPixmap(QPixmap::fromImage(qimgOriginal));
     ui->Processed->setPixmap(QPixmap::fromImage(qimgProcessed));

}
Exemplo n.º 2
0
void MainWindow::updateGUI(){
    //Webcam
    //capWebcam.read(matOriginal);

    //Drone
    ardrone.setCamera(camera);
    matOriginal = ardrone.getImage();
    if(matOriginal.empty() == true) return;
    cv::resize(matOriginal,matOriginal,cv::Size(400,280));

    cv::cvtColor(matOriginal,matGrey,CV_BGR2GRAY);
    cv::equalizeHist(matGrey,matGrey);

    std::vector<cv::Rect> faces;

    face_cascade.detectMultiScale(matGrey,faces,1.1,3,CV_HAAR_FIND_BIGGEST_OBJECT|CV_HAAR_SCALE_IMAGE,cv::Size(30,30));

    for(size_t i=0;i<faces.size();i++){
        cv::Point pt1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
        cv::Point pt2(faces[i].x, faces[i].y);
        cv::rectangle(matOriginal,faces[i],cv::Scalar(0,255,0,0),1,8,0);
    }

    cv::cvtColor(matOriginal,matOriginal,CV_BGR2RGB);
    cv::cvtColor(matGrey,matGrey,CV_GRAY2RGB);
    QImage qimgOriginal((uchar*)matOriginal.data,matOriginal.cols,matOriginal.rows,matOriginal.step,QImage::Format_RGB888);
    QImage qimgGrey((uchar*)matGrey.data,matGrey.cols,matGrey.rows,matGrey.step,QImage::Format_RGB888);
    ui->lbl_cam->setPixmap(QPixmap::fromImage(qimgOriginal));
    ui->lbl_rendu->setPixmap(QPixmap::fromImage(qimgGrey));
    ui->progressBar->setValue(ardrone.getBatteryPercentage());
    ui->lcd_alt->display(ardrone.getAltitude());
}
void QtObjectTracking::processFrame() {
	cv::Mat frame;
	cv::Mat processed;
	bool succeed = video.read(frame);
	if (succeed) {
		if (start == true) {	//start tracking object
			cv::cvtColor(frame, frame, CV_BGR2HSV);

			cv::inRange(frame, cv::Scalar(ui.lowerHSlider->value(), ui.lowerSSlider->value(), ui.lowerVSlider->value())
				, cv::Scalar(ui.upperHSlider->value(), ui.upperSSlider->value(), ui.upperVSlider->value()), processed);
			
			//openingOperation(processed);
			closingOperation(processed);

			trackObj(processed, frame);

			//Mat 2 Qimage
			cv::cvtColor(frame, frame, CV_HSV2RGB);
			QImage qimgOriginal((uchar*)frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888);
			QImage qimgProcessed((uchar *)processed.data, processed.cols, processed.rows, processed.step, QImage::Format_Indexed8);
			//display Qimage on label
			ui.OriginImg->setPixmap(QPixmap::fromImage(qimgProcessed));
			ui.ProcessedImg->setPixmap(QPixmap::fromImage(qimgOriginal));
		}
		else {	//pause for adjusting filter
			cv::cvtColor(frame, frame, CV_BGR2HSV);
			cv::inRange(frame, cv::Scalar(ui.lowerHSlider->value(), ui.lowerSSlider->value(), ui.lowerVSlider->value())
				, cv::Scalar(ui.upperHSlider->value(), ui.upperSSlider->value(), ui.upperVSlider->value()), processed);

			//openingOperation(processed);
			closingOperation(processed);

			//Mat 2 Qimage
			QImage qimgProcessed((uchar *)processed.data, processed.cols, processed.rows, processed.step, QImage::Format_Indexed8);
			//display Qimage on label
			ui.OriginImg->setPixmap(QPixmap::fromImage(qimgProcessed));
		}
	}
	else {
		return;
	}
}
Exemplo n.º 4
0
void MainWindow::ProcessFrameandDisplay()
{
    WebCam.read(matOriginal);

    if(matOriginal.empty() == true)
        return;

    cv::cvtColor(matOriginal, matOriginal, CV_BGR2RGB);
    QImage qimgOriginal((uchar*)matOriginal.data, matOriginal.cols, matOriginal.rows, matOriginal.step, QImage::Format_RGB888);

    ui->lblVideoSource->setPixmap(QPixmap::fromImage(qimgOriginal));

    if(ui->checkBox_StartCapturing->isChecked())
    {
        ImageIndex++;
        QString FileName = QString :: number (ImageIndex);
        FileName = FileName + ".JPG";
        if(qimgOriginal.save(FileName, 0, -1))
            ui->lblError->setText("Saved file " + FileName);
    }

}
void MainWindow::processFrameAndUpdateGUI()
{
    if(ui->vrMorphControl->isChecked()){
        ui->vrMorphSlider->setEnabled(true);
    }else{
        ui->vrMorphSlider->setEnabled(false);
    }

    if(ui->vrParticleControl->isChecked()){
        ui->vrParticleSlider->setEnabled(true);
    }else{
        ui->vrParticleSlider->setEnabled(false);
    }

    capWebcam.read(matOriginal);
    cv::Size size = cv::Size(280,157);
    cv::resize(matOriginal,matOriginal,size);

    if(matOriginal.empty() == true) return;

    cv::inRange(matOriginal, cv::Scalar(0,0,175), cv::Scalar(100,100,256), matProcessed);
    cv::GaussianBlur(matProcessed, matProcessed, cv::Size(9,9), 1.5);
    cv::HoughCircles(matProcessed, vecCircles, CV_HOUGH_GRADIENT, 2, matProcessed.rows / 4, 100, 50, 5, 400);

    for(itrCircles = vecCircles.begin(); itrCircles != vecCircles.end(); itrCircles++)
    {
        cv::circle(matOriginal, cv::Point((int)(*itrCircles)[0], (int)(*itrCircles)[1]), 3, cv::Scalar(0, 255, 0), CV_FILLED);
        cv::circle(matOriginal, cv::Point((int)(*itrCircles)[0], (int)(*itrCircles)[1]), (int)(*itrCircles)[2], cv::Scalar(0, 0, 255), 3);
        if(ui->vrMorphControl->isChecked()){
            /*if((*itrCircles)[0] < 1/3.0*(280.0)){
            //we have a detection and morph control is enabled, set the slider
                ui->vrMorphSlider->setValue(ui->vrMorphSlider->value()-2);
            }else if((*itrCircles)[0] > 2/3.0*(280)){
                ui->vrMorphSlider->setValue(ui->vrMorphSlider->value()+2);
            }*/
            ui->vrMorphSlider->setValue((int)((*itrCircles)[0]/280.0*100));
            ui->morphPercentageSlider->setValue((int)((*itrCircles)[0]/280.0*100));

        }
        if(ui->vrParticleControl->isChecked()){
            //we have a detection and particle control is enabled, set the slider
           /* if((*itrCircles)[1] < 1/3.0*(157.0)){
            //we have a detection and morph control is enabled, set the slider
                ui->vrParticleSlider->setValue(ui->vrParticleSlider->value()-50);
            }else if((*itrCircles)[1] > 2/3.0*(157.0)){
                ui->vrParticleSlider->setValue(ui->vrParticleSlider->value()+50);
            }*/
            ui->vrParticleSlider->setValue(2000-(int)((*itrCircles)[1]/157.0*2000));
            ui->numberOfParticlesSpinBox->setValue(2000-(int)((*itrCircles)[1]/157.0*2000));
        }
        ui->VRXLocation->setValue((*itrCircles)[0]);
        ui->VRYLocation->setValue(157-(*itrCircles)[1]);
    }

    cv::cvtColor(matOriginal, matOriginal, CV_BGR2RGB);

    QImage qimgOriginal((uchar*)matOriginal.data, matOriginal.cols, matOriginal.rows, matOriginal.step, QImage::Format_RGB888);
    QImage qimgProcessed((uchar*)matProcessed.data, matProcessed.cols, matProcessed.rows, matProcessed.step, QImage::Format_Indexed8);

    ui->lblOriginal->setPixmap(QPixmap::fromImage(qimgOriginal));
    ui->lblProcessed->setPixmap(QPixmap::fromImage(qimgProcessed));
}