Visual Studio 2010에서 opencv2.2를 사용하고 있습니다. OCR 용 이미지를 사전 처리하는 코드를 작성했습니다. 매개 변수를 변경하기 위해 많은 트랙 바를 사용하고 있습니다. 전처리 기능 중 하나는 윤곽선을 그리고 크기에 따라 필터링하여 작은 얼룩을 제거하는 것입니다. 그러나 프로그램을 실행할 때 cvDrawContours 함수에서 오류가 발생합니다. 기본적으로 나는 popup과 R6010 -abort가 호출되었다는 에러를 얻는다. 커맨드 라인은 641 행의 matrix.cpp에 알려지지 않은 배열 타입이 있다고 말한다. 여기에 내 코드를 포함하고있다. 이 문제는 BlobFunc 함수 내에서 cvDrawContours 함수에 의해 호출됩니다.Openbv를 사용하여 작은 얼룩 제거
#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);
}