Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Opencv删除小斑点_Opencv_Abort_Blobs - Fatal编程技术网

使用Opencv删除小斑点

使用Opencv删除小斑点,opencv,abort,blobs,Opencv,Abort,Blobs,我正在VisualStudio2010上使用opencv2.2。我已经写了一个代码来为OCR预处理图像。我使用了很多轨迹条来改变参数。预处理功能之一是通过绘制轮廓并根据大小过滤掉小斑点来去除小斑点。但是,当我运行程序时,cvDrawContours函数给了我一个错误。基本上,我会弹出一个对话框,并且调用了一个错误R6010-abort。命令行显示在第641行的matrix.cpp中有一个未知的数组类型。我在这里包括我的代码。该问题由BlobFunc函数中的cvDrawContours函数调用 #

我正在VisualStudio2010上使用opencv2.2。我已经写了一个代码来为OCR预处理图像。我使用了很多轨迹条来改变参数。预处理功能之一是通过绘制轮廓并根据大小过滤掉小斑点来去除小斑点。但是,当我运行程序时,cvDrawContours函数给了我一个错误。基本上,我会弹出一个对话框,并且调用了一个错误R6010-abort。命令行显示在第641行的matrix.cpp中有一个未知的数组类型。我在这里包括我的代码。该问题由BlobFunc函数中的cvDrawContours函数调用

#include <C:\OpenCV2.2\modules\core\include\opencv2\core\core.hpp>  
#include <C:\OpenCV2.2\modules\highgui\include\opencv2\highgui\highgui.hpp>  
#include <iostream>  
#include <string.h>
#include <C:\OpenCV2.2\include\opencv\cv.h>  
#include <stdlib.h>
#include <C:\OpenCV2.2\modules\highgui\include\opencv2\highgui\highgui_c.h>
#include <C:\Users\Administrator\Documents\blobs\blob.h>
#include <C:\Users\Administrator\Documents\blobs\BlobResult.h>

using namespace cv;
using namespace std;

int MAX_KERNEL_LENGTH = 30;
int counter=0;
int Blurtype=0;
int Kern=5;
int *Kernp=&Kern;
int betaval=50;
int *betavalp=&betaval;
int Threshtype=0;
int Threshval=30;
int size=10;

Mat src1, src2, dst1, dst2, dst3;
CvScalar black=CV_RGB( 0, 0, 0 ); // black color
CvScalar white=CV_RGB( 255, 255, 255 );   // white color
double area;

void BlobFunc(int,void*);
int main( int argc, char** argv )
{
    //Read Input
    src1 = imread(argv[1]);
    if( !src1.data ) { printf("Error loading src1 \n"); return -1; }
    //Create Windows
    namedWindow("Original Image",1);
    namedWindow("Binarized Image",1);
    namedWindow("Gray Image",1);
    namedWindow("Sharpened Image",1);
    namedWindow("Blurred Image",1);
    imshow("Original Image",src1);
    namedWindow("Blobs",1);
    //Create Trackbars
    cvtColor(src1,src2,CV_RGB2GRAY);
    imshow("Gray Image",src2);
    threshold( src2, dst1, Threshval, 255,Threshtype);
    imshow("Binarized Image",dst1);
    createTrackbar("Kernel","Blurred Image",&Kern,MAX_KERNEL_LENGTH,BlobFunc); 
    createTrackbar("BlurType","Blurred Image",&Blurtype,3,BlobFunc); 
    createTrackbar("Betaval","Sharpened Image",&betaval,100,BlobFunc);
    createTrackbar("Threshold value","Binarized Image",&Threshval,255,BlobFunc);
    createTrackbar("Type","Binarized Image",&Threshtype,4,BlobFunc);
    createTrackbar("Size","Blobs",&size,100,BlobFunc); //Size of Blob
    waitKey(0);
    return 0;
}

void BlobFunc(int,void*)
{
    CvMemStorage *storage=cvCreateMemStorage(0);
    CvSeq *contours=0;
    cvtColor(src1,src2,CV_RGB2GRAY);
    imshow("Gray Image",src2);
    threshold( src2, dst1, Threshval, 255,Threshtype);
    imshow("Binarized Image",dst1);
    for ( int i = 1; i < Kern; i = i + 2 )
    {
        if (Blurtype==0)
        {
            blur(dst1,dst2, Size( i, i ), Point(-1,-1) );
        }
    else if (Blurtype==1)
        {
            GaussianBlur( dst1, dst2, Size( i, i ), 0, 0 );
        }
    else if (Blurtype==2)
        {
            medianBlur ( dst1, dst2, i );
        }
    else if (Blurtype==3)
        {
            bilateralFilter ( dst1, dst2, i, i*2, i/2 );
        }       
    }
    imshow("Blurred Image",dst2);
    addWeighted( dst1, 1, dst2, -double(betaval)/100, 0.0, dst3);
    imshow("Sharpened Image",dst3);
    IplImage img=dst3;
    cvFindContours(&img,storage,&contours,sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);                                                      
    IplImage *img_out=cvCreateImage( cvGetSize(&img), 8, 3 );
    cvZero( &img_out );
    for( ; contours != 0; contours = contours->h_next )
    {
     cvDrawContours( &img_out, contours, black, black, -1, CV_FILLED, 8 );
    }

    Mat imgout=img_out;
    cvReleaseMemStorage( &storage );
    imshow("Blobs",imgout);
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间cv;
使用名称空间std;
int MAX_KERNEL_LENGTH=30;
int计数器=0;
int模糊类型=0;
int-Kern=5;
int*Kernp=&Kern;
int-betaval=50;
int*betaval=&betaval;
int Threshtype=0;
int Threshval=30;
int size=10;
材料src1、src2、dst1、dst2、dst3;
CvScalar black=CV_RGB(0,0,0);//黑色
CvScalar white=CV_RGB(255,255,255);//白色
双区;
void BlobFunc(int,void*);
int main(int argc,字符**argv)
{
//读取输入
src1=imread(argv[1]);
如果(!src1.data){printf(“加载src1\n时出错”);返回-1;}
//创建窗口
namedWindow(“原始图像”,1);
namedWindow(“二值化图像”,1);
namedWindow(“灰色图像”,1);
namedWindow(“锐化图像”,1);
namedWindow(“模糊图像”,1);
imshow(“原始图像”,src1);
namedWindow(“Blobs”,1);
//创建轨迹栏
CVT颜色(src1、src2、CV_rgb2灰色);
imshow(“灰度图像”,src2);
阈值(src2、dst1、Threshval、255、Threshtype);
imshow(“二值化图像”,dst1);
createTrackbar(“内核”、“模糊图像”和内核,最大内核长度,BlobFunc);
createTrackbar(“BlurType”、“模糊图像”和BlurType,3,BlobFunc);
createTrackbar(“Betaval”、“锐化图像”和Betaval,100,BlobFunc);
createTrackbar(“阈值”、“二值化图像”、&Threshval,255,BlobFunc);
createTrackbar(“类型”、“二值化图像”和阈值类型,4,BlobFunc);
createTrackbar(“大小”、“Blob”、&Size,100,BlobFunc);//Blob的大小
等待键(0);
返回0;
}
void BlobFunc(int,void*)
{
CvMemStorage*storage=cvCreateMemStorage(0);
CvSeq*等高线=0;
CVT颜色(src1、src2、CV_rgb2灰色);
imshow(“灰度图像”,src2);
阈值(src2、dst1、Threshval、255、Threshtype);
imshow(“二值化图像”,dst1);
对于(int i=1;ih_下一步)
{
cvDrawContours(&img_out,contours,黑色,黑色,-1,CV_填充,8);
}
Mat imgout=img_out;
cvReleaseMemStorage(&storage);
imshow(“Blobs”,imgout);
}

当我传递无效的Mat(或iplimage)时,我会遇到这种类型的错误。我可能复制不正确,或者图像可能是一种类型、通道、颜色数量等

问题似乎在于参数不正确,因此我将查看您在图像中的传递方式,即,您可以在不使用&的情况下尝试img而不是&img。恐怕我不熟悉C++,但这就是我要开始的地方。 下面的示例与此类似,可能有助于展示&和*

void displayContours(const Mat &src, Mat features) {
    RNG rng(12345);
    Mat canny_output;
    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;
    Mat s;
    src.copyTo(s);
    findContours(s, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));

    /// Approximate contours to polygons + get bounding rects and circles
    vector<vector<Point> > contours_poly(contours.size());
    vector<Rect> boundRect(contours.size());
    vector<Point2f> center(contours.size());
    vector<float> radius(contours.size());

    for (int i = 0; i < contours.size(); i++) {
        approxPolyDP(Mat(contours[i]), contours_poly[i], 3, true);
        boundRect[i] = boundingRect(Mat(contours_poly[i]));
        minEnclosingCircle(contours_poly[i], center[i], radius[i]);
    }

    /// Draw polygonal contour + bonding rects + circles
    for (int i = 0; i < contours.size(); i++) {
        Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255),
                rng.uniform(0, 255));
        drawContours(features, contours_poly, i, color, 1, 8, vector<Vec4i>(),
                0, Point());
        rectangle(features, boundRect[i].tl(), boundRect[i].br(), color, 2, 8,
                0);
        circle(features, center[i], (int) radius[i], color, 2, 8, 0);
    }

}
void显示轮廓(常数Mat和src,Mat特征){
RNG RNG(12345);
Mat-canny_输出;
矢量等值线;
向量层次;
垫子;
src.copyTo(s);
查找轮廓(s、等高线、层次、CV_RETR_树、CV_链_近似_简单、点(0,0));
///将轮廓近似为多边形+获取边界矩形和圆
向量等高线_多边形(等高线.size());
向量boundRect(contours.size());
向量中心(contours.size());
向量半径(等高线.size());
对于(int i=0;i

这是opencv教程中的一篇,它使用Mat而不是iplImage,这可能需要不同的用法。

当我传递无效的Mat(或iplImage)时,我会遇到这种类型的错误。我可能复制不正确,或者图像可能是一种类型、通道、颜色数量等

问题似乎在于参数不正确,因此我将查看您在图像中的传递方式,即,您可以在不使用&的情况下尝试img而不是&img。恐怕我不熟悉C++,但这就是我要开始的地方。 下面的示例与此类似,可能有助于展示&和*

void displayContours(const Mat &src, Mat features) {
    RNG rng(12345);
    Mat canny_output;
    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;
    Mat s;
    src.copyTo(s);
    findContours(s, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));

    /// Approximate contours to polygons + get bounding rects and circles
    vector<vector<Point> > contours_poly(contours.size());
    vector<Rect> boundRect(contours.size());
    vector<Point2f> center(contours.size());
    vector<float> radius(contours.size());

    for (int i = 0; i < contours.size(); i++) {
        approxPolyDP(Mat(contours[i]), contours_poly[i], 3, true);
        boundRect[i] = boundingRect(Mat(contours_poly[i]));
        minEnclosingCircle(contours_poly[i], center[i], radius[i]);
    }

    /// Draw polygonal contour + bonding rects + circles
    for (int i = 0; i < contours.size(); i++) {
        Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255),
                rng.uniform(0, 255));
        drawContours(features, contours_poly, i, color, 1, 8, vector<Vec4i>(),
                0, Point());
        rectangle(features, boundRect[i].tl(), boundRect[i].br(), color, 2, 8,
                0);
        circle(features, center[i], (int) radius[i], color, 2, 8, 0);
    }

}
void-displayContours(施工材料和src、材料fe