PureBasic Interface to OpenCV

Developed or developing a new product in PureBasic? Tell the world about it.
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV ---- 03/26/14 10:45 PM

Post by AAT »

Hi JHPJHP!

You have at least one (it's me :) ) who want to see more examples. Please add its to the package.
You le_stitching.pb example is very impressive! I will take photos over the weekend to experiment more.

Good luck!
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 03/27/14 12:40 AM

Post by JHPJHP »

Hi AAT,

I spent the time and updated the new example to conform to the existing standards - I hope you have some fun with it.

Thanks for responding, your appreciation makes all the effort worth while.

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

Updated:
- renamed 1 example
-- le_stitching.pb to le_stitching_1.pb
- added 1 example
-- le_stitching_2.pb: stitches images together; based on the SIFT (Scale Invariant Feature Transform) algorithm
- added 14 images

Also includes some minor updates to other examples - not worth documenting.

Unlike the first stitching example which demonstrated each stage of the SIFT process, this example takes a group of images (2, 3, 4 and 5 exclusively) and stitches them together directly.
- when the variance between multiple image perspectives is high, there is a greater degree of distortion
- another thing to be aware of is the order of images, which need to be loaded from right to left

5 image stitch: I cut a panoramic image into 5 overlapping images, the resulting stitched images are near prefect due to their identical perspectives
3 image stitch: you should see in the third image (right side), that the size of the double doors is distorted compared with the original image
- with three or more images, and depending on their perspective angles, the resulting output can be a radically distorted image
-- fixing this should be fairly simple with a few changes to the code

Some setting to be aware of (Feature Detection and Description):
- #PARAMS_EXTENDED
-- 0 means that the basic descriptors (64 elements each) shall be computed
-- 1 means that the extended descriptors (128 elements each) shall be computed
- #PARAMS_THRESHOLD
-- threshold for the keypoint detector
--- a good default value could be from 300 to 500, depending from the image contrast
Last edited by JHPJHP on Fri Mar 28, 2014 2:27 pm, edited 4 times 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.
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PureBasic Interface to OpenCV ---- 03/28/14 12:40 AM

Post by yrreti »

Some setting to be aware of (Feature Detection and Description):
Just a minor error on the link that causes a 404
feature_detection.html)
just remove the extra ) at the end of the link and its ok.
Thanks for the link.
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 03/28/14 12:40 AM

Post by JHPJHP »

Hi yrreti,

The link is now fixed... I wondered if anyone was reading the posts. :o

Thank you.
Last edited by JHPJHP on Sun Mar 30, 2014 10:23 pm, edited 2 times 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.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: PureBasic Interface to OpenCV ---- 03/28/14 12:40 AM

Post by Thunder93 »

I'm reading the posts. Good job you have been doing here.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 03/28/14 12:40 AM

Post by JHPJHP »

Hi again Thunder93, :)

Thanks for the kudos, your acknowledgement is very much appreciated.

Cheers!

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 ---- 03/30/14 10:00 AM

Post by JHPJHP »

Updated:
- updated 2 examples
-- le_stitching_1.pb: stitch together 2 images in stages; based on the SIFT (Scale Invariant Feature Transform) algorithm
-- le_stitching_2.pb: stitch together 2, 3, 4, or 5 images; based on the SIFT (Scale Invariant Feature Transform) algorithm
- deleted 4 images
- replaced 7 images

Added a Procedure to better frame the stitched image, including minor improvements and some bug fixes.

Also includes some minor updates to other examples - not worth documenting.

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

Updated:
- added 1 example
-- cv_retro.pb: retro-style photo effect done by adding noise to the luminance channel and reducing intensity of the chroma channels
- added 2 images

Original Code: image.cpp found in the current version of OpenCV.

NB*: Helpful information: Transform CvArr, CvMat and IplImage.
Last edited by JHPJHP on Sun Apr 06, 2014 6:56 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.
Morty
User
User
Posts: 35
Joined: Mon Mar 19, 2007 8:30 am
Location: Germany
Contact:

Re: PureBasic Interface to OpenCV ---- 03/30/14 10:00 AM

Post by Morty »

Thanks again for your work ... it's amazing to see what you did and how it extends PureBasic. Keep on :D
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 04/04/14 03:00 PM

Post by JHPJHP »

Hi Morty,

Thank you for your kind words - I really appreciate the acknowledgement.

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

Updated:
- added 1 example
-- cv_calcbackproject.pb: calculating the back projection of a histogram, frequent density values are displayed as bright pixels
Last edited by JHPJHP on Sun Apr 06, 2014 4:03 pm, 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.
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 04/06/14 01:35 AM

Post by JHPJHP »

Updated:
- updated Functions
- added 2 examples
-- cv_cam_pixelate.pb: pixelate a webcam stream by averaging NxN block regions, and applying the color values to grid squares
-- cv_imagedots.pb: creates an image by averaging 10x10 block regions, and applying the color values to a dot matrix

cv_cam_pixelate.pb:
Image
Last edited by JHPJHP on Thu Jun 15, 2017 8:50 pm, edited 4 times 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.
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: PureBasic Interface to OpenCV ---- 04/06/14 01:35 AM

Post by marc_256 »

hi JHPJHP,

first at all, thanks again for all your nice work,
second, do you ever sleep ? :wink: :mrgreen:

marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 04/06/14 11:40 PM

Post by JHPJHP »

Hi marc_256,

You're welcome, and thank you for the acknowledgement. As for your question on whether I sleep or not...

Sleep, those little slices of death; Oh how I loathe them.
~Edgar Allan Poe

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

Updated:
- added 3 examples
-- cv_logpolar.pb: remaps an image to log-polar space
-- le_delaunay_1.pb: manual construction of delaunay triangulation
-- le_delaunay_2.pb: random construction of delaunay triangulation
- changed the naming convention from 1a, 1b, etc. to 1, 2, etc.

le_delaunay_*.pb: based on script found here.
Last edited by JHPJHP on Thu Apr 10, 2014 5:31 pm, 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.
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 04/10/14 09:40 PM

Post by JHPJHP »

Updated:
- added Constants, Structures, Functions
- added 2 examples
-- cv_sepia.pb: convert a color image to sepia
-- le_mov_bgstatmodel.pb: using a Gaussian mixture-based background/foreground detection algorithm, foreground objects are highlighted by comparing the current frame with a static frame
- added 1 movie file: walking.avi

NB*: New Functions are from the legacy DLL - all others have been declared.

Even though the functions used in le_mov_bgstatmodel.pb are from the legacy DLL, there are numerous object-detection possibilities; I may play around with this some more.

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

Updated:
- renamed 1 example
-- le_mov_bgstatmodel.pb to le_mov_bgstatmodel_1.pb
- added 1 example
-- le_mov_bgstatmodel_2.pb: using a background/foreground detection algorithm, foreground objects are highlighted/removed by comparing the current frame with a static frame

I found a bug in the previous example, while fixing that problem I decided to add an additional example using the BGStatModel functions.

Cheers!

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 ---- 04/10/14 09:40 PM

Post by AAT »

Hi, JHPJHP

Thanks for your greate new examples!
The example le_mov_bgstatmodel_1.pb is very interesting! I saw it but I didn't knew how to translate it into PureBasic. Great!

------------
I had a need to keep the images processed with opencv in a database (in BLOB). The code with saving the image into a temporary file works too slow, so i found the solution how to make conversion in the memory. For example:

Code: Select all

*image.IplImage = cvQueryFrame(*capture)     ; getting  image from the webcam
...
If *image
  *mat.CvMat = cvEncodeImage(".jpg", *image, 0)
  Result = CatchImage(1, *mat\ptr)        
  *imgbuf = EncodeImage(1, #PB_ImagePlugin_JPEG);
  bufsize = MemorySize(*imgbuf)
  
  If OpenDatabase(0, DatabaseFile, "", "")                   
    SetDatabaseBlob(0, 0, *imgbuf, bufsize)
    Result = CheckDatabaseUpdate(0, "INSERT INTO ...")
    If Result <> 0
      ...
    Else
      ...      
    EndIf  
  EndIf
  ...  
EndIf
P.S. The code works fine but jpeg compression level is too high. I don't know how to regulate the compression level. :(

Good luck!
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 04/11/14 02:45 PM

Post by JHPJHP »

Hi AAT,

You're welcome, I'm glad you're enjoying the examples.

Conversion in memory is definitely the way to go, I wrote a Comic Book reader using the same functions because of the speed improvement over file access.
jpeg compression level is too high. I don't know how to regulate the compression level
It's done the same way as with the cvSaveImage Function, the new example should give you a clearer picture (ignore the pun) :) .

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

Updated:
- updated 1 Function
- added Procedures
- added 1 example
-- cv_cam_pbdatabase.pb: captures and saves webcam frames to a database, displaying a thumbnail version of the image loaded from the database

I usually like to work with PostgreSQL, but that obviously wouldn't work in this case, so the database I'm using is SQLite - I'm impressed with the size and speed.

Creating a database entry: ImportImage(*image, name.s, extension.s = ".jpg")
- first parameter is an OpenCV image
- second parameter is part of the database entry name (string)
-- the rest of the name is automatically generated: dd_mm_yyyy_hh_mm_ss_fff (milliseconds used for fast captures)
-- this should allow for organizing/sorting the database
- third parameter is optional
- returns the database entry name (string)

Retrieving a database entry: GetDBImage(dbName.s)
- parameter is database entry name (string)
- returns an OpenCV image

Note:
- after pressing the SPACEBAR if the thumbnail image shows/changes, then the database update/retrieval is working properly.

NB*: Image compression is static, but can be changed from the Procedure: ImportImage().

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

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