OpenCV去除边缘斑点
OpenCV remove the edge spots?
我尝试使用以下代码去除斑点,右上角边缘的斑点,一直无法去除,该怎么办?
CvContourScanner scanner = NULL; scanner = cvStartFindContours(img_src,storage,sizeof(CvContour),CV_RETR_CCOMP,CV_CHAIN_APPROX_NONE,cvPoint(0,0));
CvRect rect;
while (contour=cvFindNextContour(scanner))
{
tmparea = fabs(cvContourArea(contour));
rect = cvBoundingRect(contour,0);
if (tmparea < minarea/*||tmparea>4900*/)
{
pp=(uchar*)(img_Clone->imageData + img_Clone->widthStep*(rect.y+rect.height/2)+rect.x+rect.width/2);
if (pp[0]==0)
{
for(int y = rect.y;y<rect.y+rect.height;y++)
{
for(int x =rect.x;x<rect.x+rect.width;x++)
{
pp=(uchar*)(img_Clone->imageData + img_Clone->widthStep*y+x);
if (pp[0]==0)
{
pp[0]=255;
}
}
}
}
}
}
代码
:
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <vector>
#include <algorithm>
# include <stdio.h>
# include <math.h>
#include <cv.h>
void main()
{
cv::Mat threshold_output;
IplImage* img_src;
CvSeq* contour = NULL;
double minarea = 100.0;
double tmparea = 0.0;
CvMemStorage* storage = cvCreateMemStorage(0);
IplImage* img_temp= cvLoadImage("C:\temp\original.bmp",CV_LOAD_IMAGE_GRAYSCALE);
cvErode(img_temp, img_temp, 0, 1);
threshold(cv::cvarrToMat(img_temp), threshold_output, 200,255, THRESH_BINARY );
img_src=&IplImage(threshold_output);
IplImage* img_Clone=cvCloneImage(img_src);
uchar *pp;
IplImage* img_dst = cvCreateImage(cvGetSize(img_src),IPL_DEPTH_8U,1);
CvScalar color = cvScalar(255,0,0);//CV_RGB(128,0,0);
CvContourScanner scanner = NULL;
scanner = cvStartFindContours(img_src,storage,sizeof(CvContour),CV_RETR_CCOMP,CV_CHAIN_APPROX_NONE,cvPoint(0,0));
CvRect rect;
while (contour=cvFindNextContour(scanner))
{
tmparea = fabs(cvContourArea(contour));
rect = cvBoundingRect(contour,0);
if (tmparea < minarea/*||tmparea>4900*/)
{
pp=(uchar*)(img_Clone->imageData + img_Clone->widthStep*(rect.y+rect.height/2)+rect.x+rect.width/2);
if (pp[0]==0)
{
for(int y = rect.y;y<rect.y+rect.height;y++)
{
for(int x =rect.x;x<rect.x+rect.width;x++)
{
pp=(uchar*)(img_Clone->imageData + img_Clone->widthStep*y+x);
if (pp[0]==0)
{
pp[0]=255;
}
}
}
}
}
}
cvSaveImage("c://temp//result.bmp",img_Clone);
}
相关文章:
- 如何获取边缘窗口句柄 (HWND)?
- 提升如何在图形可视化中写入边缘的权重?
- 在 c++ 中使用 Tensorflow Lite 在边缘 TPU 上运行"mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite"时出现问题
- 分数背包边缘箱
- 应用程序无法找到铬边缘浏览器
- openCV C++将对象/斑点简化为质心
- SFML C++ Canny边缘检测双刃
- 难以使球从屏幕边缘反弹
- 我的精灵使用名为 ASGE 的C++框架卡在屏幕边缘
- 无法在 vtk 中重新着色边缘
- 如何使用提升make_label_writer写入边缘属性?
- 使用 epoll 边缘触发器的套接字上的数据过多
- 迭代提升反向图中的边缘
- 如何在提升图中访问边缘信息?
- Microsoft具有本机消息传递和非持久连接的边缘扩展不起作用
- 使用 opencv 提取最大的斑点
- 有没有一种方法可以使用弗洛伊德-沃歇尔算法给出最短路径,其中存在负权重循环而不允许重叠边缘?
- 如何在网格查看器上的选择性表面内删除边缘
- 删除存储为邻接列表的图表中的边缘
- OpenCV去除边缘斑点