Page 9 of 60
Re: PureBasic Interface to OpenCV
Posted: Sat Jan 18, 2014 1:16 am
by JHPJHP
Hi Philippe-felixer76-3,
Thanks for the kudos - it's nice to know the work is appreciated. I look forward to seeing your OCR example working with AAT's license plate recognition script.
-----------------------------------
Updated:
- added Constants, Structures, Macros, Functions, 1 Inline Function (converted to a Procedure)
- added 1 example
-- cv_histogram.pb: calculates a histogram for the Red, Green, and Blue channels of an image
Original source can be found
here.
-----------------------------------
Updated:
- added 1 example
-- cv_overlay.pb: calculates the weighted sum of two arrays, demonstrating this by overlaying two images and setting a degree of transparency on the second image
- updated 1 example
-- cv_histogram.pb: added optional transparency and a preview image
The cv_overlay.pb example came about because I wanted to add transparency to the histogram example, but found out that the OpenCV Drawing Functions don't support the alpha channel.
Re: PureBasic Interface to OpenCV
Posted: Sat Jan 18, 2014 9:55 am
by JHPJHP
Updated:
- added Functions
- added 2 examples
-- cv_warp_1.pb: calculates an affine transform from three pairs of the corresponding points
-- cv_warp_2.pb: calculates a perspective transform from four pairs of the corresponding points
Original source can be found
here.
Re: PureBasic Interface to OpenCV
Posted: Sat Jan 18, 2014 11:57 am
by falsam
Hey stop!. Drink coffee and gives us time to test your excellent work.

Re: PureBasic Interface to OpenCV
Posted: Sat Jan 18, 2014 1:37 pm
by applePi
thanks JHPJHP for the great work.
Re: PureBasic Interface to OpenCV
Posted: Sat Jan 18, 2014 11:28 pm
by Philippe-felixer76-3
JHPJHP wrote:Updated:
- added Functions
- added 2 examples
-- cv_warp_1.pb: calculates an affine transform from three pairs of the corresponding points
-- cv_warp_2.pb: calculates a perspective transform from four pairs of the corresponding points
Original source can be found
here.
You already are cool, stop this man, i can't think of a even better term for you..
Super super super...
Re: PureBasic Interface to OpenCV
Posted: Sun Jan 19, 2014 2:50 am
by AAT
Philippe-felixer76-3 wrote:...,stop this man...
No, no! Continue, please!

Re: PureBasic Interface to OpenCV
Posted: Sun Jan 19, 2014 10:15 am
by JHPJHP
Hi falsam,
... Drink coffee - too funny; I've been told more then once that I should own shares in "Second Cup" because of how much I drink.
-------------------------------
Hi applePi,
Thank you for your comments, they're appreciated.
-------------------------------
Hi Philippe-felixer76-3,
Thank you for the kind words, it's nice to know you're enjoying the examples.
-------------------------------
Hi AAT,
I still have a few things I want to accomplish with OpenCV, so for the next little bit the work will continue.
Thank you for the support.
Re: PureBasic Interface to OpenCV
Posted: Sun Jan 19, 2014 10:12 pm
by Philippe-felixer76-3
License number OCR example:
https://www.dropbox.com/s/ij8pe8k5wacfj ... OCR_PB.zip
Screenshot:
https://www.dropbox.com/s/qte3sf8c80jrr ... .51.55.png
A few things:
- OCR config is based on dutch license number ttf font for now
- RGBFilter value is image specific to get good results, i hoped to get one value for all images
- It's beta!
Just copy the files to your PB OpenCV example drawer.
The TTF to OCR cfg converter/editor wil follow asap, it works well but not when i compile it as executable, very strange.
Re: PureBasic Interface to OpenCV
Posted: Mon Jan 20, 2014 12:47 am
by JHPJHP
Hi Philippe-felixer76-3,
The "License Plate Recognition" script is really coming together, my compliments to you and AAT. I've taken the liberty to add the link to a new section I created in the
first post titled: Projects, as this has the potential to move well beyond the example stage.
Keep up the great work!
Re: PureBasic Interface to OpenCV
Posted: Mon Jan 20, 2014 12:48 pm
by AAT
Hi, Philippe-felixer76-3
My congratulations to you, it works! Not all license plates recognized properly, but I think it's because of the difference in standards.
Waiting for beta2
Good luck!
Re: PureBasic Interface to OpenCV
Posted: Mon Jan 20, 2014 7:26 pm
by Philippe-felixer76-3
JHPJHP wrote:Hi Philippe-felixer76-3,
The "License Plate Recognition" script is really coming together, my compliments to you and AAT. I've taken the liberty to add the link to a new section I created in the
first post titled: Projects, as this has the potential to move well beyond the example stage.
Keep up the great work!
Cool man, you keep it up too!
Re: PureBasic Interface to OpenCV
Posted: Mon Jan 20, 2014 7:34 pm
by Philippe-felixer76-3
AAT wrote:Hi, Philippe-felixer76-3
My congratulations to you, it works! Not all license plates recognized properly, but I think it's because of the difference in standards.
Waiting for beta2
Good luck!
Tnx AAT, but you did a lot of good work also!
There are a lot of things to tweak, and the OCR detail used in the provided config file is not that high. So adding more fonts to the OCR and increasing the detail will give general better results.
The real problem is (if you ask me) determing how to threshold black/white the right way on any image, a image taken in the rain or taken in the evening or etc etc..
We must use the power of OpenCV more to obtain the characters from a number plate, look at this for example:
https://opencv-code.com/tutorials/how-t ... ratchcard/
Re: PureBasic Interface to OpenCV
Posted: Tue Jan 21, 2014 11:48 am
by AAT
Hi, Philippe-felixer76-3.
The quote from the chapter 5 of the book "Mastering OpenCV with Practical Computer Vision Projects" from which I took algorithm of processing:
"The best results in an automatic number plate recognition (ANPR) system can be obtained with an infrared (IR) camera, because the segmentation steps for detection and OCR segmentation are easy, clean, and minimize errors...
The majority of number plates have a special characteristic named retro-reflection—the surface of the plate is made with a material that is covered with thousands of tiny hemispheres that cause light to be reflected back to the source...
If we use a camera with a filter coupled with a structured infrared light projector, we can retrieve just the infrared light and then we have a very high-quality image to segment and subsequently detect, and recognize the plate number that is independent of any light environment"
Therefore, rain, dust, day/evening light will not affect to the recognition in the real (not training) program in real ANPR system.
The real problem is (if you ask me) determing how to threshold black/white the right way on any image
Yes, it is always the real problem. Perhaps it will be useful to try to set the threshold to each symbol separately.
Yes, "Tesseract" is really powerful OCR. Some years ago i have compared "Fine Reader", "Cunei Form" and "Tesseract". "Tesseract" had the best results with my samples
Re: PureBasic Interface to OpenCV
Posted: Tue Jan 21, 2014 8:46 pm
by Philippe-felixer76-3
AAT wrote:Hi, Philippe-felixer76-3...
The real problem is (if you ask me) determing how to threshold black/white the right way on any image
Yes, it is always the real problem. Perhaps it will be useful to try to set the threshold to each symbol separately.
Think i solved this problem more or less by using THRESH_OTSU.
http://docs.opencv.org/modules/imgproc/ ... #threshold
Also, the special value THRESH_OTSU may be combined with one of the above values. In this case, the function determines the optimal threshold value using the Otsu’s algorithm and uses it instead of the specified thresh .
Yes, "Tesseract" is really powerful OCR. Some years ago i have compared "Fine Reader", "Cunei Form" and "Tesseract". "Tesseract" had the best results with my samples
Well the english data of Tesseract is very HUGE compaired to what i use now, so i think i can add some more detail in my OCR and add a english number plate font also. That would make it a lot more accurate.
Threshold now done by OpenCV only.. Works a lot better now. replace part of the code in example with below..
Code: Select all
; color to gray
*gray.IplImage = cvCreateImage(*img_crop\width, *img_crop\height, #IPL_DEPTH_8U, 1)
cvCvtColor(*img_crop, *gray, #CV_BGR2GRAY, 1)
; otsu only 8 bit
cvThreshold(*gray, *gray, 240, 255, #CV_THRESH_BINARY | #CV_THRESH_OTSU)
; show image (debug)
cvShowImage("img_crop111111", *gray)
; back to color
cvCvtColor(*gray, *img_crop, #CV_GRAY2BGR, 3)
; Load OCR data
loadOCRfile(prog\ocrfile )
; Convert CV image to PB image...
pbimage = cvimage2pbimage(*img_crop)
; Set minimum size for rects
msize.rects
msize\x = 0
msize\y = 0
msize\w = 10
msize\h = 8
; Scan: find rects
scan(pbimage, 0, 0, 0, 0, msize)
; OCR image
Debug Image2Text_OCR(pbimage, 50, prog\ocrwidth, prog\ocrheight)
You can see that function scan() now only scans for groups and lines, border, B&W, Threshold and rgbfilet are disabled.
I discovered there's a strange thing going on with images 111.* with displaying them suddenly... hmmm.
https://www.dropbox.com/s/04l5gi0h766fq ... trange.png
Re: PureBasic Interface to OpenCV
Posted: Wed Jan 22, 2014 8:23 pm
by JHPJHP
Hi Philippe-felixer76-3,
Are you going to maintain the link to the "License Plate Recognition" project or post the changes? If the latter - I will remove the link from the 1st post so as not to confuse anyone interested in testing your latest changes.
Note:
- updates to the include files since AAT posted his script caused errors with your release, and with this new batch of additions and updates there may be additional issues
------------------------------------------------
Updated:
- added Constants, Structures, Macros, Functions, Inline Functions (converted to Procedures)
I've been working on bringing some new areas of OpenCV to the package, but I'm being stalled with crashes that return no error information; I think the issues have to do with how I declared a few Structures. Anyone who would like to help resolve this latest batch of problems, I'd be more then happy to share my results.