PureBasic Interface to OpenCV

Developed or developing a new product in PureBasic? Tell the world about it.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: PureBasic Interface to OpenCV

Post by wilbert »

You're getting close to 200 JHPJHP :shock: :)
JHPJHP wrote:For the OSX build the SSE, SSE2, and SSE3 options were checked, I believe the same was true for the Windows binaries.
For OSX this would be correct. Every Intel based Mac supports SSE, SSE2 and SSE3.
JHPJHP wrote:pb_gl_cam_cube.pb & pb_gl_cam_invert.pb: needs some work due to the poor video quality.
There's something strange with the cube example on my computer.
With debug enabled it displays an error message; with debug disabled it runs but the sides that make up the cube are not connected to each other (gaps between them).
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Hi wilbert,

Getting close, I think they're only 30 - 40 examples left to convert.

The following examples in the OSX interface have been fixed:
- pb_gl_cam_cube.pb, pb_gl_cam_invert.pb

NB*: In the past few months the examples in the Windows interface have been updated with many bug-fixes and improvements.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: PureBasic Interface to OpenCV

Post by wilbert »

JHPJHP wrote:The following examples in the OSX interface have been fixed:
- pb_gl_cam_cube.pb, pb_gl_cam_invert.pb
Working fine now :)
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: PureBasic Interface to OpenCV

Post by Lunasole »

JHPJHP wrote: Hi Lunasole,

For the OSX build the SSE, SSE2, and SSE3 options were checked, I believe the same was true for the Windows binaries.
Tnx for reply, should be problem with it. I wanted to try OpenCV in text recognizing from some images, but then anyway came up to making own build of Tesseract [used by OpenCV] to not bear whole OpenCV.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated the OSX interface:
- added 1 folder: default (templates to create examples)
-- aaa_cv_cam_default.pb
-- aaa_cv_default_1.pb
-- aaa_cv_default_2.pb
-- aaa_pb_cam_default.pb

NOTE: Copy the default template to the main example area before working on it.

NB*: Update also includes some bug-fixes and improvements to various examples.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Hi wilbert,
wilbert wrote:You're getting close to 200 JHPJHP
Just about there, but I'm having trouble with the OpenCV function: cvGetRectSubPix
- example: cv_find_license_plate.pb (line: 298)

When you have some time can you please take a look at the example. Thank you.

Updated the OSX interface:
- converted 10 examples
-- cv_cam_undistort.pb: calibrate webcam with a 10 x 7 chessboard pattern, displaying the raw and undistorted images
-- cv_distortion_1.pb: distort a color image by manipulating pixel locations
-- cv_distortion_2.pb: distort a grayscale image by manipulating pixel locations
-- cv_disttransform_1.pb: calculates the distance to the closest zero pixel for each pixel of the source image
-- cv_disttransform_2.pb: calculates the distance to the closest zero pixel for each pixel in the image
-- cv_encode_decode.pb: encode / decode a 4 channel image where the black areas have been converted to transparency
-- cv_find_license_plate.pb: license plate recognition (experimental)
-- cv_find_speed_sign.pb: speed sign recognition (experimental)
-- cv_gaussian_laplacian.pb: a visual representation of a Gaussian and Laplacian Pyramid
-- cv_haar_transform.pb: implements a Haar wavelet transform, decomposing then reconstructing the image

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV

Post by AAT »

Hi, JHPJHP!

Here are two examples of how to access tesseract from openCV http://rgho.st/7jdgjVmfd (90 days!)

- cv_tesseract.pb -- using opencv image in tesseract

Image

- cv_cam_tesseract.pb -- webcam frame OCR

Image

Dictionaries for various languages can be downloaded https://github.com/tesseract-ocr/tessdata

Enjoy! :)

P.S. Thanks, Lunasole! http://www.purebasic.fr/english/viewtop ... 12&t=66231
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: PureBasic Interface to OpenCV

Post by wilbert »

Thanks for the examples JHPJHP :)
JHPJHP wrote:I'm having trouble with the OpenCV function: cvGetRectSubPix
- example: cv_find_license_plate.pb (line: 298)
The center coordinate (2x float) needs to be passed by register xmm0.
Two ways to accomplish this.

Code: Select all

cvGetRectSubPix(*src, *dst, center.d)

center.d
PokeF(@center, minRect\center\x) : PokeF(@center + 4, minRect\center\y)
cvGetRectSubPix(*rotated, *crop, center)

Code: Select all

cvGetRectSubPix(*src, *dst)

PokeF(@*center, minRect\center\x) : PokeF(@*center + 4, minRect\center\y)
!movq xmm0, [p.p_center]
cvGetRectSubPix(*rotated, *crop)
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Hi AAT,

It is very good to hear from you :!:

Thank you for posting a couple great examples using OpenCV and the Tesseract framework interfaced by Lunasole.
- I'll add them to the Windows and OSX packages as soon as time permits

-----------------------------------------------------------------

Hi wilbert,
wilbert wrote:The center coordinate (2x float) needs to be passed by register xmm0.
I appreciate your patience repeating instructions you've previously covered. My only excuse for not catching it is that I'm fully engaged in another project.

The OSX interface has been updated with the fix provided by wilbert.
- update also includes some minor improvements to various examples

NB*: The two examples cv_find_license_plate.pb and cv_find_speed_sign.pb (including others) were created by AAT, which bears repeating considering the Tesseract examples he just posted.
Last edited by JHPJHP on Thu Jul 28, 2016 5:51 am, edited 1 time in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: PureBasic Interface to OpenCV

Post by wilbert »

JHPJHP wrote:NB*: The two examples cv_find_license_plate.pb and cv_find_speed_sign.pb (including others) were created by AAT, which bears repeating considering the Tesseract examples he just posted.
They are interesting examples; recognizing things inside an image 8)
Windows (x64)
Raspberry Pi OS (Arm64)
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV

Post by AAT »

Hi, JHPJHP.
JHPJHP wrote:NB*: The two examples cv_find_license_plate.pb and cv_find_speed_sign.pb (including others) were created by AAT, which bears repeating considering the Tesseract examples he just posted.
Yes, it was my second thought - to add OCR to these examples (The first one was about my work :lol: )
I do not have much free time, so made a quick example that needs to be improved in the future.
cv_find_speed_sign2.pb http://rgho.st/7TXt8g7Pn (90 days!)

= Update ===============
Improoved version of cv_find_speed_sign2.pb and cv_find_license_plate2.pb with OCR
http://rgho.st/8kfst4bry (90 days!)
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Hi wilbert,
wilbert wrote:They are interesting examples; recognizing things inside an image
I agree, and when time permits I hope to build the Tesseract libraries for OSX.

---------------------------------------------------------------------------------------

Hi AAT,

Thank you again for the webcam and image OCR examples, and for updating cv_find_license_plate.pb and cv_find_speed_sign.pb with the Tesseract OCR engine.
- NOTE: Tesseract OCR framework interfaced by Lunasole

Updated the Windows 32bit OpenCV Interface(s):
- added include: includes\pb_tesseract.pbi
- added folder: binaries\tesseract\tessdata
-- eng.traineddata, whitelist.cfg
- added binaries: binaries\liblept168.dll, libtesseract304.dll, libtesseract304.lib

The folder binaries\tesseract includes the following files:
- license.txt: Apache 2.0 license
- readme.txt: written by Lunasole

---------------------------------------------------------------------------------------

Updated the Windows 32bit OpenCV Interface(s):
- renamed 2 examples
-- cv_find_license_plate.pb to cv_OCR_license_plate.pb
-- cv_find_speed_sign.pb to cv_OCR_speed_sign.pb
- added 2 examples
-- cv_cam_OCR_tesseract.pb: using Tesseract OCR (Optical Character Recognition) a section of a webcam frame is translated to text
-- cv_OCR_tesseract.pb: Using Tesseract OCR (Optical Character Recognition) an image of numbers is translated to text

NB*: Currently I don't have the time to find / build the 64bit binaries, so only the 32bit packages have been updated.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated the OSX interface:
- converted 10 examples
-- cv_houghcircles.pb: finds circles in a grayscale image using the Hough transform
-- cv_houghlines_1.pb: finds lines in a binary image using the probabilistic Hough transform
-- cv_houghlines_2.pb: finds lines in a binary image using the standard Hough transform
-- cv_laplace.pb: calculates the Laplacian of an image
-- cv_logpolar.pb: remaps an image to log-polar space
-- cv_match_train.pb: creates a text file to later match contours against two image files containing numbers
-- cv_match_write.pb: tries to match contours learned from one image file containing numbers against another
-- cv_matchtemplate.pb: compares a template against overlapped image regions; matching one face against many faces
-- cv_maxrect.pb: finds a bounding rectangle for two given rectangles
-- cv_minarea_2.pb: finds the minimal area of a point set wrapping it in a triangle and a circle

cv_match_train.pb and cv_match_write.pb was a basic attempt to create an "OCR" type effect.
- binaries/trained/numbers.txt: learned file created using cv_match_train.pb
- double-click cv_match_write.pb to view the image converted to text

cv_minarea_2.pb is only partially working until I rebuild the OSX libraries to include additional script.
- see: http://www.purebasic.fr/english/viewtop ... 26#p466626

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: PureBasic Interface to OpenCV

Post by wilbert »

JHPJHP wrote:cv_matchtemplate.pb: compares a template against overlapped image regions; matching one face against many faces
That works pretty well ! :)
Nice work.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Hi wilbert,

Thank you for your post, and for taking the time to test the examples.
- only 10 examples left to convert and the OSX interface is complete

Updated the OSX interface:
- converted 12 examples
-- cv_morphology.pb: performs advanced morphological transformations using a specific structuring element
-- cv_mov_houghcircles.pb: finds circles in grayscale image frames using the Hough transform on a movie file
-- cv_mov_writeframe.pb: draws text to a movie file and saves it as an AVI
-- cv_pb_cam_database.pb: captures and saves webcam frames to a database
-- cv_pb_font.pb: draw text using PureBasic commands with any font onto an OpenCV generated image
-- cv_pb_image_1.pb: formats a PureBasic image to work with OpenCV
-- cv_pb_image_2.pb: formats a PureBasic image to work with OpenCV
-- cv_precornerdetect_1.pb: calculates a feature map for corner detection
-- cv_precornerdetect_2.pb: calculates a feature map for corner detection
-- cv_steganography_image_1.pb: steganography is the practice of concealing a file
-- cv_steganography_image_2.pb: steganography is the practice of concealing a file
-- cv_steganography_text.pb: steganography is the practice of concealing a file

NB*: Added additional functionality to the example cv_pb_cam_database.pb; updated all packages.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Locked