PureBasic Interface to OpenCV

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

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

skywalk wrote:Mine is a muddy river with beaver and muskrat and the usual water fowl.
Sounds like heaven; my favorite times in life have been in places like the one you have just described.

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

Updated (Windows Main Packages):
- added 1 example
-- pbcv_webcam_MDI_cvtcolor.pb: PureBasic parent window hosting an OpenCV webcam child window

This example starts a new naming convention [ pbcv ]; a PureBasic example with an embedded OpenCV window.

Using a wide range of API's and Callbacks I managed to embed an OpenCV window into a PureBasic frame.
While the embedding was fairly easy, my main focus was to have a dynamic window that responded correctly when mixing with PureBasic Gadgets.

The embedded window (webcam) can be resized and moved, and includes an optional title bar.
The CONSTANTS at the beginning of the code can be used to control most options, but this is only an example meant for instructional purposes.

The advantage of this example is that it combines speed with function.
The examples that start with [ cv ] have speed, but access to PureBasic Gadgets is limited.
The examples that start with [ pb ] have access to PureBasic Gadgets, but the speed of OpenCV is reduced because images are converted between platforms.
Last edited by JHPJHP on Mon Apr 05, 2021 12:53 am, edited 4 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; access key required.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1763
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated (all packages):
- improvements to pbcv_webcam_MDI_cvtcolor.pb
- renamed some examples, conforming to a new naming convention
- set DPI Aware to all Windows examples that start with [ pb ]

Naming Convention
1. cv_ : OpenCV examples, OpenCV image / window
2. cv_le_ : OpenCV Legacy examples, OpenCV image / window
3. cv_pb_ : OpenCV examples, PureBasic to OpenCV image / window
4. pb_cv_ : PureBasic examples, OpenCV to PureBasic image / window
5. pbcv_ : PureBasic examples, OpenCV image / window embedded into PureBasic gadget / window

NB*: There is no one right solution, each of the example types above have there own benefits depending on your requirements.
Last edited by JHPJHP on Mon Apr 05, 2021 12:54 am, edited 4 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; access key required.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1763
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated (Windows Main Packages):
- added 1 example
-- pbcv_webcam_cvtcolor.pb: PureBasic ContainerGadget hosting an OpenCV webcam child window

pbcv_webcam_cvtcolor.pb
This example greatly expands the use of OpenCV with PureBasic, converting the ContainerGadget into an OpenCvGadget.

Updated Packages
- OpenCV_2.4.13.6_WIN_32_SRC_(main)
- OpenCV_2.4.13.6_WIN_64_SRC_(main)
- OpenCV_3.4.1_WIN_32_SRC_(world)
- OpenCV_3.4.1_WIN_64_SRC_(world)

Image
Last edited by JHPJHP on Fri Apr 02, 2021 4:23 am, edited 2 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; access key required.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1763
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated (Windows Main Packages):
- pbcv_webcam_cvtcolor.pb
- pbcv_webcam_MDI_cvtcolor.pb
- numerous small improvements to various parts of the code

pbcv_webcam_cvtcolor.pb
Code has been restructured; main OpenCV loop is now threaded.

pbcv_webcam_MDI_cvtcolor.pb
Example includes a second webcam window.
Code has been restructured; main OpenCV loop is now threaded.
Last edited by JHPJHP on Mon Apr 05, 2021 12:55 am, edited 1 time in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; access key required.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1763
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated (Windows Main Packages):
- pbcv_webcam_MDI_cvtcolor.pb
- various code improvements

pbcv_webcam_MDI_cvtcolor.pb
Added PureBasic Structured Maps to allow for individual customized window styles.
Windows can be made to look like OpenCV Gadgets (pbcv_webcam_cvtcolor.pb), but still be movable and resizable.

Image

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; access key required.
_________________
spacebuddy
Enthusiast
Enthusiast
Posts: 343
Joined: Thu Jul 02, 2009 5:42 am

Re: PureBasic Interface to OpenCV

Post by spacebuddy »

Hi All,

Is it possible to set the exposure for a webcam using opencv?

Anyone have sample code?

Thanks
User avatar
JHPJHP
Addict
Addict
Posts: 1763
Joined: Sat Oct 09, 2010 3:47 am
Contact:

PureBasic Interface to OpenCV

Post by JHPJHP »

Hi spacebuddy,

Note, the following available settings are dependent on your webcam.
spacebuddy wrote:Is it possible to set the exposure for a webcam using opencv?

Anyone have sample code?
Yes, and a code sample is as simple as the follow...

Code: Select all

cvSetCaptureProperty(*capture, #CV_CAP_PROP_EXPOSURE, -4)
I believe the following sets manual exposure (0.25 sets auto exposure OFF and 0.75 sets auto exposure ON)...

Code: Select all

cvSetCaptureProperty(*capture, #CV_CAP_PROP_AUTO_EXPOSURE, 0.25)
If your having trouble with the correct settings or prefer a dialog window...

Code: Select all

cvSetCaptureProperty(*capture, #CV_CAP_PROP_SETTINGS, #True)
Image Image
Last edited by JHPJHP on Tue Apr 06, 2021 10:01 pm, edited 5 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; access key required.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1763
Joined: Sat Oct 09, 2010 3:47 am
Contact:

PureBasic Interface to OpenCV

Post by JHPJHP »

Updated (Windows Main Packages):
- added two default examples
-- default\aaa_pbcv_webcam_default.pb
-- default\aaa_pbcv_webcam_MDI_default.pb

Default Examples
The new default examples can be used as templates for a PureBasic / OpenCV hybrid application.
Default examples must be copied from their current location to the main examples folder in order to execute.

The examples pbcv_webcam_cvtcolor.pb and pbcv_webcam_MDI_cvtcolor.pb are more advanced, but offer greater detail on how to merge OpenCV with PureBasic.

NB*: The new examples include a context menu option to open webcam settings; see previous post for additional information.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; access key required.
_________________
spacebuddy
Enthusiast
Enthusiast
Posts: 343
Joined: Thu Jul 02, 2009 5:42 am

Re: PureBasic Interface to OpenCV

Post by spacebuddy »

thank you, works great!!

I do have another question, my webcam has 5 times zoom, is there anyway to use that with opencv?

Thanks
User avatar
JHPJHP
Addict
Addict
Posts: 1763
Joined: Sat Oct 09, 2010 3:47 am
Contact:

PureBasic Interface to OpenCV

Post by JHPJHP »

Hi spacebuddy,
spacebuddy wrote:I do have another question, my webcam has 5 times zoom, is there anyway to use that with opencv?
The answer is yes, providing your webcam supports it.
My previous response still applies... if you're having trouble with the correct settings...

Code: Select all

cvSetCaptureProperty(*capture, #CV_CAP_PROP_SETTINGS, #True)
If Zoom is available from the dialog window then maybe. If the slider works to adjust the webcam zoom then maybe.

The only way to tell if OpenCV has access to your webcam is to try it for yourself...

Code: Select all

cvSetCaptureProperty(*capture, #CV_CAP_PROP_ZOOM, [the dialog window should provide working values])

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; access key required.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1763
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated (main Windows packages):
- some minor improvements to the OpenCV_Gadget examples
-- pbcv_webcam_cvtcolor.pb, pbcv_webcam_MDI_cvtcolor.pb

NB*: Update also includes improvement to the Default OpenCV_Gadget examples.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; access key required.
_________________
Post Reply