Page 25 of 60

Re: PureBasic Interface to OpenCV

Posted: Wed Sep 17, 2014 6:45 pm
by JHPJHP
Hi applePi,

The following quotes from the link you posted are a couple reasons why I like math facts - thank you:
All simple pendulums should have the same period regardless of their initial angle (and regardless of their masses).
...
The period for a simple pendulum does not depend on the mass or the initial angular displacement, but depends only on the length of the string.
I'm not sure if you're going to spend anymore time on this, but there are numerous ways to improve the sensitivity for detecting objects.
- listed from top to bottom, not by effectiveness

Try changing the "shape" parameter:

Code: Select all

*kernel.IplConvKernel = cvCreateStructuringElementEx(3, 3, 1, 1, #CV_SHAPE_RECT, #Null)
Try changing the order, increasing/decreasing values, removing existing filters or adding additional filters:

Code: Select all

cvErode(*imgSilhouette, *imgSilhouette, *kernel, 1)
cvDilate(*imgSilhouette, *imgSilhouette, *kernel, 2)
cvErode(*imgSilhouette, *imgSilhouette, *kernel, 1)
Try changing the "mode" and/or "method" parameters:

Code: Select all

nContours = cvFindContours(*imgSilhouette, *storage, @*contours, SizeOf(CvContour), #CV_RETR_EXTERNAL, #CV_CHAIN_APPROX_NONE, 0, 0)
Try without an area minimum, removing the "If" structure:

Code: Select all

If area >= 500
Something else that may improve results is adjusting zone size. Try using only vertical or horizontal slats depending on what area your camera is focused on, the string or weight.

NB*: I found a problem with the thread function, it was missing a delay which caused the CPU usage to max-out when the alarm wasn't activated.

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

Updated:
- renamed 1 example
-- cv_cam_chessboard.pb to cv_cam_chessboard_2.pb
- added 1 example
-- cv_cam_chessboard_1.pb: after finding the positions of internal corners for a 10 x 7 chessboard pattern, a video is embedded using a warping algorithm

I'm currently using an iPad to load the chessboard pattern from the following link: http://www.clipartbest.com/cliparts/RiA ... 5yoKiL.png, but a printed copy would work just as well.
- I've replaced the chessboard image included with the package with the one from the above link

NB*: The chessboard pattern needed for the examples [ cv_cam_chessboard_1.pb ] and [ cv_cam_chessboard_2.pb ] to work, must match the configuration 10 x 7.

Image

Re: PureBasic Interface to OpenCV

Posted: Tue Sep 23, 2014 10:26 am
by Ziltch
Thank you for the huge amount of work you have put into this.
I also really appreciate the examples.

I wrote a program years ago to modify video/webcam using OpenCV the QT interface. I really wanted to make a Purebasic version and have better interface.
Thanks to you I can now do this! :D

Re: PureBasic Interface to OpenCV

Posted: Mon Sep 29, 2014 6:48 am
by JHPJHP
Hi Ziltch,

You're welcome and thank you for your comments. I would have responded sooner, but I wanted to write a new example first. :)
I wrote a program years ago to modify video/webcam using OpenCV the QT interface. I really wanted to make a Purebasic version and have better interface.
I'm glad the "PureBasic Interface to OpenCV" package can be of some use.

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

Updated:
- added 1 example
-- cv_parametric_curve.pb: Parametric Curve: A curve defined as a function of independent variables

Based on script found here.
- based on equations found here: http://en.wikipedia.org/wiki/Parametric ... _functions

Image

Re: PureBasic Interface to OpenCV

Posted: Tue Sep 30, 2014 6:17 pm
by JHPJHP
Updated:
- added 2 examples
-- cv_cam_glow_color.pb: adds a glow effect to red objects
-- cv_thinning_3.pb: repeated iterations using multiple filters on a grayscale image producing a skeleton effect

cv_cam_glow_color.pb: Based on script found here.
cv_thinning_3.pb: Based on script found here.

NB*: Update also includes small changes to examples that use the function: cvInRangeS.

Re: PureBasic Interface to OpenCV

Posted: Tue Sep 30, 2014 9:19 pm
by marc_256
Hi JHPJHP,

Thanks for all your work,
I know this is big.

Marc,

Re: PureBasic Interface to OpenCV

Posted: Sat Oct 04, 2014 9:32 pm
by applePi
Hi JHPJHP
i have seen your parametric curves "cv_parametric_curve.pb" , and it is really good, so i wonder how it looks like in 3D space !, so i have used your pb_gl_photo_cube.pb as a base, and then fill it with a classic OpenGL code , first fill one dimensional array with x,y,color values. then we position a pointer to that array. then we draw the array :

glVertexPointer_(3, #GL_FLOAT,SizeOf(Point3D),Point3D(0))
glColorPointer_(3, #GL_FLOAT, SizeOf(Point3D), @Point3D(0)\r)
glDrawArrays_(#GL_POINTS, 0, Nb)

then we rotate it.
and it is really speedy,
here the first picture are obtained by choosing :
a.f = 3.8 :b.f=2 ; k=1.9 (line 47)
the second pic by choosing
a.f = 3 :b.f=0.5 ; k=6 (line 48)
the third pic by choosing
a.f = 0.66 :b.f=2 ; k=0.33 (line 49)

Image
Image
Image

if you find the code needs more adjustment or corrections or additions then you are the expert

Code: Select all

Structure Point3D
  x.f
  y.f
  r.f
  g.f
  b.f
EndStructure

CompilerIf #PB_Compiler_Version >= 530
  IncludeFile "includes/cv_functions.pbi"

  #CV_WINDOW_NAME = "PureBasic Interface to OpenCV"
  #CV_DESCRIPTION = "Using OpenGL to display parametric curves"

  FrameWidth = 640
  FrameHeight = 480
  cvNamedWindow(#CV_WINDOW_NAME, #CV_WINDOW_AUTOSIZE)
  cvMoveWindow(#CV_WINDOW_NAME, -1000, -1000)
  cvResizeWindow(#CV_WINDOW_NAME, FrameWidth, FrameHeight)
  window_handle = cvGetWindowHandle(#CV_WINDOW_NAME)
  hWnd = GetParent_(window_handle)
  ShowWindow_(hWnd, #SW_HIDE)

  If OpenWindow(0, 0, 0, FrameWidth, FrameHeight, #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)
    SetWindowColor(0, 0)
    OpenGLGadget(0, 0, 0, FrameWidth, FrameHeight)
    ToolTip(window_handle, #CV_DESCRIPTION)

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

    glLoadIdentity_();
    gluPerspective_(45.0, 800/600, 1.0, 60.0)
    glTranslatef_(0, 0, -5)
    glEnable_(#GL_DEPTH_TEST)


Nb = 10054

Dim Point3D.Point3D(Nb)

u.f : v.f=-1 :r.f :t.f
x.f: y.f :z.f : N.l=0
;a.f = 1.3 :b.f=2 ; k=0.65
a.f = 3.8 :b.f=2 ; k=1.9
;a.f = 3 :b.f=0.5  ; k=6
;a.f = 0.66 :b.f=2 ; k=0.33

While t <= 32*#PI
 
          x = (a - b) * Cos(t) + b * Cos(t * ((a / b) - 1))
          y = (a - b) * Sin(t) - b * Sin(t * ((a / b) - 1))
          Point3D(N)\x = x*1
          Point3D(N)\y = y*1
          Point3D(N)\r = 0 :Point3D(N)\g = 1 :Point3D(N)\b = 0 
          N+1      
        
    t + 0.01
  Wend
    
     
  arrayLength = ArraySize(Point3D())
  
 ;=================================================================================
rot.f = 1
glTranslatef_(0.0, 0.0, -10)
    
    BringToTop(WindowID(0))
    
  Repeat
  glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  glEnableClientState_(#GL_VERTEX_ARRAY )
  glEnableClientState_(#GL_COLOR_ARRAY)
  glRotatef_(rot, 0, 1, 0);
 
  glVertexPointer_(3, #GL_FLOAT,SizeOf(Point3D),Point3D(0))
  glColorPointer_(3, #GL_FLOAT, SizeOf(Point3D), @Point3D(0)\r)
  
  glDrawArrays_(#GL_POINTS, 0, Nb)
  
  glDisableClientState_(#GL_VERTEX_ARRAY);
  glDisableClientState_(#GL_COLOR_ARRAY)
Repeat
    event = WindowEvent()
    If event = #PB_Event_CloseWindow
      quit = #True
    EndIf
  Until event = 0 Or quit = #True
  SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
  Delay(10)
Until quit = #True
  EndIf  
  cvDestroyWindow(#CV_WINDOW_NAME)
CompilerElse
  MessageBox_(0, "This example can only run in PureBasic 5.30 or greater." + #CRLF$ + #CRLF$ + "Operation cancelled.", "PureBasic Interface To OpenCV", #MB_ICONERROR)
CompilerEndIf

PureBasic Interface to OpenCV

Posted: Sun Oct 05, 2014 4:34 am
by JHPJHP
Hi marc_256,

Thank you for commenting, I'm glad you're still finding the project interesting.

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

Hi applePi,

Very nice work adapting a GL version of: cv_parametric_curve.pb. I'm also enjoying your examples in the 3D Programming forum.

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

Updated:
- added 1 example (jointly contributed by applePi)
-- pb_gl_parametric_curve.pb: using OpenGL to display various parametric curves

NB*: A nice way to view parametric curves, thanks to applePi.

Re: PureBasic Interface to OpenCV

Posted: Sun Oct 05, 2014 9:38 am
by applePi
Thanks JHPJHP for the new pb_gl_parametric_curve.pb example. and for making it possible to try all the curves easily. a wise Plan to use double curves with a small spacing, this enhances the Observer's feeling of the 3D Space and the Distance.
best wishes

PureBasic Interface to OpenCV

Posted: Thu Oct 09, 2014 5:48 am
by JHPJHP
Hi applePi,

You're welcome, but it was your OpenGL skills that made all the difference :!:

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

Updated:
- added 1 example
-- cv_cam_hsv_bgr.pb: display the HSV and BGR color space values determined by the X/Y mouse pointer location

This is a simple example, but I wanted an easier way to return values from the HSV color space.
- may help with adding a parameter range for the function: cvInRangeS

NB*: OpenCV's HSV values are different from those found in such programs as Photoshop and GIMP.

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

Updated:
- added 1 example
-- cv_standard_deviation.pb: applies Standard Deviation to an image by calculating the square root of the variance

Based on script found here.

Re: PureBasic Interface to OpenCV

Posted: Thu Nov 06, 2014 3:24 am
by JHPJHP
Image

Updated:
- updated 1 example
-- cv_pb_font.pb: draw text using PureBasic commands with any font onto an OpenCV generated image
- added 1 example
-- cv_addweighted.pb: alpha blend multiple images to simulate face morphing
- added 4 images

I couldn't just leave it at 199 examples... :wink:

Re: PureBasic Interface to OpenCV

Posted: Thu Nov 06, 2014 1:58 pm
by AAT
YES! It happened! 200 examples!
My congratulations to JHPJHP and to all PB interface to OpenCV users!
Soon there will be another date: anniversary of the beginning of the project :)

Good luck!

Re: PureBasic Interface to OpenCV

Posted: Thu Nov 06, 2014 2:26 pm
by Ziltch
More thanks from me, as well. The examples are great!

Re: PureBasic Interface to OpenCV

Posted: Thu Nov 06, 2014 11:34 pm
by JHPJHP
Hi AAT,
YES! It happened! 200 examples!
It sure did, and you were a big part of that. I would also like to thank applePi for his contributions.

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

Hi Ziltch,

You're welcome, it's good to hear you're still enjoying the examples.

Thank you for your comments.

Re: PureBasic Interface to OpenCV

Posted: Tue Nov 18, 2014 5:58 pm
by spacebuddy
Is there anyway to remove shadows in live video using opencv? :D

Re: PureBasic Interface to OpenCV

Posted: Wed Nov 19, 2014 1:39 pm
by AAT
Hi, spacebuddy.

Yes, there are some C examples:
http://stackoverflow.com/questions/9081 ... ing-opencv
http://stackoverflow.com/questions/9081 ... ing-opencv
http://www.youtube.com/watch?v=PdyErKsRB1o
and so on in google.

Translate C code to PB and voila :)

It is an interesting task. Sorry, i have no time to solve it.

Good luck!