PureBasic Interface to OpenCV

Developed or developing a new product in PureBasic? Tell the world about it.
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:This time I'm mostly intrigued by the Gabor examples.
I thought the same thing about edge-detection in general.
- edge-detection is an important part of image analysis; numerous examples use a variety of edge-detection methods

Updated the OSX interface:
- converted 10 examples
-- cv_cam_setimageROI.pb: displays either a second webcam or simulates a second webcam by duplicating the main one
-- cv_cam_spider_web.pb: draw a Spider Web sketch from a webcam frame
-- cv_cam_warpaffine.pb: warp, stretch, rotate and resize a webcam stream
-- cv_cam_warpperspective.pb: calculates a perspective transform from four pairs of corresponding points
-- cv_overlay_1.pb: apply a perspective transform calculated from four pairs of points to an image, overlayed onto another image
-- cv_solve_maze.pb: maze game / solve a maze using a morphological transformation
-- cv_warpaffine.pb: calculates an affine transform from three pairs of corresponding points
-- cv_warpperspective_1.pb: calculates a perspective transform from four pairs of corresponding points
-- cv_warpperspective_2.pb: calculates a perspective transform from four pairs of corresponding points
-- cv_water_ripples.pb: creates the illusion of water ripples on a background image

NB*: An added bonus to converting examples to OSX are the corrections and enhancements being made to the Windows interface.

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:Updated the OSX interface:
- converted 10 examples
You are getting close to 100. :shock:

Some nice examples again.
Now I know I should have brought my computer with me if I get lost in a maze :wink:
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,
wilbert wrote:You are getting close to 100.
Updated the OSX interface:
- converted 10 examples :)
-- cv_add_subtract.pb: add or subtract every array element of an image
-- cv_depth_of_field.pb: using a second image as a mask to compare against an object in the original image, depth of field is simulated
-- cv_poisson_blending_2.pb: using a mixed Poisson blending algorithm, two images are blended together
-- cv_poisson_blending_3.pb: using a Poisson blending algorithm, a monochrome transfer is achieved between two images
-- cv_poisson_blending_4.pb: using a Poisson blending algorithm, a localized color change is achieved
-- cv_poisson_blending_5.pb: using a Poisson blending algorithm, a localized illumination change is achieved
-- cv_smooth_edges_1.pb: smooth the edges of an image using a normalized convolution filter
-- cv_smooth_edges_2.pb: smooth the edges of an image using a recursive filter
-- cv_stylize_1.pb: stylize an image by applying various filters
-- cv_stylize_2.pb: stylize an image by applying various filters

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:converted 10 examples :)
Congratulations. That's 100 :)

You had a Poisson blending example before but I'm still impressed by the algorithm.
It's a great way of blending images.
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 support and interest.
wilbert wrote:Congratulations. That's 100
Do you think we've reached any other OSX users :?: When creating the Windows interface, at 100 examples there were at least a few comments indicating interest :?
wilbert wrote:You had a Poisson blending example before but I'm still impressed by the algorithm.
The Poisson blending examples use a modified version of the code found in cv_poisson_blending_1.pb, but significantly expand the ability to blend images; based on a group of scripts found here.

The following images show a user defined cutout of a jet pasted onto a landscape, and the completed mixed blending process; for the most part I've opted to use full images in order to demonstrate Poisson blending without requiring user interaction.

NB*: Refer to the example cv_transparent_1.pb for script hosting a user defined cutout process.

Image

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:Do you think we've reached any other OSX users :?: When creating the Windows interface, at 100 examples there were at least a few comments indicating interest :?
I hope so. You only know for sure of course if someone leaves a comment.
But it's also good for Windows users who think of cross platform development. :)
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: PureBasic Interface to OpenCV

Post by Keya »

that Poisson blending is INSAAAAANE!!!!!!!! i had to google it, very fascinating algorithm but WOW the results really speak for themselves :) plus I could just keep saying Poisson with my best French accent all weekend
Great work on bringing such a beast to PB!!! :) :) :)
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:But it's also good for Windows users who think of cross platform development.
I agree, and it's not a waste of time if it has the potential to attract new users to PureBasic, at least that's what I keep telling myself :|

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

Hi Keya,

Now that was a response I can relate too :) Thank you for the comment, it was very much appreciated :!:

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

Most of the following examples were created while the Windows interface was in early development, and may seem basic compared to some of the previously added examples, but should be viewed more closely.

Updated the OSX interface:
- converted 10 examples
-- cv_approxpoly_1.pb: calculates the contour areas, approximating polygonal curves with specified precision
-- cv_approxpoly_2.pb: calculates the contour areas, approximating polygonal curves with specified precision
-- cv_bounding_rectangle.pb: calculates the contour areas
-- cv_convexhull_2.pb: calculates the contour areas, finding the convex hull of point sets, and approximating polygonal curves with specified precision
-- cv_fitellipse_2.pb: calculates the contour areas
-- cv_goodfeatures.pb: determines strong corners on an image, marked by circles
-- cv_minareacircle_2.pb: calculates the contour areas
-- cv_minarearect_2.pb: calculates the contour areas
-- le_fitellipse_2.pb: calculates the contour areas
-- le_minarearect_2.pb: calculates the contour areas
Last edited by JHPJHP on Mon Jun 13, 2016 5:06 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.
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_edges.pb: add an edge filter to an image detecting edges in all directions
-- cv_emboss_2.pb: apply a raised or pressed embossed style effects to an image
-- cv_emboss_3.pb: using an extended Sobel operator an embossed effect is acheived
-- cv_enhance_edges.pb: enhance the edges of an image in 2 stages using various filters
-- cv_fitellipse_1.pb: creates a sequence of points, bounding them in an ellipse of the minimal area
-- cv_flip.pb: flips a 2D array around vertical, horizontal, or both axes
-- cv_minareacircle_1.pb: creates a sequence of points, bounding them in a circle of the minimal area
-- cv_minarearect_1.pb: creates a sequence of points, bounding them in a rectangle of the minimal area
-- le_minarearect_1.pb: creates a sequence of points, bounding them in a rectangle of the minimal area
-- le_nearest_neighbor.pb: detects keypoints and computes SURF descriptors, finding the two nearest neighbors, but only returning the nearest if it is distinctly the better one

I remember awhile back a post requesting a searching algorithm that matched an image within a directory of images, where there may be a discrepancy between color, size, and angle...

The example le_nearest_neighbor.pb uses some of the same algorithms found in the stitching examples, but provides a powerful new approach to using them.

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:I remember awhile back a post requesting a searching algorithm that matched an image within a directory of images, where there may be a discrepancy between color, size, and angle...

The example le_nearest_neighbor.pb uses some of the same algorithms found in the stitching examples, but provides a powerful new approach to using them.
Yes, it was this thread by KCC to which I also contributed
http://www.purebasic.fr/english/viewtop ... =7&t=57731
Your example will most likely be better at finding a match.
I don't know if it will be fast enough for so many pictures but it's an interesting example. :)
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,
wilbert wrote:it was this thread by KCC to which I also contributed
I was familiar with the post and thought at the time to add a response, but was too interested in the direction you were taking.
- see the example cv_norm.pb (uses the images posted by KCC)

I could also use your help...

I've processed another 10 example, but I'm having trouble with one of the Functions...
- cv_cam_camshift.pb: [ cvCamShift ]

I've also patched together a Procedure in another example that I thought would move the mouse pointer, but it's not working.
- cv_cam_track_color.pb: [ includes/pb_procedures.pbi/SetCursorPos ]

Updated the OSX interface:
- converted 10 examples
-- cv_cam_angle.pb: calculates the angle of a line between two tracked object, one red and one blue, relative to their horizontal position
-- cv_cam_camshift.pb: using the Camshift algorithm, color information is used to track an object along an image sequence
-- cv_cam_glow_color.pb: adds a glow effect to red objects
-- cv_cam_motionhistory.pb: gradients of motion history are used to detect direction of motion
-- cv_cam_select_1.pb: demonstrates the ability to select an area on the webcam interface
-- cv_cam_select_2.pb: demonstrates the ability to select an area on the webcam interface
-- cv_cam_split_merge.pb: divides a multi-channel array into several single-channel arrays
-- cv_cam_track_color.pb: tracks red objects demonstrated by drawing a line that traces its location
-- pb_cam_effects_1.pb: applies a fixed-level threshold to each array element
-- pb_cam_effects_2.pb: calculates the per-element bit-wise conjunction
Last edited by JHPJHP on Tue Jun 14, 2016 9:24 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:- cv_cam_camshift.pb: [ cvCamShift ]
I'm not 100% sure about this one. Can you try if this works

Import
cvCamShift(*prob_image, window_xy, window_wh, criteria_tm, criteria_e.d, *comp, *box)

Usage

Code: Select all

        PokeL(@*recta, window\x) : PokeL(@*recta + 4, window\y)
        PokeL(@*rectb, window\width) : PokeL(@*rectb + 4, window\height)
        cvCamShift(*projection, *recta, *rectb, PeekQ(@criteria), criteria\epsilon, @comp, @box)
As for changing the mouse pointer, try this for OSX

Code: Select all

ImportC ""
  CGWarpMouseCursorPosition(x.CGFloat, y.CGFloat)
EndImport

CGWarpMouseCursorPosition(10, 100)
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,

Both of your patches worked great, thank you.

The Structure CvTermCriteria holds three parameters while the Function cvCamShift is now only referencing two of them; I see in the declaration two of the parameters have been combined.

Can you please explain the logic behind the new declaration, how the excluded Structure parameter is being referenced.

Thank you again for continuing to support PureBasic Interface to OpenCV :: OSX.

NB*: The OSX interface has been updated and is ready for download.

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:HThe Structure CvTermCriteria holds three parameters while the Function cvCamShift is now only referencing two of them; I see in the declaration two of the parameters have been combined.

Can you please explain the logic behind the new declaration, how the excluded Structure parameter is being referenced.
It was a little bit of a gamble. :wink:
What is clear from the function declaration is that the CvTermCriteria structure needs to be passed by value and not by reference.
The first two fields of CvTermCriteria are 32 bit integer values. Since they fit in one 64 bit register value, they are combined into one 64 bit integer by using PeekQ (just like CvPoint).
The third field is a double precision value which is also declared this way.
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,

Your ability to see the various declaration possibilities is just incredible.
wilbert wrote:It was a little bit of a gamble.
Based on your posts throughout the forum and your contributions here, I'd say it was more of a sure thing.

Thank you for your support, and for taking the time to explain the process :!:

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

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