bool ImageViewer::saveLabelledResult(QString path, QString ext) { if(!_srcOcvImage) return false; if(!_displayImage) return false; if(!_result_display) return false; QString path1 = QString("%1_0.%2").arg(path).arg(ext); QString path2 = QString("%1_1.%2").arg(path).arg(ext); IplImage* cv_result_display = QImageToIplImage(*_result_display); IplImage* scaled = cvCreateImage(cvSize(this->_orgWidth, this->_orgHeight), cv_result_display->depth, cv_result_display->nChannels); cvResize(cv_result_display, scaled, CV_INTER_CUBIC); QImage* temp = IplImageToQImage(scaled); bool ret1 = temp->save(path1, ext.toUtf8().constData()); DELETEPTR(temp); IplImage* cv_result_save = QImageToIplImage(*_result_save); cvResize(cv_result_save, scaled, CV_INTER_CUBIC); temp = IplImageToQImage(scaled); bool ret2 = temp->save(path2, ext.toUtf8().constData()); DELETEPTR(temp); cvReleaseImage(&cv_result_display); cvReleaseImage(&scaled); cvReleaseImage(&cv_result_save); return ret1 && ret2; }
void VentanaPrincipal::MostrarImagenes(IplImage* rImgMondrian, IplImage* rImgOriginal) { //Se modifica el tamano de las imagenes cvResize(rImgOriginal,mImagenOriginal); cvResize(rImgMondrian,mImagenMondrian); //Se les aplica el efecto mirror cvFlip(mImagenOriginal,mImagenOriginal,1); cvFlip(mImagenMondrian,mImagenMondrian,1); //Se muestran en la ventana ui->label_foto_original->setPixmap(QPixmap::fromImage(IplImageToQImage(mImagenOriginal),0)); ui->label_foto_mondrian->setPixmap(QPixmap::fromImage(IplImageToQImage(mImagenMondrian), 0)); }
void ImageView::canny() { IplImage *currentIpl = ImageToIplImage(¤tPixmap); if(currentIpl == 0) return; //! IplImage *dst = toGray(currentIpl); float r = random(); int low = static_cast<int>(r*150+0.5); int high = static_cast<int>(r*200+0.5); cvCanny(dst, dst, low, high); // ALGORITHMS QImage *image = 0; if(dst->width > MAX_ALLOWED_SIZE) { image = IplImage2QImageLowEffect(dst); } else { image = IplImageToQImage(dst, (uchar**)&dst->imageData, 0, 0); } currentPixmap = QPixmap::fromImage(*image); /// @warning BIG IMAGE CORRUCTED update(); // Update the curreent image cvReleaseImage(&dst); cvReleaseImage(¤tIpl); delete image; ui->statusBar->showMessage("Canny"); }
void ImageView::bilateral_smooth() { IplImage *currentIpl = ImageToIplImage(¤tPixmap); if(currentIpl == 0) return; IplImage *grayImage = toGray(currentIpl); IplImage *dst = cvCloneImage(grayImage); cvSmooth(grayImage, dst, CV_BILATERAL, 3, 0, 0, 0); cvReleaseImage(&grayImage); QImage *image = 0; if(dst->width > MAX_ALLOWED_SIZE) { image = IplImage2QImageLowEffect(dst); } else { image = IplImageToQImage(dst, (uchar**)&dst->imageData, 0, 0); } currentPixmap = QPixmap::fromImage(*image); update(); // Update the curreent image delete image; cvReleaseImage(&dst); cvReleaseImage(¤tIpl); ui->statusBar->showMessage("Bilateral Smooth"); }
bool ImageViewer::saveMask(QString path, QString ext) { if(_mask.empty()) return false; path = QString("%1.%2").arg(path).arg(ext); if(m_method == 0) { return saveLabelMap(path, ext.toUtf8().constData()); } else { _mask = _mask * 255; cv::Mat edgeMap; cv::Canny(_mask, edgeMap, 1, 3); cv::Mat edge; cv::resize(edgeMap, edge, cv::Size(_orgWidth, _orgHeight), 0, 0, cv::INTER_CUBIC); IplImage* temp = new IplImage(edge); QImage* temp2 = IplImageToQImage(temp); bool ret = temp2->save(path, ext.toUtf8().constData()); if(temp2) delete temp2; return ret; } }
void ImageView::median_smoooth() { IplImage *currentIpl = ImageToIplImage(¤tPixmap); if(currentIpl == 0) return; IplImage *grayImage = toGray(currentIpl); IplImage *dst = cvCloneImage(grayImage); cvSmooth(grayImage, dst, CV_MEDIAN, 3, 0, 0, 0); cvReleaseImage(&grayImage); QImage *image = 0; if(dst->width > MAX_ALLOWED_SIZE) { image = IplImage2QImageLowEffect(dst); } else { image = IplImageToQImage(dst, (uchar**)&dst->imageData, 0, 0); } currentPixmap = QPixmap::fromImage(*image); update(); // Update the curreent image delete image; cvReleaseImage(&dst); cvReleaseImage(¤tIpl); ui->statusBar->showMessage("Median Smooth"); #if(0) // Testing Code IplImage *ipl = cvLoadImage("E:/yang.jpg"); cvNamedWindow("AAA",CV_WINDOW_AUTOSIZE); cvShowImage("AAA", ipl); QImage *image = IplImageToQImage(ipl, (uchar**)&ipl->imageData, 0, 0); currentPixmap = QPixmap::fromImage(*image); update(); cvWaitKey(0); cvReleaseImage(&ipl); cvDestroyWindow("AAA"); delete image; #endif }
void testNode_MainWindow::timerEvent(QTimerEvent *) { if(ui->tabWidget->currentIndex()==0){ IplImage* showCamera = cvQueryFrame(m_camera); QImage *frame = IplImageToQImage(showCamera); ui->threshold_num->setNum(ui->threshold_bar->value()); *frame = func_Gray(*frame); if(ui->check_Threshold->isChecked()){ threshold = ui->threshold_bar->value(); }else{ threshold = Average_Threshold(*frame); } for(int h=0;h<frame->height();h++){ for(int w=0;w<frame->width();w++){ if(qRed(frame->pixel(w,h))<=threshold){ frame->setPixel(w,h,QColor(0,0,0).rgb()); }else{ frame->setPixel(w,h,QColor(255,255,255).rgb()); } } } ui->show_camera->setPixmap(QPixmap::fromImage(*frame)); }else if(ui->tabWidget->currentIndex()==1){ ros::NodeHandle n; image_transport::ImageTransport it(n); image_transport::Subscriber sub = it.subscribe("camera/image", 1, imageCallback); // sub1 = it1->subscribe("/camera/image",1,imageCallback); // sub_image = MatToQImage(cvframe); // ui->sub_label->setPixmap(QPixmap::fromImage(sub_image)); ros::spin(); killTimer(m_nTimerId); }else if(ui->tabWidget->currentIndex()==2){ cv::VideoCapture cap(201); cap>>cv00; cv::VideoCapture cap1(202); cap1>>cv01; // IplImage* showCamera = cvQueryFrame(m_camera); // QImage *camera2 = IplImageToQImage(showCamera); camera0 = MatToQImage(cv00); camera1 = MatToQImage(cv01); ui->camera01->setPixmap(QPixmap::fromImage(camera0)); ui->camera02->setPixmap(QPixmap::fromImage(camera1)); }
void Camera::captureImage() { qDebug("Camera::captureImage()"); if (!this->m_cameraCapture) return; QTime timer; timer.start(); IplImage *iplImage = cvQueryFrame(this->m_cameraCapture); uchar *data; QImage *qImg = IplImageToQImage(iplImage, &data); this->m_mainWindow->setCameraFrame(*qImg); this->m_mainWindow->setCaptureTime(timer.elapsed()); //qDebug("did in %i ms", timer.elapsed()); }
bool ImageViewer::saveAsMask(QString &pathMask) { if(_mask.empty()) return false; QFileDialog *fDlg = new QFileDialog(this); fDlg->setWindowTitle(tr("保存掩码")); fDlg->setAcceptMode(QFileDialog::AcceptSave); fDlg->setFileMode(QFileDialog::AnyFile); fDlg->setViewMode(QFileDialog::Detail); fDlg->setDirectory(QDir::currentPath()); fDlg->setFilter(MOLI_IMAGE_FILTER); fDlg->setDefaultSuffix("bmp"); if(fDlg->exec() == QDialog::Accepted) { QString filename = fDlg->selectedFiles()[0]; if(m_method == 0) { if(saveLabelMap(filename)) { pathMask = filename; return true; } else return false; } else { _mask = _mask * 255; IplImage* temp = new IplImage(_mask); QImage* temp2 = IplImageToQImage(temp); if(temp2->save(filename)) { pathMask = filename; if(temp2) delete temp2; return true; } else return false; } } else { return true; } }
bool ImageViewer::saveLabelMap(const QString &fileName, const char *fileFormat) { bool flag; for (int i = 0; i < _labelMapImage->height(); i++) { for (int j = 0; j < _labelMapImage->width(); j++) { flag = false; for (int k = 0; k < 10; k++) { QRgb rgb = qRgb(colorTable[3*k], colorTable[3*k+1], colorTable[3*k+2]); QRgb rgb1 = _labelMapImage->pixel(j, i); if (rgb == rgb1) { flag = true; } } if (!flag) { _labelMapImage->setPixel(j,i, qRgb(0, 0, 0)); } } } IplImage* temp = QImageToIplImage(*_labelMapImage); IplImage* scaled = cvCreateImage(cvSize(this->_orgWidth, this->_orgHeight), temp->depth, temp->nChannels); cvResize(temp, scaled, CV_INTER_CUBIC); QImage* temp2 = IplImageToQImage(scaled); bool ret = temp2->save(fileName, fileFormat); cvReleaseImage(&temp); cvReleaseImage(&scaled); if(temp2) delete temp2; return ret; }
void VideoDisplay::paintEvent(QPaintEvent *event) { QPainter p(this); if (!m_worker->m_pFrame) { QFont font; font.setPointSize(30); p.setFont(font); p.setPen(QPen(Qt::red, 4)); if (m_worker->m_IsCapturing) p.drawText(m_Config._config.frmWidth/2 - 100, m_Config._config.frmHeight /2 +5, "Connecting..."); else p.drawText(m_Config._config.frmWidth/2 - 80, m_Config._config.frmHeight /2 +5, "NO VIDEO"); return; } //qDebug()<<"Test"; if(qImageBuffer) delete qImageBuffer; if (_bufferFrame) _qImg = IplImageToQImage(_bufferFrame,0,255); if (_qImg) { QRect rect(0, 0, m_Config._config.frmWidth, m_Config._config.frmHeight); p.drawRect(rect); p.drawImage(rect,*_qImg,_qImg->rect()); QFont font; font.setPointSize(11); p.setFont(font); p.setPen(QPen(QColor(0,255,255), 2)); // for (int i = 1; i <= m_StringListView.count(); i++) // { // p.drawText(6, i*18, m_StringListView.at(i-1)); // } QString tmpStr ="Zoom : "; tmpStr += QString::number(m_Zoom/100.0f); tmpStr += "x"; p.drawText(6, 16,tmpStr); tmpStr ="Focus : "; tmpStr += QString::number(m_Focus); p.drawText(5, 34,tmpStr); tmpStr =QString::fromUtf8("Ph.vị : "); tmpStr += QString::number(m_Azi/100.0f); p.drawText(7, 52,tmpStr); tmpStr =QString::fromUtf8("Góc tà: "); tmpStr += QString::number(m_Ele/100.0f); p.drawText(5, 70,tmpStr); if (m_Writer) { p.setPen(QPen(Qt::red, 2)); p.drawText(m_Config._config.frmWidth - 85, 18, "Recording..."); } } if (!m_worker->m_IsTracking && !m_IsMouseOn) { //QRect rect1(m_Config._config.frmWidth / 2 - m_rectWidthInit / 2, m_Config._config.frmHeight / 2 - m_rectHeightInit / 2, m_rectWidthInit, m_rectHeightInit); p.setPen(QPen(Qt::red, 2)); //p.setBrush(QBrush(Qt::transparent)); p.drawLine(m_Config._config.frmWidth / 2 - m_rectWidthInit / 2, m_Config._config.frmHeight / 2 - m_rectHeightInit / 2, m_Config._config.frmWidth / 2 - m_rectWidthInit / 2 + 10, m_Config._config.frmHeight / 2 - m_rectHeightInit / 2); p.drawLine(m_Config._config.frmWidth / 2 - m_rectWidthInit / 2, m_Config._config.frmHeight / 2 - m_rectHeightInit / 2, m_Config._config.frmWidth / 2 - m_rectWidthInit / 2, m_Config._config.frmHeight / 2 - m_rectHeightInit / 2 + 10); p.drawLine(m_Config._config.frmWidth / 2 + m_rectWidthInit / 2, m_Config._config.frmHeight / 2 - m_rectHeightInit / 2, m_Config._config.frmWidth / 2 + m_rectWidthInit / 2 - 10, m_Config._config.frmHeight / 2 - m_rectHeightInit / 2); p.drawLine(m_Config._config.frmWidth / 2 + m_rectWidthInit / 2, m_Config._config.frmHeight / 2 - m_rectHeightInit / 2, m_Config._config.frmWidth / 2 + m_rectWidthInit / 2, m_Config._config.frmHeight / 2 - m_rectHeightInit / 2 + 10); p.drawLine(m_Config._config.frmWidth / 2 - m_rectWidthInit / 2, m_Config._config.frmHeight / 2 + m_rectHeightInit / 2, m_Config._config.frmWidth / 2 - m_rectWidthInit / 2 + 10, m_Config._config.frmHeight / 2 + m_rectHeightInit / 2); p.drawLine(m_Config._config.frmWidth / 2 - m_rectWidthInit / 2, m_Config._config.frmHeight / 2 + m_rectHeightInit / 2, m_Config._config.frmWidth / 2 - m_rectWidthInit / 2, m_Config._config.frmHeight / 2 + m_rectHeightInit / 2 - 10); p.drawLine(m_Config._config.frmWidth / 2 + m_rectWidthInit / 2, m_Config._config.frmHeight / 2 + m_rectHeightInit / 2, m_Config._config.frmWidth / 2 + m_rectWidthInit / 2 - 10, m_Config._config.frmHeight / 2 + m_rectHeightInit / 2); p.drawLine(m_Config._config.frmWidth / 2 + m_rectWidthInit / 2, m_Config._config.frmHeight / 2 + m_rectHeightInit / 2, m_Config._config.frmWidth / 2 + m_rectWidthInit / 2, m_Config._config.frmHeight / 2 + m_rectHeightInit / 2 - 10); } else if (_isSelecting) { p.setPen(QPen(Qt::red, 2)); p.setBrush(QBrush(Qt::transparent)); p.drawRect(_toBeTracked); } else if (m_worker->m_IsTracking) { if ((m_rectCurrent.top == 0) && (m_rectCurrent.bottom == 0)) m_rectCurrent = m_worker->m_rectCurrent; else { m_rectCurrent.top = (int)(0.3f*m_worker->m_rectCurrent.top + 0.7f*m_rectCurrent.top); m_rectCurrent.bottom = (int)(0.3f*m_worker->m_rectCurrent.bottom + 0.7f*m_rectCurrent.bottom); m_rectCurrent.left = (int)(0.3f*m_worker->m_rectCurrent.left + 0.7f*m_rectCurrent.left); m_rectCurrent.right = (int)(0.3f*m_worker->m_rectCurrent.right + 0.7f*m_rectCurrent.right); } p.setPen(QPen(QColor(0,255,0), 2)); QPoint lefttop[3] = { QPoint(m_rectCurrent.left, m_rectCurrent.top + 10), QPoint(m_rectCurrent.left, m_rectCurrent.top), QPoint(m_rectCurrent.left + 10, m_rectCurrent.top), }; QPoint righttop[3] = { QPoint(m_rectCurrent.right, m_rectCurrent.top + 10), QPoint(m_rectCurrent.right, m_rectCurrent.top), QPoint(m_rectCurrent.right - 10, m_rectCurrent.top), }; QPoint rightbottom[3] = { QPoint(m_rectCurrent.right, m_rectCurrent.bottom - 10), QPoint(m_rectCurrent.right, m_rectCurrent.bottom), QPoint(m_rectCurrent.right - 10, m_rectCurrent.bottom), }; QPoint leftbottom[3] = { QPoint(m_rectCurrent.left, m_rectCurrent.bottom - 10), QPoint(m_rectCurrent.left, m_rectCurrent.bottom), QPoint(m_rectCurrent.left + 10, m_rectCurrent.bottom), }; p.drawPolyline(lefttop, 3); p.drawPolyline(righttop, 3); p.drawPolyline(rightbottom, 3); p.drawPolyline(leftbottom, 3); } }
bool ImageViewer::openImage(const QString &fileName) { if ( !fileName.isEmpty() ) { deleteImage(); std::string sstr = fileName.toLocal8Bit().data(); IplImage* newImage = cvLoadImage( sstr.c_str(), 1 ); if ( !newImage ) { QMessageBox::warning( this, tr("提示"), tr("无法打开文件 %1.\n").arg(fileName), QMessageBox::Close); return false; } _orgWidth = newImage->width; _orgHeight = newImage->height; if (cv::max(newImage->width,newImage->height) > 800) { _scale = cv::max(newImage->width/600.0f, newImage->height/600.0f); _ocvImage = cvCreateImage(cvSize(newImage->width/_scale, newImage->height/_scale), 8, 3); cvResize(newImage,_ocvImage); } else if (newImage->width <= 250 || newImage->height <= 250) { _scale = cv::min(newImage->width/300.0f, newImage->height/300.0f); _ocvImage = cvCreateImage(cvSize(newImage->width/_scale,newImage->height/_scale),8,3); cvResize(newImage,_ocvImage); } else { _ocvImage = cvCreateImage(cvSize(newImage->width, newImage->height), 8, 3); cvCopy(newImage, _ocvImage); } if( !_srcOcvImage ) { _srcOcvImage = cvCreateImage(cvSize(_ocvImage->width, _ocvImage->height), _ocvImage->depth, _ocvImage->nChannels); cvCopy(_ocvImage, _srcOcvImage); } _srcWidth = _ocvImage->width; _srcHeight = _ocvImage->height; _labelMapImage = new QImage(_ocvImage->width, _ocvImage->height, QImage::Format_ARGB32); QImage _alphaImage(_ocvImage->width, _ocvImage->height, QImage::Format_Indexed8); _alphaImage.fill(255); _labelMapImage->setAlphaChannel(_alphaImage); _labelMapImage->fill(qRgb(0, 0, 0)); QImage *image = IplImageToQImage( _ocvImage ); setImage( *image ); DELETEPTR(image); if(CV_IS_IMAGE(newImage)) { cvReleaseImage(&newImage); newImage = 0; } } return true; }