void MainWindow::on_AdelgazamientoBT_clicked() { dstImageAdelgazada = Mat::zeros(dstImageClose.size(), CV_8UC1); dstImageClose.copyTo(dstImageAdelgazada); ControlPreprocesamiento::adelgazamiento(dstImageAdelgazada); dstImageAdelgazada.copyTo(dstImageRectanguloEnvolvente); //Se suman 3 pixeles de distancia a las medidas del rectangulo para darle espacio //alalgoritmo de busqueda de end-points // Rect rect = boundingRect(dstImageAdelgazada); // if(dstRectanguloEnvolvente.x <= 5 || dstRectanguloEnvolvente.y <= 5 ) continue; dstRectanguloEnvolvente.height += 10; dstRectanguloEnvolvente.width += 10; dstRectanguloEnvolvente.x -= 5; dstRectanguloEnvolvente.y -= 5; rectangle(dstImageRectanguloEnvolvente,dstRectanguloEnvolvente,Scalar(255)); //Convertir imagenes y transformarlas para mostrar en la UI QImage RectanguloEnvolventeImage = Mat2QImage(dstImageRectanguloEnvolvente); ui->RectanguloEnvolventeLB->setPixmap(QPixmap::fromImage(RectanguloEnvolventeImage)); QImage adelgazamientoImage = Mat2QImage(dstImageAdelgazada); ui->AdelgazamientoLB->setPixmap(QPixmap::fromImage(adelgazamientoImage)); //Habilitar el boton de Caracteristicas ui->CaracteristicasBT->setEnabled(true); }
void MainWindow::putImage(const Mat& src,int windowID){ switch(windowID){ case LEFT_WINDOW: qimageL = Mat2QImage(src); ui->lblOriginalLeft->setPixmap(QPixmap::fromImage(qimageL)); break; case RIGHT_WINDOW: qimageR = Mat2QImage(src); ui->lblOriginalRight->setPixmap(QPixmap::fromImage(qimageR)); break; } }
void VideoEditorWidget::processSelectedImage(const sensor_msgs::Image::ConstPtr msg) { // image //ROS_ERROR("Encoding: %s", msg->encoding.c_str()); double aspect_ratio = (double)msg->width/(double)msg->height; // ROS_ERROR("Size: %dx%d aspect %f", msg->width, msg->height, aspect_ratio); cv_bridge::CvImagePtr cv_ptr; try { cv_ptr = cv_bridge::toCvCopy(*msg, sensor_msgs::image_encodings::BGR8); } catch (cv_bridge::Exception& e) { //ROS_ERROR("cv_bridge exception: %s", e.what()); return; } cv::Size2i img_size; if(aspect_ratio > 1) { img_size.width = ui->image_view->width(); img_size.height = ((float)ui->image_view->width())/aspect_ratio; } else { img_size.width = ((float)ui->image_view->height())/aspect_ratio; img_size.height = ui->image_view->height(); } cv::resize(cv_ptr->image, cv_ptr->image, img_size, 0, 0, cv::INTER_NEAREST); QImage tmp = Mat2QImage(cv_ptr->image); QPixmap pixmap = QPixmap::fromImage(tmp); ui->image_view->setPixmap(pixmap); }
void CameraHandler::run(){ camera.StartCapture(); qDebug() << "Started Capture"; unsigned int rowBytes; while(1){ //qDebug() << "Start of loop"; error = camera.RetrieveBuffer(&rawImage); if(error != FlyCapture2::PGRERROR_OK){ continue; } //qDebug() << "In image loop"; rawImage.Convert(FlyCapture2::PIXEL_FORMAT_RGB8, &rgbImage); rowBytes = (double)rgbImage.GetReceivedDataSize()/(double)rgbImage.GetRows(); cv::Mat cvImageMatrix = cv::Mat(rgbImage.GetRows(), rgbImage.GetCols(), CV_8UC3, rgbImage.GetData(), rowBytes); image = Mat2QImage(cvImageMatrix); //cameraWindow->setPicture(QPixmap::fromImage(image)); emit gotCameraImage(image); /* emit signal containing camera image */ //msleep(10); } }
void ROSOutput3DWrapper::showKeyframeDepth(const cv::Mat& image){ // //testing // // // cv::Mat ch1, ch2, ch3, test; // // "channels" is a vector of 3 Mat arrays: // std::vector<cv::Mat> channels(3); // // split img: // cv::split(image, channels); // ch1 = channels[0]; // ch2 = channels[1]; // ch3 = channels[2]; // test = ch1.clone(); // test = cv::Scalar(255); // std::vector<cv::Mat> diff(3); // diff[0] = test != ch1; // diff[1] = test != ch2; // diff[2] = test != ch3; // for(int i = 0; i < 3; i++){ // bool isequal = cv::countNonZero(diff[i]) == 0; // if(!isequal) // qDebug() << "\t\t ERROR #########################"; // } // // // //end testing v1->setImage(Mat2QImage(image)); }
void operator()(const tbb::blocked_range<short>& range) const { for (short labelid=range.begin(); labelid!=range.end(); ++labelid) { // Compute mask. // For big images it might make sense to parallelize this on a // smaller granularity (pixel ranges). // And it might be a good idea to cache these. cv::Mat1b mask(labels == labelid); if(tbb::task::self().is_cancelled()) { //GGDBGM("aborted through tbb cancel." << endl); return; } // transform mask into icon cv::Mat1b masktrf = cv::Mat1b::zeros(iconSizecv); cv::warpAffine(mask, masktrf, trafo, iconSizecv, CV_INTER_AREA); if(tbb::task::self().is_cancelled()) { //GGDBGM("aborted through tbb cancel." << endl); return; } // The rest is probably too fast to allow checking for cancellation. QColor color = ctx.colors.at(labelid); // Fill icon with solid color in ARGB format. cv::Vec4b argb(0, color.red(), color.green(), color.blue()); cv::Mat4b icon = cv::Mat4b(iconSizecv.height, iconSizecv.width, argb); // Now apply alpha channel. // Note: this is better than OpenCV's mask functionality as it // preserves the antialiasing! // Make ARGB 'array' which is interleaved to a true ARGB image // using mixChannels. const cv::Mat1b zero = cv::Mat1b::zeros(iconSizecv.height, iconSizecv.width); const cv::Mat in[] = {masktrf, zero, zero, zero}; // Copy only the alpha channel (0) of the in array into the // alpha channel (0) of the ARGB icon. const int mix[] = {0,0}; // 4 input matrices, 1 dest, 1 mix-pair cv::mixChannels(in,4, &icon,1, mix,1); // convert the result to a QImage QImage qimage = Mat2QImage(icon); /* draw a border (alternative: the icon view could do this) */ QPainter p(&qimage); QPen pen(color); // ensure border visibility, fixed to 1px pen.setWidthF(1.f); p.setPen(pen); p.drawRect(brect); ctx.icons[labelid] = qimage; } }
void PhotoDialog::timerEvent(QTimerEvent *){ if(this->isSwitching||this->isshot) return; if(this->capture->isOpened()) (*this->capture)>>imagemat; QImage img = Mat2QImage(this->imagemat); this->ui->imageLabel->setPixmap(QPixmap::fromImage(img)); }
void MainWindow::disp_image() { Mat tmp_img; cur_img.copyTo(tmp_img); QImage qimg = Mat2QImage(tmp_img); img_label->setPixmap(QPixmap::fromImage(qimg)); }
void DisplayManager::display(const cv::Mat &image) { QImage *qImage = Mat2QImage(resize(image)); QPixmap img = QPixmap::fromImage(*qImage); label->setPixmap(img); delete qImage; }
void MainForm::myimshow(cv::Mat & frame) { video_frame->setPixmap(QPixmap::fromImage(Mat2QImage(frame))); //video_frame->update(); video_frame->show(); mut.unlock(); //qApp->processEvents(); }
void MainWindow::on_SegmentacionBT_clicked() { Mat src = imread(this->imageFile.toStdString()); ControlSegmentacion::encontrarSegmentos(src,dstImageClose,dstImageSegmentacion,dstRectanguloEnvolvente); QImage segmentacionImage = Mat2QImage(this->dstImageSegmentacion); ui->SegmentacionLB->setPixmap(QPixmap::fromImage(segmentacionImage)); ui->AdelgazamientoBT->setEnabled(true); }
/** * @brief MapManager::printImage slot chiamato quando il robot invia immagini della camera da mostrare * @param cvImage l'immagine da mostrare */ void MapManager::printImage(cv::Mat cvImage) { // Converto l'immagine da Mat a QImage QImage image = Mat2QImage(cvImage); // Setto l'immagine e aggiorno la grandezza della finestra cameraLabel.setPixmap(QPixmap::fromImage((image))); cameraLabel.adjustSize(); }
void FalseColorModelPayload::processRunnerSuccess(std::map<std::string, boost::any> output) { runner->deleteLater(); if(canceled) { return; } cv::Mat3f mat = boost::any_cast<cv::Mat3f>(output["multi_img"]); result.convertFromImage(Mat2QImage((cv::Mat3b)mat)); emit finished(coloringType, true); // success }
/** * @brief MapManager::printVictimImage slot chiamato quando il robot trova una vittima * @param cvImage l'immagine da mostrare */ void MapManager::printVictimImage(cv::Mat cvImage) { QImage image = Mat2QImage(cvImage); QLabel *victimImage = new QLabel(); victimImage->setPixmap(QPixmap::fromImage((image))); victimImage->adjustSize(); layout->addWidget(victimImage); }
void MainWindow::timerEvent(QTimerEvent *event) { counter +=1; ui->labelCounter->setText(QString("Count is: %1").arg(QString::number(counter))); if (ui->pbStartCamera->isChecked()) { camera.run(); ui->labelDispImage->setPixmap(QPixmap::fromImage(Mat2QImage(camera.getDisparityImage()))); } }
void FaceDetector::run(){ CascadeClassifier cascade; if (!cascade.load("res/haarcascade_frontalface_alt.xml") ) { qDebug() << "Erreur lors du chargement du haar cascade frontalface..."; exit(0); } QSize processSize = keepAspectRatio(_image.cols, _image.rows, MAX_PROCESS_WIDTH, MAX_PROCESS_HEIGHT); Mat color; if ( _image.cols > processSize.width() ){ cv::resize( _image, color, cv::Size(processSize.width(), processSize.height() ) ); } else { color = _image.clone(); } QSize displaySize = keepAspectRatio(color.cols, color.rows); _ratio = (double) color.cols/displaySize.width(); Mat gray; cvtColor(color, gray, CV_BGR2GRAY); //PRETRAITEMENT equalizeHist(gray, gray); vector<Rect> facesRects; cascade.detectMultiScale(gray, facesRects, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, cvSize(16,16)); // qDebug() << "detected faces size: " << facesRects.size(); for (unsigned int i = 0; i < facesRects.size(); ++i){ Rect r = facesRects[i]; Mat croppedFace; getRectSubPix(color, Size(r.width, r.height), Point2f(r.x + r.width/2, r.y + r.height / 2), croppedFace); // qImageFaces << Mat2QImage(croppedFace); struct DetectorData tmpData; tmpData.id = i; cv::resize( croppedFace, croppedFace, Size(WORK_SIZE,WORK_SIZE) ); tmpData.image = Mat2QImage(croppedFace); emit sendFace( tmpData.image ); tmpData.rect = QRect(r.x/_ratio+1, r.y/_ratio+1, r.width/_ratio+1, r.height/_ratio+1); tmpData.cvRect = r; tmpData.mat = croppedFace; cvtColor(croppedFace, tmpData.gray, CV_RGB2GRAY); // cv::resize( tmpData.gray, tmpData.gray, Size(WORK_SIZE,WORK_SIZE) ); detectorData << tmpData; } qRegisterMetaType< QList<struct DetectorData> >( "QList<struct DetectorData>" ); emit detectionFinished( _index, detectorData ); }
void MainWindow::on_calcularUmbralBT_clicked() { this->dstImageThresholdAdaptative = ControlPreprocesamiento::umbralAutomaticoAdaptativo(srcImage); this->dstImageThreshold = ControlPreprocesamiento::umbralAutomatico(srcImageEqualizada); QImage umbralImage = Mat2QImage(dstImageThresholdAdaptative); ui->UmbralizacionLB->setPixmap(QPixmap::fromImage(umbralImage)); ui->AperturaBT->setEnabled(true); }
void MainWindow::on_AperturaBT_clicked() { Mat BStructElement = getStructuringElement(CV_SHAPE_RECT,Size(2,2)); morphologyEx(this->dstImageThresholdAdaptative, this->dstImageClose, CV_MOP_CLOSE, BStructElement,Point(-1,-1) ,2 ); QImage filtradoImage = Mat2QImage(dstImageClose); ui->FiltradoMorfologicoLB->setPixmap(QPixmap::fromImage(filtradoImage)); ui->SegmentacionBT->setEnabled(true); }
void GammaDialog::viewGamma(){ double inverse_gamma = 50 / slSigma->value(); cv::Mat lut_matrix(1, 256, CV_8UC1 ); uchar * ptr = lut_matrix.ptr(); for( int i = 0; i < 256; i++ ) ptr[i] = (int)( cv::pow( (double) i / 255.0, inverse_gamma ) * 255.0 ); cv::Mat result; cv::LUT( QImage2Mat(imgM), lut_matrix, result ); imgL->setPixmap(QPixmap::fromImage(Mat2QImage(result).scaledToWidth(anch))); }
QString SquareOcl::start_preview(int operate_type, QLabel* lb_image) { QString str_result = ""; Mat mat_image = imread(SQUARE_OCL_FILE_SRC, 1); vector<vector<Point> > squares; long start_time, end_time; if(mat_image.empty()) { str_result = "Couldn't load "; str_result.append(SQUARE_OCL_FILE_SRC); return str_result; } if(operate_type == OPENCL_CL_OFF_H) { start_time = getTickCount(); find_squares_cpu(mat_image, squares); end_time = getTickCount(); } else if(operate_type == OPENCL_CL_ON_H) { // OCL Init vector<ocl::Info> info; CV_Assert(cv::ocl::getDevice(info)); start_time = getTickCount(); find_squares_gpu(mat_image, squares); end_time = getTickCount(); } else { str_result = "Not Operate Mode!!"; return str_result; } draw_squares(mat_image, squares); QImage tmp_image = Mat2QImage(mat_image); lb_image->setPixmap(QPixmap::fromImage(tmp_image)); str_result = QString("Find Search Result : \n - Square Count : ") + QString::number(squares.size()); str_result = str_result + QString("\n - Search Time : "); str_result = str_result + QString::number(1000.0f * (double)(end_time - start_time) / getTickFrequency() / 10 ).append("ms"); return str_result; }
void MorphologyWindow::updateStructuringElement() { int size = ui->sizeSpinBox->value(); if (ui->squareRadioButton->isChecked()) { structuringElement = cv::Mat::ones(size, size, CV_8U) * 255; } else { structuringElement = cv::Mat::zeros(size, size, CV_8U); int center = (size - 1) / 2; if (ui->customRadioButton->isChecked()) { // TODO structuringElement.at<quint8>(center, center) = 255; } else if (ui->crossRadioButton->isChecked()) { for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) if ((i == center) || (j == center)) structuringElement.at<quint8>(i, j) = 255; } else if (ui->diskRadioButton->isChecked()) { int squaredRadius = center * center; for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) if (((i - center) * (i - center) + (j - center) * (j - center)) <= squaredRadius) structuringElement.at<quint8>(i, j) = 255; } else if (ui->xRadioButton->isChecked()) { for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) if ((i == j) || (i == (size - j - 1))) structuringElement.at<quint8>(i, j) = 255; } } QPixmap pixmap = QPixmap::fromImage(Mat2QImage(structuringElement)); QSize labelSize = ui->structuringElementLabel->size(); ui->structuringElementLabel->setPixmap(pixmap.scaled(labelSize, Qt::KeepAspectRatio)); }
void Image::update() const { double min, max; cv::minMaxLoc(current, &min, &max); ui->minimumLabel->setText(QString::number(min)); ui->maximumLabel->setText(QString::number(max)); ui->heightLabel->setText(QString::number(current.rows)); ui->widthLabel->setText(QString::number(current.cols)); switch (current.channels()) { case 1: ui->channelLabel->setText("1"); break; case 3: ui->channelLabel->setText("3"); break; } switch (current.depth()) { case CV_8U: ui->depthLabel->setText("8 bits"); break; case CV_32F: ui->depthLabel->setText("32 bits"); break; } QPixmap pixmap = QPixmap::fromImage(Mat2QImage(current)); if (ui->fitToScreenCheckBox->isChecked()) pixmap = pixmap.scaled(ui->displayLabel->size(), Qt::KeepAspectRatio); ui->displayLabel->clear(); ui->displayLabel->setPixmap(pixmap); }
QVector <face> center_faces(QImage frame, QImage* ResultImg, float scale) { QVector <face> null_face; QVector <face> find_faces; int number_of_true_face = -1; Mat image = qimage2mat(frame); if(image.empty()) { cout << "Couldn't read image" << endl; return null_face; } *ResultImg = Mat2QImage(detect_Face_and_eyes(image, scale, find_faces)); for(int i = 0; i < find_faces.size(); i++) { if(find_faces[i].number_eyes()>=1) { number_of_true_face = i; } } if(number_of_true_face!=-1) return find_faces; return null_face; }
void ROSOutput3DWrapper::showStereoReferenceFrame(const cv::Mat& image){ v4->setImage(Mat2QImage(image)); }
void SmoothDialog::viewSmooth(){ src = QImage2Mat(imgM); cv::Mat dst; if(box->isChecked()){ slSigmaX->setDisabled(true); slSigmaY->setDisabled(true); for ( int i = 1; i < slKSize->value(); i = i + 2 ){ cv::boxFilter(src,dst,-1,cv::Size(i,i)); src = dst; } imgL->setPixmap(QPixmap::fromImage(Mat2QImage(dst)).scaledToWidth(anch)); } else if(median->isChecked()){ slSigmaX->setDisabled(true); slSigmaY->setDisabled(true); for ( int i = 1; i < slKSize->value(); i = i + 2 ){ cv::medianBlur(src,dst,i); src = dst; } imgL->setPixmap(QPixmap::fromImage(Mat2QImage(dst)).scaledToWidth(anch)); } else if(bilateral->isChecked()){ slSigmaX->setEnabled(true); slSigmaY->setEnabled(true); for ( int i = 1; i < slKSize->value(); i = i + 2 ){ cv::bilateralFilter(src,dst,i,slSigmaX->value(),slSigmaY->value()); } imgL->setPixmap(QPixmap::fromImage(Mat2QImage(dst)).scaledToWidth(anch)); } else if(gaussian->isChecked()){ slSigmaX->setEnabled(true); slSigmaY->setEnabled(true); for ( int i = 1; i < slKSize->value(); i = i + 2 ){ cv::GaussianBlur( src, dst, cv::Size( i, i ),slSigmaX->value(), slSigmaY->value()); src = dst; } imgL->setPixmap(QPixmap::fromImage(Mat2QImage(dst)).scaledToWidth(anch)); }/* for(int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) { blur( src, dst, Size( i, i ), Point(-1,-1) ); if( display_dst( DELAY_BLUR ) != 0 ) { return 0; } } /// Applying Gaussian blur if( display_caption( "Gaussian Blur" ) != 0 ) { return 0; } for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) { GaussianBlur( src, dst, Size( i, i ), 0, 0 ); if( display_dst( DELAY_BLUR ) != 0 ) { return 0; } } /// Applying Median blur if( display_caption( "Median Blur" ) != 0 ) { return 0; } for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) { medianBlur ( src, dst, i ); if( display_dst( DELAY_BLUR ) != 0 ) { return 0; } } /// Applying Bilateral Filter if( display_caption( "Bilateral Blur" ) != 0 ) { return 0; } for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) { bilateralFilter ( src, dst, i, i*2, i/2 ); if( display_dst( DELAY_BLUR ) != 0 ) { return 0; } }*/ }
void ROSOutput3DWrapper::showTrackingResidual(const cv::Mat& image){ v2->setImage(Mat2QImage(image)); }
void ROSOutput3DWrapper::showStereoKeyframe(const cv::Mat& image){ v3->setImage(Mat2QImage(image)); }
void VideoEditorWidget::addImageChild(QTreeWidgetItem *parent, const unsigned long& id, const std::string& topic, const sensor_msgs::Image& image, const sensor_msgs::CameraInfo& camera_info) { /*int row = 0; ui->treeWidget->add; ui->treeWidget->setRowHeight(row,100);*/ // add info about images to the table QTreeWidgetItem * item; // image item = new QTreeWidgetItem(); //ROS_ERROR("Encoding: %s", image.encoding.c_str()); double aspect_ratio = (double)image.width/(double)image.height; // ROS_ERROR("Size: %dx%d aspect %f", image.width, image.height, aspect_ratio); cv_bridge::CvImagePtr cv_ptr; try { cv_ptr = cv_bridge::toCvCopy(image, sensor_msgs::image_encodings::BGR8); } catch (cv_bridge::Exception& e) { // ROS_ERROR("cv_bridge exception: %s", e.what()); return; } cv::Size2i img_size; if(aspect_ratio > 1) { img_size.width = 100.0f; img_size.height = 100.0f/aspect_ratio; } else { img_size.width = 100.0f/aspect_ratio; img_size.height = 100.0f; } cv::resize(cv_ptr->image, cv_ptr->image, img_size, 0, 0, cv::INTER_NEAREST); QImage tmp = Mat2QImage(cv_ptr->image); QPixmap pixmap = QPixmap::fromImage(tmp); item->setData(0,Qt::DecorationRole, pixmap); item->setToolTip(0,QString::number(id)); //ui->treeWidget->setItem(row,0,item); //ROS_ERROR("Added %ld to the table",id); // stamp //item = new QTreeWidgetItem(timeFromMsg(image.header.stamp)); item->setText(1,timeFromMsg(image.header.stamp)); item->setToolTip(1,QString::number((int)image.header.stamp.toSec())); // source //item = new QTreeWidgeexttItem(QString(topic.c_str())); item->setText(2,QString(topic.c_str())); // width // item = new QTreeWidgetItem(QString::number(image.width)); item->setText(3,QString::number(image.width)); // height // item = new QTreeWidgetItem(QString::number(image.height)); item->setText(4,QString::number(image.height)); parent->setText(1,timeFromMsg(image.header.stamp)); parent->setText(2,QString(topic.c_str())); //parent->parent()->setText(1,timeFromMsg(image.header.stamp)); parent->addChild(item); }
void ImgWidget::setImageMat(cv::Mat &src){ src_img_mat=src.clone(); src_img_q = Mat2QImage(src_img_mat); }