libOpenCV Windows/Linux 32/64-bit

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
D.J.Peters
Posts: 8023
Joined: May 28, 2005 3:28
Contact:

libOpenCV Windows/Linux 32/64-bit

Postby D.J.Peters » Mar 03, 2020 20:07

Preview of libOpenCV ~700 commands !

wikipedia: https://en.wikipedia.org/wiki/OpenCV

doc: https://docs.opencv.org/2.4.13.6/

github: https://github.com/opencv/opencv/releases/tag/2.4.13.6

Tip: search for "OReilly Learning OpenCV.pdf"

Latest uploads are from Mar 07, 2020

OpenCV for FreeBASIC include files and first simple tests.
fbopencv.zip

opencv windows runtime and import libraries
opencv_win32.zip
opencv_win64.zip
opencv linux runtime libraries
opencv_lin32.tar.gz
opencv_lin64.tar.gz
download the linux runtime your $HOME folder then type
in case of 32-bit
>tar -xvvzf opencv_lin32.tar.gz
>cd opencv_lin32
sudo cp libopencv*.* /usr/lib
*****
in case of 64-bit
>tar -xvvzf opencv_lin64.tar.gz
>cd opencv_lin64
sudo cp libopencv*.* /usr/lib
******
Joshy
Last edited by D.J.Peters on Mar 07, 2020 9:38, edited 15 times in total.
D.J.Peters
Posts: 8023
Joined: May 28, 2005 3:28
Contact:

Re: [preview] libOpenCV

Postby D.J.Peters » Mar 04, 2020 3:37

Added 50 more commands and build linux 64-bit opencv runtime with Video4linux2 see first post.

Joshy
Last edited by D.J.Peters on Mar 05, 2020 6:17, edited 2 times in total.
D.J.Peters
Posts: 8023
Joined: May 28, 2005 3:28
Contact:

Re: libOpenCV Windows 32/64.bit Linux 64-bit

Postby D.J.Peters » Mar 04, 2020 3:55

more than 500 commands now !

Joshy
D.J.Peters
Posts: 8023
Joined: May 28, 2005 3:28
Contact:

Re: libOpenCV Windows 32/64.bit Linux 64-bit

Postby D.J.Peters » Mar 04, 2020 15:33

In scope of realtime image/video processing you need often a user interface with sliders to change any value.

OpenCV comes with a "trackbar" slider (windows native,linux gtk, window/linux qt ..."

Of course you can ignore the OpenCV simple GUI and use the FreeBASIC gfx screen alone or your favorite GUI !

test of one window with 3 simple trackbar's
file: trackbar01.bas

Code: Select all

#include "opencv.bi"
dim as long r,g,b
cvNamedWindow("win") : cvResizeWindow("win",640,480)
cvCreateTrackbar("red"  ,"win",@r,255)
cvCreateTrackbar("green","win",@g,255)
cvCreateTrackbar("blue" ,"win",@b,255)

' loop with 30Hz while [ESC] not pressed
while cvWaitKey(1000/30)<>27
 locate 3,1 : print r,g,b
wend

cvDestroyWindow("win")


test of one window with 3 trackbar's and callback's
file: trackbar02.bas

Code: Select all

#include "opencv.bi"
sub cbRed CV_CDECL (r as long)
  locate 1,1 : print "red  : " & r
end sub
sub cbGreen CV_CDECL (g as long)
  locate 2,1 : print "green: " & g
end sub
sub cbBlue CV_CDECL (b as long)
  locate 3,1 : print "blue : " & b
end sub

dim as long r,g,b
cvNamedWindow("win") : cvResizeWindow("win",640,480)
cvCreateTrackbar("red"  ,"win",@r,255,@cbRed)
cvCreateTrackbar("green","win",@g,255,@cbGreen)
cvCreateTrackbar("blue" ,"win",@b,255,@cbBlue)

' loop with 30Hz while [ESC] not pressed
while cvWaitKey(1000/30)<>27
  locate 4,1 : print r,g,b
wend

cvDestroyWindow("win1")
D.J.Peters
Posts: 8023
Joined: May 28, 2005 3:28
Contact:

Re: libOpenCV Windows 32/64.bit Linux 64-bit

Postby D.J.Peters » Mar 04, 2020 16:00

Note: The heartbeat of the OpenCV GUI are cvWaitKey() it's the message/event pump.
Without a repeated call of cvWaitKey() nothing will be refreshed or changed. (window size, mouse events, trackbar callback, ...)

Joshy
Last edited by D.J.Peters on Mar 06, 2020 23:23, edited 1 time in total.
D.J.Peters
Posts: 8023
Joined: May 28, 2005 3:28
Contact:

Re: libOpenCV Windows 32/64.bit Linux 64-bit

Postby D.J.Peters » Mar 04, 2020 18:25

Last but not least the mouse callback :-)

Note: the message pump cvWaitKey() calls the mouse callback independent does a value changed or not !

This is why I use the static vars old mouse coords "ox,oy" and old flags "of" .

Joshy

file "mouse01.bas"

Code: Select all

#include "opencv.bi"

' mouse callback
sub cbMouse CV_CDECL ( event as long, x as long, y as long, flags as long, userdata as any ptr )
  static as long ox=-1,oy=-1,of=-1
  ' print event,x,y,flags
  select case as const event
  case CV_EVENT_MOUSEMOVE     
    if ox<>x orelse oy<>y orelse of<>flags then
      print "MOUSEMOVE",x,y
      ox=x : oy=y : of=flags
    end if 
  case CV_EVENT_LBUTTONDOWN   : print "Left Button Down"
  case CV_EVENT_RBUTTONDOWN   : print "Right Button Down"
  case CV_EVENT_MBUTTONDOWN   : print "Middle Button Down"
  case CV_EVENT_LBUTTONUP     : print "Left Button Up"
  case CV_EVENT_RBUTTONUP     : print "Right Button Up"
  case CV_EVENT_MBUTTONUP     : print "Middle Button Up"
  case CV_EVENT_LBUTTONDBLCLK : print "Left Button Doubleclick"
  case CV_EVENT_RBUTTONDBLCLK : print "Right Button Doubleclick"
  case CV_EVENT_MBUTTONDBLCLK : print "Middle Button Doubleclick"
  case else : print "event: " & event
  end select 
 
  if flags=0 then exit sub
  dim as string sFlags
  if (flags and CV_EVENT_FLAG_LBUTTON)  then sFlags &= "Left Button "
  if (flags and CV_EVENT_FLAG_RBUTTON)  then sFlags &= "Right Button "
  if (flags and CV_EVENT_FLAG_MBUTTON)  then sFlags &= "Middle Button "
  if (flags and CV_EVENT_FLAG_CTRLKEY)  then sFlags &= "[CTRL] Key "
  if (flags and CV_EVENT_FLAG_SHIFTKEY) then sFlags &= "[SHIFT] Key "
  if (flags and CV_EVENT_FLAG_ALTKEY)   then sFlags &= "[ALT] Key"
  print sFlags
  of=flags
end sub

cvNamedWindow("win") : cvResizeWindow("win",640,480)
cvSetMouseCallback("win",@cbMouse,NULL)

' loop with 10Hz while [ESC] not pressed
while cvWaitKey(1000/10)<>27
  ' ...
wend

cvDestroyWindow("win")
BasicCoder2
Posts: 3525
Joined: Jan 01, 2009 7:03

Re: libOpenCV Windows 32/64.bit Linux 64-bit

Postby BasicCoder2 » Mar 05, 2020 6:03

Again you show your knowledge and expertise!! Great work Joshy. Another wonderful gift to the FreeBASIC community. Hopefully I will eventually be able to test the Linux version as well with the RPi. I did notice I couldn't use the FreeBasic graphics with the main window. Much to learn I think before I can use the captured images with the routines I wrote that used escapi.bi
Thanks again and best wishes.
D.J.Peters
Posts: 8023
Joined: May 28, 2005 3:28
Contact:

Re: libOpenCV Windows 32/64.bit Linux 64-bit

Postby D.J.Peters » Mar 05, 2020 6:12

BasicCoder2 wrote:Hopefully I will eventually be able to test the Linux version as well with the RPi.
It's a Windows Linux X86 and X86_64 build not ARM !
For the Raspberry Pi you have to build OpenCV 2.4.13.6 on the Pi self.

You can download the source code from github see first post and build it with cmake.

Joshy
BasicCoder2
Posts: 3525
Joined: Jan 01, 2009 7:03

Re: libOpenCV Windows 32/64.bit Linux 64-bit

Postby BasicCoder2 » Mar 05, 2020 6:16

Ok. Thanks for the info. I haven't worked with the RPi for some time now and it has been collecting dust on the shelf while I played with some Arduino projects.
D.J.Peters
Posts: 8023
Joined: May 28, 2005 3:28
Contact:

Re: libOpenCV Windows 32/64.bit Linux 64-bit

Postby D.J.Peters » Mar 05, 2020 17:06

I added the Face tracking interface, the Eyes tracking Interface, the Mouth tracking Interface and last but not least the 3D tracking interface also.

Joshy
D.J.Peters
Posts: 8023
Joined: May 28, 2005 3:28
Contact:

Re: libOpenCV Windows 32/64.bit Linux 64-bit

Postby D.J.Peters » Mar 05, 2020 17:18

More than 200 views and I'm sure the half of them has a USB or integrated camera and no once get a feedback does it works or not.

Shame on you crazy BASIC coders :lol:

Again and again I spend a lot of time and do my best to create or make high quality stuff available for the community for free
but I have no time to test all the stuff for you guys !

Joshy
BasicCoder2
Posts: 3525
Joined: Jan 01, 2009 7:03

Re: libOpenCV Windows 32/64.bit Linux 64-bit

Postby BasicCoder2 » Mar 05, 2020 19:41

Perhaps they look out of curiosity not need? I don't remember any other FreeBASIC programmer having an interest in computer vision. There was a lot of interest in writing computer games when I first joined the forum. Writing code for a simple retro game in FB is something I could do. Writing a game anyone would want to play is another story.

My interests and ambitions have always well out stripped what I was ever capable of actually doing. Like an amateur artist thinking he could match the works of someone who had a natural talent and the time to hone their skills by long hours and years of practice.

Unlike 11 years ago when I first joined the forum I am no longer so passionate about programming and on the few occasions I feel motivated I have spent the time mostly with other languages relevant to some hardware projects using the RPi and the Arduino. It has always been a conflict deciding if to do something with FreeBASIC or use the Processing language or Python for which there are many tutorials and examples.

The truth is Joshy you are a brilliant, knowledgeable and prolific programmer compared with me. Even using the code you provide is an up hill battle. Still I am interested to see what I can do with the opencv code but it may take some time. It is 6:35am as I write this post. I will try and get some time tonight to test your Face tracking interface, the Eyes tracking Interface, the Mouth tracking Interface. This weekend will be taken up with family events.
badidea
Posts: 2007
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: libOpenCV Windows 32/64.bit Linux 64-bit

Postby badidea » Mar 05, 2020 20:56

Tying not to be one of those 200 lazy coders, but I ran into a problem: The symbolic links (linux version) seem broken after unzipping.
BasicCoder2
Posts: 3525
Joined: Jan 01, 2009 7:03

Re: libOpenCV Windows 32/64.bit Linux 64-bit

Postby BasicCoder2 » Mar 05, 2020 23:03

I can find 5 example programs:

capture_loop.bas
mouse01.bas 'tracking mouse positions?
test01A.bas
trackbar01.bas
trackbar02.bas

But not any face tracking, eye tracking?

Can't see how to transfer an image captured by opencv to a FreeBASIC bitmap or ulong array so I can access the pixel data in a FreeBASIC program?

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 2 guests