(相关资料图)
形态学处理-morphologyEx 运算
void cv::morphologyEx(InputArray src,OutputArray dst,int op,InputArray Kernel,Point anchor=Point(-1,-1),int iteration=1,int borderType=BORDER_CONSTANT,const Scalar& borderValue=morphologyDefaultBorderValue())
这里面的op
op-操作类型,各种形态学运算的操作规则:将腐蚀和膨化进行结合得到
下面给出一个表
下面给出关于形态学的代码
void MainWindow::on_erode_triggered(){//定义形状int morph_elem=cv::MORPH_RECT;//定义大小int morph_size=3;//调用getStructuringElementcv::Mat element=cv::getStructuringElement(morph_elem,cv::Size(2*morph_size+1,2*morph_size+1),cv::Point(morph_size,morph_size));//调用morphologyEx函数cv::morphologyEx(srcImage,dstImage,cv::MORPH_ERODE,element);//显示img=QImage((const unsigned char*)(dstImage.data),dstImage.cols,dstImage.rows,dstImage.cols*dstImage.channels(),QImage::Format_RGB888);img=img.scaled(ui->label_2->size());ui->label_2->setPixmap(QPixmap::fromImage(img));}void MainWindow::on_dilate_triggered(){//定义形状int morph_elem=cv::MORPH_RECT;//定义大小int morph_size=3;//调用getStructuringElementcv::Mat element=cv::getStructuringElement(morph_elem,cv::Size(2*morph_size+1,2*morph_size+1),cv::Point(morph_size,morph_size));//调用morphologyEx函数cv::morphologyEx(srcImage,dstImage,cv::MORPH_DILATE,element);//显示img=QImage((const unsigned char*)(dstImage.data),dstImage.cols,dstImage.rows,dstImage.cols*dstImage.channels(),QImage::Format_RGB888);img=img.scaled(ui->label_2->size());ui->label_2->setPixmap(QPixmap::fromImage(img));}void MainWindow::on_open_triggered(){//定义形状int morph_elem=cv::MORPH_RECT;//定义大小int morph_size=3;//调用getStructuringElementcv::Mat element=cv::getStructuringElement(morph_elem,cv::Size(2*morph_size+1,2*morph_size+1),cv::Point(morph_size,morph_size));//调用morphologyEx函数cv::morphologyEx(srcImage,dstImage,cv::MORPH_OPEN,element);//显示img=QImage((const unsigned char*)(dstImage.data),dstImage.cols,dstImage.rows,dstImage.cols*dstImage.channels(),QImage::Format_RGB888);img=img.scaled(ui->label_2->size());ui->label_2->setPixmap(QPixmap::fromImage(img));}void MainWindow::on_close_triggered(){//定义形状int morph_elem=cv::MORPH_RECT;//定义大小int morph_size=3;//调用getStructuringElementcv::Mat element=cv::getStructuringElement(morph_elem,cv::Size(2*morph_size+1,2*morph_size+1),cv::Point(morph_size,morph_size));//调用morphologyEx函数cv::morphologyEx(srcImage,dstImage,cv::MORPH_CLOSE,element);//显示img=QImage((const unsigned char*)(dstImage.data),dstImage.cols,dstImage.rows,dstImage.cols*dstImage.channels(),QImage::Format_RGB888);img=img.scaled(ui->label_2->size());ui->label_2->setPixmap(QPixmap::fromImage(img));}void MainWindow::on_gradient_triggered(){//定义形状int morph_elem=cv::MORPH_RECT;//定义大小int morph_size=3;//调用getStructuringElementcv::Mat element=cv::getStructuringElement(morph_elem,cv::Size(2*morph_size+1,2*morph_size+1),cv::Point(morph_size,morph_size));//调用morphologyEx函数cv::morphologyEx(srcImage,dstImage,cv::MORPH_GRADIENT,element);//显示img=QImage((const unsigned char*)(dstImage.data),dstImage.cols,dstImage.rows,dstImage.cols*dstImage.channels(),QImage::Format_RGB888);img=img.scaled(ui->label_2->size());ui->label_2->setPixmap(QPixmap::fromImage(img));}void MainWindow::on_tophat_triggered(){//定义形状int morph_elem=cv::MORPH_RECT;//定义大小int morph_size=3;//调用getStructuringElementcv::Mat element=cv::getStructuringElement(morph_elem,cv::Size(2*morph_size+1,2*morph_size+1),cv::Point(morph_size,morph_size));//调用morphologyEx函数cv::morphologyEx(srcImage,dstImage,cv::MORPH_TOPHAT,element);//显示img=QImage((const unsigned char*)(dstImage.data),dstImage.cols,dstImage.rows,dstImage.cols*dstImage.channels(),QImage::Format_RGB888);img=img.scaled(ui->label_2->size());ui->label_2->setPixmap(QPixmap::fromImage(img));}void MainWindow::on_blackhat_triggered(){//定义形状int morph_elem=cv::MORPH_RECT;//定义大小int morph_size=3;//调用getStructuringElementcv::Mat element=cv::getStructuringElement(morph_elem,cv::Size(2*morph_size+1,2*morph_size+1),cv::Point(morph_size,morph_size));//调用morphologyEx函数cv::morphologyEx(srcImage,dstImage,cv::MORPH_BLACKHAT,element);//显示img=QImage((const unsigned char*)(dstImage.data),dstImage.cols,dstImage.rows,dstImage.cols*dstImage.channels(),QImage::Format_RGB888);img=img.scaled(ui->label_2->size());ui->label_2->setPixmap(QPixmap::fromImage(img));}
下面是程序运行
下面是开运算和形态学阶梯
【领 QT开发教程 学习资料, 点击下方链接莬费领取↓↓ ,先码住不迷路~】
点击这里:
关键词: