Page 8 of 60
Re: PureBasic Interface to OpenCV
Posted: Sun Jan 12, 2014 12:25 am
by JHPJHP
From one of my previous posts:
- that's the problem when a thread has so many posts... too much information to review
I've done some testing with the 64-bit DLLs working with PureBasic; some functions need to be declared differently from the method I used in cv_functions.pbi... or more accurately they need to be declared the same way they're referenced in the manual; there are also some Structure discrepancies (alignment issues) between versions...
With the 32-bit DLL functions I needed to split out the Structure parameters, but for the same 64-bit DLL functions the Structure parameters needed to remain intact in order to work; a lot of trial and error.
Something like: [ CvRect ] vs [ x, y, width, height ]
And because there was/is so much to do creating an interface between PureBasic and OpenCV - I decided to remove the 64-bit part of the package, at least for the interim - until I'm comfortable with the progress.
Re: PureBasic Interface to OpenCV
Posted: Sun Jan 12, 2014 2:16 am
by Philippe-felixer76-3
Ziltch wrote:I have been using OpenCV in BlitzMax and C++ for ages. Great to see your work here getting it working with purebasic.
I am getting POLINK errors using PB x64. I can see no x64 directory in the binaries directory.
Is this now only 32bit?
I also run into this problem, just use PB 32 bit for now.
Re: PureBasic Interface to OpenCV
Posted: Sun Jan 12, 2014 3:29 am
by Ziltch
Thanks.
Re: PureBasic Interface to OpenCV
Posted: Sun Jan 12, 2014 5:34 am
by AAT
JHPJHP wrote:Hi AAT,
The new example may be of some help with your current project.
Hi JHPJHP!
This is no project, it's just for study openCV and for fun.
Thank you for your new example, very interesting!
I replaced the the part of code in your example to get more predictable results with an arbitrary image, something like that:
Code: Select all
*poly.CvSeq
*pt1.CvPoint
*pt2.CvPoint
For rtnCount = 0 To nContours - 1
area.d = cvContourArea(*contours, 0, #CV_WHOLE_SEQ_END_INDEX, 0)
If area >= 35 And area <= 100000
*poly = cvApproxPoly(*contours, SizeOf(CvContour), *storage, #CV_POLY_APPROX_DP, cvContourPerimeter(*contours) * 0.02, 0)
total = *poly\total
For rtnPoint = 0 To total - 1
*pt1 = cvGetSeqElem(*poly, rtnPoint)
*pt2 = cvGetSeqElem(*poly, (rtnPoint+1)%total)
Select total
Case 3
cvLine(*resize, *pt1\x, *pt1\y, *pt2\x, *pt2\y, 255, 0, 0, 0, 2, #CV_AA, #Null)
Case 4
cvLine(*resize, *pt1\x, *pt1\y, *pt2\x, *pt2\y, 0, 255, 0, 0, 2, #CV_AA, #Null)
Case 9
cvLine(*resize, *pt1\x, *pt1\y, *pt2\x, *pt2\y, 0, 0, 255, 0, 2, #CV_AA, #Null)
Default
cvLine(*resize, *pt1\x, *pt1\y, *pt2\x, *pt2\y, 0, 200, 255, 0, 2, #CV_AA, #Null)
EndSelect
Next
EndIf
*contours = *contours\h_next
Next
Good luck!
Re: PureBasic Interface to OpenCV
Posted: Sun Jan 12, 2014 9:17 pm
by JHPJHP
Nice change AAT, makes the example a little more dynamic... I've updated the package to include the change.
Re: PureBasic Interface to OpenCV
Posted: Sun Jan 12, 2014 11:45 pm
by Philippe-felixer76-3
Update on OCR, I added the dutch license plate font
http://www.dafont.com/kenteken.font as ocr config and it seems to work well.
https://www.dropbox.com/s/j2djq7ew0oy8g0j/OCR_test.png
The only thing is, i need to threshold the image to black and white pixels only, i can't seem to set a default value to get a good result for all images.
I have some idea's to improve the overal ocr a bit more.. so i will be working on it a bit more..
Re: PureBasic Interface to OpenCV
Posted: Mon Jan 13, 2014 12:55 pm
by AAT
Philippe-felixer76-3 wrote:...I have some idea's to improve the overal ocr a bit more.. so i will be working on it a bit more..
Very good result! I'll be waiting for your example of OCR.
Re: PureBasic Interface to OpenCV
Posted: Tue Jan 14, 2014 2:45 am
by JHPJHP
Updated:
- added Functions
- added 3 examples
-- cv_cam_good.pb: determines strong corners on an image, displaying them by drawing circles on the webcam interface
-- cv_corner.pb: calculates a feature map for corner detection
-- cv_harris.pb: Harris edge detector
- added 1 default image
The new examples use different corner detection functions.
- cvGoodFeaturesToTrack
- cvPreCornerDetect
- cvCornerHarris
As with most of the examples these are basic implementations of some powerful functions to prove-out compatibility with PureBasic.
Re: PureBasic Interface to OpenCV
Posted: Tue Jan 14, 2014 11:25 pm
by JHPJHP
Updated:
- modified 1 Function
-- cvCreateVideoWriter (split-out the size Structure parameter to width, height)
-- updated examples that used: cvCreateVideoWriter
- added 1 Procedure
As I've mentioned in previous posts - the OpenCV documentation does not match the required syntax most Functions need to work with PureBasic.
- the difficult aspect to figuring out the correct syntax was that it seemed to work (mostly) either way
cvCreateVideoWriter now works with more codecs. Previously I was using CV_FOURCC("M", "S", "V", "C"), but it created an extremely large AVI file (AVI Type 1 format). Now the default is CV_FOURCC("D", "I", "V", "X") and the file size is manageable as it uses better compression (2MB vs 250MB).
Note:
- cvGetCaptureProperty(*capture, #CV_CAP_PROP_FOURCC) is not currently working correctly
-- returns the same code no matter which codec is "loaded"
Re: PureBasic Interface to OpenCV
Posted: Thu Jan 16, 2014 6:04 am
by JHPJHP
Updated:
- added Constants, Functions
- added 1 example
-- cv_cam_game.pb: falling ball game played on the webcam interface
- added 2 default images
This is another one of those examples where I saw a demonstration
video and wanted to duplicate it... enjoy.
Original source can be found
here.
Re: PureBasic Interface to OpenCV
Posted: Thu Jan 16, 2014 1:32 pm
by AAT
Hi, JHPJHP!
Thank you for continuing to work with openCV. I not always manage to trace quickly additions, but it is always interesting to me.
Good luck!
Re: PureBasic Interface to OpenCV
Posted: Thu Jan 16, 2014 2:00 pm
by Kwai chang caine
What a big work !!!
But if sometime, ....
http://docs.opencv.org/doc/tutorials/im ... ation.html
and
http://docs.opencv.org/doc/tutorials/im ... rison.html
We never know....when you sleep !!!
Have i good understand ?? this is really for compare image no ???
Thanks in advance

Re: PureBasic Interface to OpenCV
Posted: Thu Jan 16, 2014 3:20 pm
by JHPJHP
Hi AAT,
Your support and continued interest is very much appreciated; Thanks!
Something you might find interesting / of use:
CvMat* cvGetSubRect(const CvArr* arr, CvMat* submat, CvRect rect)
submat – Pointer to the resultant sub-array header
Code: Select all
*roi.CvMat
submat.CvMat
*roi = cvGetSubRect(*gray, @submat, self(rtnCount)\x, self(rtnCount)\y, self(rtnCount)\width, self(rtnCount)\height)
nZero = cvCountNonZero(*roi)
Unlike other occurrences where CvMat or IplImage was used as a parameter, in this occasion (CvMat* submat) assigning the Structure to a memory address caused a bunch of problems.
--------------------
Hi Kwaï chang caïne,
For what you're trying to do (comparing album covers) using a Histogram Calculation or Histogram Comparison won't work, the comparison is too simplistic. I've done some SURF (Speeded Up Robust Features) examples that are a
start to what is required when dealing with images that are similar, but different due too rotation, pixel intensity, artifacts, etc. There are also a couple examples that compare contours that may be of some interest, but I can't say if or when I'll do anymore work on the subject.
Cheers!
Re: PureBasic Interface to OpenCV
Posted: Thu Jan 16, 2014 4:00 pm
by Kwai chang caine
Thanks JHPJHP for your answer
I have try with your code SURF, but the result for similar picture is enough different
It's for that i continue to search...but your idea for compare contours is a new way...i try to use it
Again thanks

Re: PureBasic Interface to OpenCV
Posted: Thu Jan 16, 2014 11:44 pm
by Philippe-felixer76-3
JHPJHP wrote:Updated:
- added Constants, Functions
- added 1 example
-- cv_cam_game.pb: falling ball game played on the webcam interface
- added 2 default images
This is another one of those examples where I saw a demonstration
video and wanted to duplicate it... enjoy.
- converted from Python example located
here

Super cool JHPJHP!!!
I'm working on the OCR, this weekend i think the first version of my OCR engine is ready..
https://www.dropbox.com/s/qk0duhyyung9p ... est_01.png
https://www.dropbox.com/s/4n48ccnhvjzf4cl/OCR_Test.png
https://www.dropbox.com/s/1jxi93i2crfby ... Test_3.png
https://www.dropbox.com/s/4otpdamzm5fal7x/OCR_Test2.png