subokita / Robust-Text-Detection

Robust Text Detection implementation based on http://www.stanford.edu/~hchen2/papers/ICIP2011_RobustTextDetection.pdf
MIT License
157 stars 80 forks source link

Error when building #1

Open pxuanqui opened 10 years ago

pxuanqui commented 10 years ago

When debug to this function, it shows the error "Access violation reading location 0xCDCDCDD1" Mat RobustTextDetection::createMSERMask(Mat& grey) { /* Find MSER components */ vector<vector> contours; MSER mser(8, param.minMSERArea, param.maxMSERArea, 0.25, 0.1, 100, 1.01, 0.03, 5); mser(grey, contours);

/* Create a binary mask out of the MSER */
Mat mser_mask(grey.size(), CV_8UC1, Scalar(0));

for (size_t i = 0; i < contours.size(); i++) {
    for (Point& point : contours[i])
        mser_mask.at<uchar>(point) = 255;
}

return mser_mask;

}

subokita commented 10 years ago

Hi pxuanqui, can I have 3 things before I can debug this issue?

I'm not sure what's the issue (it's still working on mine) ...

MSER mser( 8, param.minMSERArea, param.maxMSERArea, 0.25, 0.1, 100, 1.01, 0.03, 5 );
mser(grey, contours);

but if those two lines are the cause of the error, then I hate to tell you that, those are the APIs from OpenCV. But again, if you're okay with it, please supply me those 3 things so that I can debug it.

For your information, this example uses OpenCV 2.4.9 and Tesseract 3.02.

pxuanqui commented 10 years ago

I use your TestText.png and the same parameters, I don't modify anything I also use OpenCV 2.4.9 and Tesseract 3.02 and Visual Studio 2013 Here the project I build, BTW, I also get the error "unresolved external symbol _cvFontQt referenced in function _main" https://www.dropbox.com/s/1py0k7x28zaz6k0/textDetection.zip Thank you !!!

subokita commented 10 years ago

Hmmm, I don't have a Visual Studio, I only have a Macbook here, so there are things that I can't do.

First, here's some of the information about my build of OpenCV from home-brew (a package installer in mac)

Required: jpeg ✔, libpng ✘, libtiff ✔
Optional: eigen ✔, jasper ✔, openexr ✔, openni ✘, qt ✔, tbb ✘, ffmpeg ✘

I don't think you need eigen, jasper, or openexr. But the example were compiled with QT functionalities for printing out the text, so you might want to comment the part out.

Second, I wrote a small test function to help me localise the issue, please try this updated main.cpp file: https://www.dropbox.com/s/5pt941ulbp388vh/main.cpp If it's okay it should print out "Everything is okay!", else it should throw a runtime error with specified message. If it's not one of the messages, then it's highly probably it might be related to OpenCV instead of the logic of the code.

Third, I'd presume that your OpenCV weren't built with QT support, so you might want to comment out

    /* And draw them on screen */
    CvFont font = cvFontQt("Helvetica", 24.0, CV_RGB(0, 0, 0) );
    Point coord = Point( result.second.br().x + 10, result.second.tl().y );
    for( string& line: splitted ) {
        addText( image, line, coord, font );
        coord.y += 25;
    }
    rectangle( image, result.second, Scalar(0, 0, 255), 2);

And print out the detected text from splitted to console instead.

Please update me about the progress, I'm apologise for the inconveniences.

pxuanqui commented 10 years ago

Now I can build your original project, with the tested image TestText.png, it work well. But when I try to use another image, it doesn't work, for example the following image, it shows an exception scenetext01

subokita commented 10 years ago

First is that I updated RobustTextDetection to have a check on the resulting detected region, to avoid exception

Second, sadly for your example, you require to increase your max connected component count param.maxConnCompCount to 4000 (or just increase till it doesn't complain about it),

And finally, although it will run now, the result will be way off, and you might need to start with parameter tuning to get the desired result.

ghost commented 9 years ago

image

Now I can build your original project, with the tested image TestText.png, it work well. But when I try to use another image, it doesn't work, for example the following image, it shows an exception

subokita commented 9 years ago

Sadly the application is very fragile, you might need to tweak the parameters a bit when it comes to new images. It's not meant to be a library, it's supposed to be a sample test case on how it works.

ghost commented 9 years ago

Hmmm,thanks,i am a student who study your paper ,so can you tell something about how to tweak the parameters a bit when it comes to new images.thank you, i need some help about this,thank you very much

image

subokita commented 9 years ago

Well, I'm not the one who wrote the paper... Anyway, if I still recall correctly, here are some of the explanations of the parameters:

param.minMSERArea        = 10;
param.maxMSERArea        = 400;

These are the range of the detected MSER area, for detected regions that are outside of those number of pixels (10 - 400 pixels), it's discarded

param.cannyThresh1       = 30;
param.cannyThresh2       = 100;

Parameters for canny edge detection

param.maxConnCompCount   = 3000;
param.minConnCompArea    = 35;
param.maxConnCompArea    = 300;

These are for connected components. Similar to the MSER params above, any connected component above or below the range, will be discarded

param.minEccentricity    = 0.4;
param.maxEccentricity    = 0.995;
param.minSolidity        = 0.2;
param.maxStdDevMeanRatio = 0.5;

The final 4 params, are bit confusing, even for me. Basically it defines whether the detected region is a blob, or twisted, it's solid, and how spread out it is. You might want to play a bit around it, to see how it affects the detection of letters like 'I' or 'S', etc.

ghost commented 9 years ago

oh! ! !thank you very much,i can run it now thank you !!

HerShawn commented 9 years ago

Hello,subokia! I use opencv 2.4.10 for windows(without QT support i guess,so i just replace cvFontQT with fontQT and i don't know wether it works or not),Tesseract 3.02 and Visual Studio 2013. I debuged it for several days but failed in the end. I wonder if thise code could only run at Mac? Did you have a "windows version"? (Sorry,I'm not good at speeking english. But i want to say: you are a nice person!)

HerShawn commented 9 years ago

1

subokita commented 9 years ago

Hi HerShawn, sadly I don't really know what's the main issue when running on Windows (I don't own a Windows PC, sadly).

Anyway, maybe try to comment out the QT part first, and see if that's the issue, sometimes I think it's more of the incompatible library, but maybe not in this case. Below is the snippet of the last few chunk of codes on the main method, just comment out the QT font part.

/* And draw them on screen */
//CvFont font = cvFontQt("Helvetica", 24.0, CV_RGB(0, 0, 0) );
//Point coord = Point( result.second.br().x + 10, result.second.tl().y );
for( string& line: splitted ) {
    //addText( image, line, coord, font );
    //coord.y += 25;

    cout << line << endl;
}

rectangle( image, result.second, Scalar(0, 0, 255), 2);

/* Append the original and stroke width images together */
cvtColor( stroke_width, stroke_width, CV_GRAY2BGR );
Mat appended( image.rows, image.cols + stroke_width.cols, CV_8UC3 );
image.copyTo( Mat(appended, Rect(0, 0, image.cols, image.rows)) );
stroke_width.copyTo( Mat(appended, Rect(image.cols, 0, stroke_width.cols, stroke_width.rows)) );

resize(appended, appended, Size(), 0.5f, 0.5f );

imshow("", appended );
waitKey();

I doubt that commenting QT would resolve the issue, but please keep me updated. 我觉得,你的英语相当不错. 向反来讲,我的华语是蛮差

HerShawn commented 9 years ago

Thank you very much,Saburo Okita! I really think you are passionate, Sincerely and kind(说实话,我虽然考到了英语6级,但是我的 真实水平也只是能读懂英语的程度;我并不擅长英语写作) I‘ll try to solve this problem by following your instructions. Thanks a lot for your concern and efforts!

HerShawn commented 9 years ago

Hi,brother:

  Thanks a lot! Finally i worked it out with your help. Now these code could use

in windows. So i send them to you . Good night!

                                                                           best wishes

------------------ 原始邮件 ------------------ 发件人: "Saburo Okita";notifications@github.com; 发送时间: 2015年4月11日(星期六) 凌晨0:04 收件人: "subokita/Robust-Text-Detection"Robust-Text-Detection@noreply.github.com; 抄送: "贺翔"hexiangman@qq.com; 主题: Re: [Robust-Text-Detection] Error when building (#1)

Hi HerShawn, sadly I don't really know what's the main issue when running on Windows (I don't own a Windows PC, sadly).

Anyway, maybe try to comment out the QT part first, and see if that's the issue, sometimes I think it's more of the incompatible library, but maybe not in this case. Below is the snippet of the last few chunk of codes on the main method, just comment out the QT font part. /* And draw them on screen _/ //CvFont font = cvFontQt("Helvetica", 24.0, CVRGB(0, 0, 0) ); //Point coord = Point( result.second.br().x + 10, result.second.tl().y ); for( string& line: splitted ) { //addText( image, line, coord, font ); //coord.y += 25; cout << line << endl; } rectangle( image, result.second, Scalar(0, 0, 255), 2); / Append the original and stroke width images together */ cvtColor( stroke_width, stroke_width, CV_GRAY2BGR ); Mat appended( image.rows, image.cols + stroke_width.cols, CV_8UC3 ); image.copyTo( Mat(appended, Rect(0, 0, image.cols, image.rows)) ); stroke_width.copyTo( Mat(appended, Rect(image.cols, 0, stroke_width.cols, stroke_width.rows)) ); resize(appended, appended, Size(), 0.5f, 0.5f ); imshow("", appended ); waitKey();
I doubt that commenting QT would resolve the issue, but please keep me updated. 我觉得,你的英语相当不错. 向反来讲,我的华语是蛮差

— Reply to this email directly or view it on GitHub.

subokita commented 9 years ago

Great! Have fun with it!

ctouffet commented 9 years ago

Hi Subokita,

I have an error when building with g++ (-std=gnu++11) :

/usr/include/c++/4.8/bits/stl_algo.h:2263:35: error: no match for call to ‘(ConnectedComponent::apply(const cv::Mat&)::lambda0) (ComponentProperty&, const ComponentProperty&)’ while (comp(*first, pivot)) ^ ConnectedComponent.cpp:156:51: note: candidates are: sort( properties.begin(), properties.end(), [=](ComponentProperty& a, ComponentProperty& b){

Do you know what it could be?

Thanks in advance!

swingfox commented 8 years ago

Hello Subokita,

In what line of code will I insert the bounding box part found on part 4 MATLAB implementation?

Thanks :)

subokita commented 8 years ago

@swingfox Should be starting around line 123 in RobustTextDetection.cpp

yunzhongzhuhuo commented 8 years ago

@ctouffet
Do you solve the error.I have the same problem.Can you help me? Thanks.

mynameischaos commented 8 years ago

Hello, when I compile the project, I get the error: variable type 'cv::MSER' is an abstract class.
Opencv version: 2.4.13 tesseract version: 3.04 But can't run.

subokita commented 8 years ago

@mynameischaos Sadly I haven't touched this project for 2 years.

Based on the documentation, it shouldn't be abstract, but I no longer know what's the issue. http://docs.opencv.org/2.4/modules/features2d/doc/feature_detection_and_description.html

Basically in the createMSERMask() it should call opencv's MSER method

MSER mser( 8, param.minMSERArea, param.maxMSERArea, 0.25, 0.1, 100, 1.01, 0.03, 5 );
mser(grey, contours);

Maybe the version of OpenCV I used were too old, just update it to newest opencv code that apply MSER to the greyscale image.

mynameischaos commented 8 years ago

@subokita Oh,no. Because of the version, based on the documentation of version 3.1.0, now it's abstract class.