PureBasic Interface to OpenCV

Developed or developing a new product in PureBasic? Tell the world about it.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: PureBasic Interface to OpenCV ---- 07/06/14 08:00 AM

Post by applePi »

sorry JHPJHP you are right, i haven't noticed the webcam , i will try it with the webcam.
i use pb 5.30 beta 6, your program does not issue any errors, it just close, it needs the webcam which i will try on another computer
thanks
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: PureBasic Interface to OpenCV ---- 07/06/14 08:00 AM

Post by applePi »

after connecting a webCam I have tried it on windows 7 32bit and it works like Charm.
tried it on windows xp/32 bit on the same system. it works but showing the following screen
Image
there is something rotating behind the red circles (can't show here). but when i click "X" to close the program the cube with the scene are displayed correctly but for a second before closing
regards
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV ---- 07/06/14 08:00 AM

Post by AAT »

Hi, JHPJHP!
Thanks a lot!

Updated
-------------------------
Hi, applePi
Don't understand yet, but if you change code to

Code: Select all

       If OpenWindow(0, 0, 0, 640, 480, #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))
       ToolTip(window_handle, #CV_DESCRIPTION)
      FrameWidth = cvGetCaptureProperty(*capture, #CV_CAP_PROP_FRAME_WIDTH)
you will see the cube.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: PureBasic Interface to OpenCV ---- 07/06/14 08:00 AM

Post by applePi »

thanks AAT , yes it works now with windows xp. so it is only commenting line
SetParent_(window_handle, WindowID(0))
thank you
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 07/06/14 08:00 AM

Post by JHPJHP »

Hi applePi,

Thank you for testing the example on Windows XP, and posting the problem.

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

Hi AAT,

Thank you for working out the problem when running the example on Windows XP, as usual you help is appreciated. And you're welcome, I'm glad you liked the example.

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

The package has been updated to include the fix mentioned above, as well as script added to the webcam examples to report if one cannot be found; it will not report if a webcam is in use.

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: 2250
Joined: Sat Oct 09, 2010 3:47 am

PureBasic Interface to OpenCV ---- 07/10/14 07:50 PM

Post by JHPJHP »

Updated
- renamed 2 examples
-- cv_cam_pb_database.pb to cv_pb_cam_database.pb
-- pb_cam_gl_cube.pb to pb_gl_cam_cube.pb
- added 1 example
-- pb_gl_photo_cube.pb: using OpenGL and textures, multiple images are displayed onto the surfaces of a rotating cube

I wanted to add an OpenGL example that didn't require a webcam, so I decided to do one with multiple textures / images.

Enjoy.
Last edited by JHPJHP on Sun Jul 20, 2014 9:29 pm, edited 5 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.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: PureBasic Interface to OpenCV ---- 07/10/14 01:30 AM

Post by applePi »

thanks JHPJHP ,very good textured cube "pb_gl_photo_cube.pb" , it works on windows xp but after commenting line "SetParent_(window_handle, WindowID(0))" as AAT referred to. so it is not a problem now. let me post a capture
Image
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV ---- 07/10/14 01:30 AM

Post by JHPJHP »

Hi applePi,

Thank you for the heads-up, but I realized my mistake shortly after uploading the new package, and had already applied a patch; you must've been the first person in the download queue. :P

I've opted to include the following line of code for the OpenGL examples, as opposed to removing the SetParent function; without it tooltips do not work, which are now only sacrificed when running the examples in Windows XP.

Code: Select all

If OSVersion() > #PB_OS_Windows_XP : SetParent_(window_handle, WindowID(0)) : EndIf
---------------------------------

Updated
- added 1 example
-- pb_gl_cam_invert.pb: using OpenGL and textures, the webcam interface is displayed onto the front and inverted onto the back of a revolving rectangle

Ok I'll admit it, now I'm just playing. :wink:

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

Added a small update to the example: pb_gl_cam_invert.pb - improving performance.

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: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Updated:
- added 2 examples
-- cv_dithering_1.pb: implementation of the Floyd-Steinberg dithering algorithm applied to a gray-scale image
-- cv_dithering_2.pb: implementation of the Floyd-Steinberg dithering algorithm applied to a color image

References:
http://en.wikipedia.org/wiki/Floyd%E2%8 ... _dithering
http://raine.tistory.com/81

Cheers!
Last edited by JHPJHP on Thu Jul 24, 2014 1:01 am, 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.
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!
Thanks a lot for your work!

I have a question: what it for seams on pictures (marked with red squares)?

Image

Image
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: PureBasic Interface to OpenCV

Post by blueb »

AAT,

I ran the program (using Lena.jpg) and cannot see any obvious distortion in the areas you mention.

Perhaps a graphics card issue?

Here's an expanded view of the area... https://www.dropbox.com/s/5prrcmo9nqadwyv/crop2.jpg

HTH
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: PureBasic Interface to OpenCV

Post by AAT »

Hi, blueb
blueb wrote:Perhaps a graphics card issue?
Don't think there is a problem with the video card.
Sometimes there are seams, sometimes not.
Please, try with others pictures http://rghost.ru/57052847

I will test this example in other PC with Windows 7 tomorrow (for now i use Windows XP).

By
User avatar
JHPJHP
Addict
Addict
Posts: 2250
Joined: Sat Oct 09, 2010 3:47 am

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Hi AAT, blueb,

Thank you for looking at the examples.

I just tested the examples on Windows XP, but didn't see any distortion.

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

Hi AAT,

I think I've figured it out. I believe the problem has to do with the window size/refresh, and it only affects the display. Run the example, then open a large image (e.g. building.jpg), close the program then run it again. The lena.jpg image should display with a grid like pattern. Save the image to your desktop and open it with any image editor - it should show without any distortion.

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

The "fix" was simple, changed the parameter #CV_WINDOW_NORMAL to #CV_WINDOW_AUTOSIZE.
- because it had such a drastic effect on these and other examples... I've updated all the examples to this setting

Updated the example: cv_dithering_1.pb.
- modified for a second time: adjusted the algorithm for better results

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

Post by AAT »

Hi, JHPJHP!

You are right.
When you open new picture first time, the window size is slightly different of the right values http://rghost.ru/57065541/image.png
I don't know why.
If

Code: Select all

cvResizeWindow(#CV_WINDOW_NAME, iWidth, iHeight)
or

Code: Select all

cvResizeWindow(#CV_WINDOW_NAME, *image\width, *image\height)
repeat twice, the window will be right size.

Also, it's possible to add one line to code

Code: Select all

        If *dither
          cvResizeWindow(#CV_WINDOW_NAME, *dither\width, *dither\height)        ; <----------- to set properly window size 
          cvShowImage(#CV_WINDOW_NAME, *dither)
.....
but I like your way more than my. :D

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

Re: PureBasic Interface to OpenCV

Post by JHPJHP »

Hi AAT,

Thanks again for taking the time to look at the examples.

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

Updated the example [ cv_inpaint.pb ] with a small enhancement.
- added the ability to apply multiple inpaint methods to the loaded image
- methods are color coded
-- BLUE: Navier-Stokes
-- GREEN: [Telea04]
-- RED: Navier-Stokes & [Telea04]

NB*: Apply the current repair (spacebar) before changing the method.

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

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