PureBasic Interface to OpenCV
Re: PureBasic Interface to OpenCV ---- 04/18/14 07:30 PM
Hi AAT,
The post by Shervin Emami was one of the references I used to write the example. I also read the quote that he believed cvGetQuadrangleSubPix was faster then cvWarpAffine. I first thought that speed may have been affected by how I created the Mat matrix - different from his example, but quickly dismissed it.
I've recently optimized the example, but it didn't make a difference. I've also tested without using the trig functions - replacing them with cv2DRotationMatrix, again no difference. I would think a Function that replicates the border with each call would be slower then one that didn't, and I can't find any OpenCV documentation to support Shervin Emami's conclusions.
NB*: [ cvGetQuadrangleSubPix ] "Every channel of multiple-channel images is processed independently."
The post by Shervin Emami was one of the references I used to write the example. I also read the quote that he believed cvGetQuadrangleSubPix was faster then cvWarpAffine. I first thought that speed may have been affected by how I created the Mat matrix - different from his example, but quickly dismissed it.
I've recently optimized the example, but it didn't make a difference. I've also tested without using the trig functions - replacing them with cv2DRotationMatrix, again no difference. I would think a Function that replicates the border with each call would be slower then one that didn't, and I can't find any OpenCV documentation to support Shervin Emami's conclusions.
NB*: [ cvGetQuadrangleSubPix ] "Every channel of multiple-channel images is processed independently."
Last edited by JHPJHP on Wed Apr 23, 2014 8:19 pm, edited 4 times in total.
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Re: PureBasic Interface to OpenCV ---- 04/19/14 02:45 PM
Hi JHPJHP! Thanks for your help again!
Im triying SetBkColor_(window_handle, 0), but is always in gray (the system color)
I will send a message with the code, thanks!
Im triying SetBkColor_(window_handle, 0), but is always in gray (the system color)
I will send a message with the code, thanks!

If translation=Error: reply="Sorry, Im Spanish": Endif
Re: PureBasic Interface to OpenCV ---- 04/21/14 04:00 PM
Hi minimy
There are a couple of ways to achieve this:
ROI (Region Of Interest):
- set the back color of a destination image
- set an ROI to the destination image
- apply the source image to the ROI
Embed an OpenCV window onto a PureBasic window: See related examples.
There are a couple of ways to achieve this:
ROI (Region Of Interest):
- set the back color of a destination image
- set an ROI to the destination image
- apply the source image to the ROI
Code: Select all
...
cvSet(*dest, 0, 0, 0, 0, #Null)
cvSetImageROI(*dest, 20, 20, iWidth, iHeight)
cvAndS(*dest, 0, 0, 0, 0, *dest, #Null)
cvAdd(*dest, *source, *dest, #Null)
cvResetImageROI(*dest)
cvRectangleR(*dest, 19, 19, iWidth + 2, iHeight + 2, 0, 255, 255, 0, 1, #CV_AA, #Null)
...
Last edited by JHPJHP on Tue Apr 22, 2014 7:52 pm, edited 4 times in total.
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Re: PureBasic Interface to OpenCV ---- 04/21/14 04:00 PM
Hi JHPJHP, can say me how embedding the OpenCV window into a PureBasic window?
I think is the most easy way for change the color.
Thanks, regards!!
I think is the most easy way for change the color.
Thanks, regards!!
If translation=Error: reply="Sorry, Im Spanish": Endif
Re: PureBasic Interface to OpenCV ---- 04/21/14 04:00 PM
Hi minimy,
Check out the examples in the following format: pb_cam*.pb
Check out the examples in the following format: pb_cam*.pb
Code: Select all
...
cvNamedWindow(#CV_WINDOW_NAME, #CV_WINDOW_NORMAL)
cvMoveWindow(#CV_WINDOW_NAME, -1000, -1000)
cvResizeWindow(#CV_WINDOW_NAME, 640, 480)
window_handle = cvGetWindowHandle(#CV_WINDOW_NAME)
hWnd = GetParent_(window_handle)
ShowWindow_(hWnd, #SW_HIDE)
If OpenWindow(0, 0, 0, 640, 540, #CV_WINDOW_NAME, #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
opencv = LoadImage_(GetModuleHandle_(0), @"icons/opencv.ico", #IMAGE_ICON, 35, 32, #LR_LOADFROMFILE)
SendMessage_(WindowID(0), #WM_SETICON, 0, opencv)
SetParent_(window_handle, WindowID(0))
SetWindowColor(0, 0)
...
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Re: PureBasic Interface to OpenCV ---- 04/21/14 04:00 PM
Hi JHPJHP, Thanks friend! I see the light now!! 

If translation=Error: reply="Sorry, Im Spanish": Endif
PureBasic Interface to OpenCV ---- 04/22/14 03:20 AM
Updated:
- updated the OpenCV binaries
-- from v2.4.8 to v2.4.9
- updated Structures
- added 5 examples
-- cv_cam_skin_1.pb: detect skin tone using the HSV (Hue, Saturation and Value) color space
-- cv_cam_skin_2.pb: detect skin tone using the YUV (Luma [Y] and Chroma [UV]) color space
-- cv_cam_skin_3.pb: detect skin tone using the YCrCb (Luma [Y] and Chroma [CrCb]) color space
-- cv_cam_skin_4.pb: detect skin tone using the RGB (Red, Green and Blue) color space
-- cv_cam_skin_5.pb: detect skin tone using the RG (Red and Green) color space
I've tested the examples with the new OpenCV binaries - all seems good.
The "skin" examples are based on code found here.
Update includes various changes to examples including some bug fixes.
NB*: Some of the skin examples work better then others, and are affected by different lighting conditions.
- updated the OpenCV binaries
-- from v2.4.8 to v2.4.9
- updated Structures
- added 5 examples
-- cv_cam_skin_1.pb: detect skin tone using the HSV (Hue, Saturation and Value) color space
-- cv_cam_skin_2.pb: detect skin tone using the YUV (Luma [Y] and Chroma [UV]) color space
-- cv_cam_skin_3.pb: detect skin tone using the YCrCb (Luma [Y] and Chroma [CrCb]) color space
-- cv_cam_skin_4.pb: detect skin tone using the RGB (Red, Green and Blue) color space
-- cv_cam_skin_5.pb: detect skin tone using the RG (Red and Green) color space
I've tested the examples with the new OpenCV binaries - all seems good.
The "skin" examples are based on code found here.
Update includes various changes to examples including some bug fixes.
NB*: Some of the skin examples work better then others, and are affected by different lighting conditions.
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Re: PureBasic Interface to OpenCV ---- 04/25/14 06:30 PM
Updated:
- added 2 examples
-- cv_cam_histogram.pb: calculates a histogram for the Red, Green, and Blue channels of captured webcam frames
-- cv_stereobm.pb: computes disparity using the BM (Block Matching) algorithm for a rectified stereo pair of images
- added 3 images
cv_cam_histogram.pb: Original source can be found here.
cv_stereobm.pb: Additional information.
- added 2 examples
-- cv_cam_histogram.pb: calculates a histogram for the Red, Green, and Blue channels of captured webcam frames
-- cv_stereobm.pb: computes disparity using the BM (Block Matching) algorithm for a rectified stereo pair of images
- added 3 images
cv_cam_histogram.pb: Original source can be found here.
cv_stereobm.pb: Additional information.
Disparity refers to the difference in location of an object in corresponding two (left and right) images as seen by the left and right eye which is created due to parallax (eyes’ horizontal separation). The brain uses this disparity to calculate depth information from the two dimensional images.
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Re: PureBasic Interface to OpenCV ---- 04/29/14 05:50 AM
Updated:
- added 1 example
-- cv_thinning.pb: repeated iterations using an edge detection algorithm on a gray scale image produces increasingly thinner edges
- added 2 images
Original source can be found here.
Other thinning algorithms converted to OpenCV:
- http://opencv-code.com/quick-tips/imple ... in-opencv/
- http://opencv-users.1802565.n2.nabble.c ... 25544.html
NB*: Updated the example to show the thinning process.
- added 1 example
-- cv_thinning.pb: repeated iterations using an edge detection algorithm on a gray scale image produces increasingly thinner edges
- added 2 images
Original source can be found here.
Other thinning algorithms converted to OpenCV:
- http://opencv-code.com/quick-tips/imple ... in-opencv/
- http://opencv-users.1802565.n2.nabble.c ... 25544.html
NB*: Updated the example to show the thinning process.
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Re: PureBasic Interface to OpenCV ---- 04/29/14 05:00 PM
Hi!
I promised to write about connection of the IP camera. I keep the promise
If your camera supports two streams (like mine), you will see 2 windows with "Main Stream" and "Sub Stream" like this:

If you do not see the image, check firewall settings or temporarily disable it.
Some pictures about IPCam settings:
http://exfile.ru/460734
(file will be available one month)
Good Luck!
I promised to write about connection of the IP camera. I keep the promise

Code: Select all
; IP camera link format:
; rtsp://login:password@IPaddres:port/stream
; or
; http://login:password@IPaddres:port/stream
;
IncludeFile "includes/cv_functions.pbi"
#CV_WINDOW_NAME = "IPcam Test Window #1"
#CV_WINDOW_NAME2 = "IPcam Test Window #2"
nCreate = 0
Repeat
nCreate + 1
;IP cam (china's noname)with 2 sreams:
;main stream 1280*720
*capture = cvCreateFileCapture("rtsp://admin:123456@192.168.1.35:554/mpeg4")
;sub stream 640*360
*capture2 = cvCreateFileCapture("rtsp://admin:123456@192.168.1.35:554/mpeg4cif")
;D-Link "DCS-6616"
;rtsp
; *capture = cvCreateFileCapture("rtsp://admin:123456@192.168.0.20:554/live1.sdp")
; *capture = cvCreateFileCapture("rtsp://admin:123456@192.168.0.20:554/live2.sdp")
;http
; *capture = cvCreateFileCapture("http://admin:123456@192.168.0.20:80/video3.mjpg")
If (*capture <> 0) And (*capture2 <> 0)
Break
EndIf
Delay(500)
Until nCreate = 20
cvNamedWindow(#CV_WINDOW_NAME, #CV_WINDOW_AUTOSIZE)
cvNamedWindow(#CV_WINDOW_NAME2, #CV_WINDOW_AUTOSIZE)
*image.IplImage
*image2.IplImage
Repeat
*image = cvQueryFrame(*capture)
*image2 = cvQueryFrame(*capture2)
If *image
cvShowImage(#CV_WINDOW_NAME, *image)
EndIf
If *image2
cvShowImage(#CV_WINDOW_NAME2, *image2)
EndIf
keyPressed = cvWaitKey(10)
Until keyPressed = 27
cvDestroyWindow(#CV_WINDOW_NAME)
cvDestroyWindow(#CV_WINDOW_NAME2)

If you do not see the image, check firewall settings or temporarily disable it.
Some pictures about IPCam settings:
http://exfile.ru/460734
(file will be available one month)
Good Luck!
Re: PureBasic Interface to OpenCV ---- 04/29/14 05:00 PM
Since you're doing livestreaming over a network anyway, I think now would FINALLY be the appropriate time to ask if someone could please both add sound and send the sound over the network at the same time with hardly any latency so that way we can create live video chat programs. 
Thank You so much!

Thank You so much!
Re: PureBasic Interface to OpenCV ---- 04/29/14 05:00 PM
Hi, Mythros
I have not seen any examples to decode audio with opencv.
Good luck!
I have not seen any examples to decode audio with opencv.
Good luck!
Re: PureBasic Interface to OpenCV ---- 04/29/14 05:00 PM
Well, I think we should just use regular sound commands and regular packet commands to make it look like & act like it has sound. in other words, it actually DOES have sound.
Re: PureBasic Interface to OpenCV ---- 05/07/14 07:00 AM
Updated:
- added 3 examples
-- cv_DFT.pb: taking the DFT (Discrete Fourier Transform) of an image, and displaying its power spectrum
-- cv_fisheye.pb: standard fisheye lens effect derived from mathematical equations
-- cv_seam_carving.pb: deleting vertical seams in an image, detected by calculating the intensity of pixels, reducing the image width
cv_DFT.pb: based on dft.c - found in a previous version of OpenCV.
- http://www.thefouriertransform.com/
cv_fisheye.pb: based on script found here.
cv_seam_carving.pb
- a basic example of a powerful technique to manipulate images
-- I scripted a simple algorithm to demonstrate Seam-Carving
--- optimized to visually demonstrate Seam-Carving not speed
- check out the following links for the original (true) algorithm by Shai Avidan & Ariel Shamir
-- http://www.faculty.idc.ac.il/arik/SCWeb ... index.html : see video
-- https://en.wikipedia.org/wiki/Seam_carving
Also includes some minor updates and bug fixes to other examples - not worth documenting.
------------------------------------------------------------------
Updated cv_seam_carving.pb.
- included a trackbar to adjust spacing
- minor bug fixes and improvements
The following images demonstrate Content-Aware seam carving through user interaction, not included with the current example, but easily applied:

- added 3 examples
-- cv_DFT.pb: taking the DFT (Discrete Fourier Transform) of an image, and displaying its power spectrum
-- cv_fisheye.pb: standard fisheye lens effect derived from mathematical equations
-- cv_seam_carving.pb: deleting vertical seams in an image, detected by calculating the intensity of pixels, reducing the image width
cv_DFT.pb: based on dft.c - found in a previous version of OpenCV.
- http://www.thefouriertransform.com/
cv_fisheye.pb: based on script found here.
cv_seam_carving.pb
- a basic example of a powerful technique to manipulate images
-- I scripted a simple algorithm to demonstrate Seam-Carving
--- optimized to visually demonstrate Seam-Carving not speed
- check out the following links for the original (true) algorithm by Shai Avidan & Ariel Shamir
-- http://www.faculty.idc.ac.il/arik/SCWeb ... index.html : see video
-- https://en.wikipedia.org/wiki/Seam_carving
Also includes some minor updates and bug fixes to other examples - not worth documenting.
------------------------------------------------------------------
Updated cv_seam_carving.pb.
- included a trackbar to adjust spacing
- minor bug fixes and improvements
The following images demonstrate Content-Aware seam carving through user interaction, not included with the current example, but easily applied:



If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Re: PureBasic Interface to OpenCV ---- 05/08/14 12:15 AM
Updated:
- added 1 example
-- cv_poisson_blending.pb: using a Poisson blending algorithm, two similarly colored images are blended together
- added 10 images
Based on script found here.
Additional Information:

- added 1 example
-- cv_poisson_blending.pb: using a Poisson blending algorithm, two similarly colored images are blended together
- added 10 images
Based on script found here.
Additional Information:

Last edited by JHPJHP on Wed Jun 24, 2015 11:19 pm, edited 2 times in total.
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.