PureBasic Interface to OpenCV

Developed or developing a new product in PureBasic? Tell the world about it.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post 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.
Philippe-felixer76-3
User
User
Posts: 45
Joined: Mon Dec 30, 2013 10:12 pm

Re: PureBasic Interface to OpenCV

Post 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.
Ziltch
User
User
Posts: 52
Joined: Sun Aug 03, 2003 12:05 am
Location: Australia

Re: PureBasic Interface to OpenCV

Post by Ziltch »

Thanks.
AAT
Enthusiast
Enthusiast
Posts: 256
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV

Post 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!
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Nice change AAT, makes the example a little more dynamic... I've updated the package to include the change.
Philippe-felixer76-3
User
User
Posts: 45
Joined: Mon Dec 30, 2013 10:12 pm

Re: PureBasic Interface to OpenCV

Post 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..
AAT
Enthusiast
Enthusiast
Posts: 256
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV

Post 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.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post 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.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post 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"
Last edited by JHPJHP on Thu Jan 16, 2014 3:03 pm, edited 1 time in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post 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.

Image

Original source can be found here.
Last edited by JHPJHP on Sat Jan 18, 2014 10:28 pm, edited 3 times in total.
AAT
Enthusiast
Enthusiast
Posts: 256
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV

Post 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!
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: PureBasic Interface to OpenCV

Post by Kwai chang caine »

What a big work !!! 8)

But if sometime, .... :oops: :oops:
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 !!! :mrgreen: :lol:

Have i good understand ?? this is really for compare image no ???
Thanks in advance 8)
ImageThe happiness is a road...
Not a destination
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post 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!
Last edited by JHPJHP on Thu Jan 16, 2014 6:31 pm, edited 6 times in total.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: PureBasic Interface to OpenCV

Post 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 :cry:
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 8)
ImageThe happiness is a road...
Not a destination
Philippe-felixer76-3
User
User
Posts: 45
Joined: Mon Dec 30, 2013 10:12 pm

Re: PureBasic Interface to OpenCV

Post 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

Image
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
Locked