OpenCV to capture an image with a webcam?

General FreeBASIC programming questions.
Post Reply
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

OpenCV to capture an image with a webcam?

Post by BasicCoder2 »

Is it possible to use OpenCV to capture webcam images for use in a FreeBASIC program?
At the moment I am using escapi.bi and escapi.dll but they are window's dependent and I would like to do the same with the Linux os.
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: OpenCV to capture an image with a webcam?

Post by badidea »

Maybe possible with libVLC? viewtopic.php?f=14&t=24028
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: OpenCV to capture an image with a webcam?

Post by BasicCoder2 »

Downloaded the folder from SourceForge into my FreeBASIC folder.
Ran Joshy's example but it failed.
Looks like I have some google exploring to do or just forget about using FreeBasic with Linux and just using Processing or Python which is well supported in this area.


Command executed:
"C:\FreeBasic\fbc.exe" "C:\FreeBasic\simplest_libvlc_example\vlcTest.bas"

Compiler output:
C:\FreeBasic\bin\win32\ld.exe: cannot find -lvlc

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 1.05.0 (01-31-2016), built for win32 (32bit)
OS: Windows NT 6.2 (build 9200)
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: OpenCV to capture an image with a webcam?

Post by badidea »

What does locate libvlc.so say?

Here:
/usr/lib/x86_64-linux-gnu/libvlc.so
/usr/lib/x86_64-linux-gnu/libvlc.so.5
/usr/lib/x86_64-linux-gnu/libvlc.so.5.6.0


And if I check with ls -l /usr/lib/x86_64-linux-gnu/libvlc.*
lrwxrwxrwx 1 root root 15 Sep 11 13:39 /usr/lib/x86_64-linux-gnu/libvlc.so -> libvlc.so.5.6.0
lrwxrwxrwx 1 root root 15 Sep 11 13:39 /usr/lib/x86_64-linux-gnu/libvlc.so.5 -> libvlc.so.5.6.0
-rw-r--r-- 1 root root 153512 Sep 11 13:39 /usr/lib/x86_64-linux-gnu/libvlc.so.5.6.0

Which tells me the version.

On Ubuntu, I can say sudo apt-get install libvlc
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libvlc


I check with the "Synaptic Package Manager" (first thing to install on a new Ubuntu install), I see that it is named libvlc5

So, sudo apt-get install libvlc5
Reading package lists... Done
Building dependency tree
Reading state information... Done
libvlc5 is already the newest version (3.0.8-0ubuntu18.04.1)
...


I have tried something (play a movie clip, not with a webcam) with libvlc some time ago, it worked. Probably only with 64-bit fbc, as I don't have libvlc5:i386 installed here.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: OpenCV to capture an image with a webcam?

Post by BasicCoder2 »

Sorry brain glitch!! I had been trying to compile it on windows10.

It has been some time since I last ran a FreeBASIC program on the RPi and my knowledge and experience with Linux has been very limited. The example code and vlc download stuff was on a ram stick. The Linux directory system is a little different to Windows and it took time to find the ram stick in the directory. Anyway I eventually ran the code example with this result:

fbc -w all "vlcTest.bas" (in directory: /media/pi/C6DB-5276/simplest_libvlc_example)
vlcTest.bas(4) error 23: File not found, "vlc/vlc.bi" in '#include once "vlc/vlc.bi"'
Compilation failed.

I was unable to locate the vlc.bi

Looks like I am going to have to spend time relearning and extending my knowledge of Linux on the RPi. As I get older I find remembering new things and recalling them later is becoming more difficult!
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: OpenCV to capture an image with a webcam?

Post by badidea »

I cannot remember the details when I tried libvlc, but vlc.bi seems to bee in the freebasic installation since at least version 0.90.0:

Code: Select all

 locate vlc.bi
/home/badidea/Downloads/FB/FreeBASIC-0.90.0-source/inc/vlc/libvlc.bi
/home/badidea/Downloads/FB/FreeBASIC-0.90.0-source/inc/vlc/vlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.05.0-linux-x86/include/freebasic/vlc/libvlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.05.0-linux-x86/include/freebasic/vlc/vlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.05.0-linux-x86_64/include/freebasic/vlc/libvlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.05.0-linux-x86_64/include/freebasic/vlc/vlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.06.0-linux-x86_64/include/freebasic/vlc/libvlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.06.0-linux-x86_64/include/freebasic/vlc/vlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.07.0-linux-x86/include/freebasic/vlc/libvlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.07.0-linux-x86/include/freebasic/vlc/vlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.07.0-linux-x86_64/include/freebasic/vlc/libvlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.07.0-linux-x86_64/include/freebasic/vlc/vlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.07.0-source/inc/vlc/libvlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.07.0-source/inc/vlc/vlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.07.1-linux-x86/include/freebasic/vlc/libvlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.07.1-linux-x86/include/freebasic/vlc/vlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.07.1-linux-x86_64/include/freebasic/vlc/libvlc.bi
/home/badidea/Downloads/FB/FreeBASIC-1.07.1-linux-x86_64/include/freebasic/vlc/vlc.bi
/usr/local/include/freebasic/vlc/libvlc.bi
/usr/local/include/freebasic/vlc/vlc.bi
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: OpenCV to capture an image with a webcam?

Post by BasicCoder2 »

Where did you type locate vlc.bi ?
All I can find in my FreeBasic folder is fbc_linux_armv7a_hf_debian
The bin, doc, inlcude and lib folders seem empty.
The vlc.bi is in the Windows version of FreeBasic.
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: OpenCV to capture an image with a webcam?

Post by badidea »

BasicCoder2 wrote:Where did you type locate vlc.bi ?
At the terminal. But I don't know anything about RPi's.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: OpenCV to capture an image with a webcam?

Post by BasicCoder2 »

Thank you for your responses.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: OpenCV to capture an image with a webcam?

Post by D.J.Peters »

download freebasic_additional_headers.zip from here http://users.freebasic-portal.de/stw/builds/

unzip it and copy the folder inc over your FreeBASIC include folder

or copy only the inc/vlc folder to you FreeBASIC include folder

Joshy
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: OpenCV to capture an image with a webcam?

Post by BasicCoder2 »

Thanks Joshy I will give it a try later.
JohnK_RQ
Posts: 27
Joined: Nov 25, 2019 1:50

Re: OpenCV to capture an image with a webcam?

Post by JohnK_RQ »

I have used opencv from fb but might be too much work:

Write opencv code in C++ but Use export Dll functions to expose to fb. Fb calls the dll functions and it loads bitmap memory, you then blit to your form.

My actual implementation was Rapidq forms > fb c wrapper > DLL with c++ code. Sounds complicated but worked great.

Direct from fb will be nearly impossible because of c++ vector types and c++ templates. The good news is that working opencv code is everywhere

Sorry the code is not for sharing. :(
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: OpenCV to capture an image with a webcam?

Post by D.J.Peters »

BasicCoder2 wrote:... At the moment I am using escapi.bi and escapi.dll ...
Do you use escapi3 the 64-bit version on Windows 10 ?
(I can't use my cameras on 64-bit windows)

https://sol.gfxile.net/escapi/index.html

Joshy
JohnK_RQ
Posts: 27
Joined: Nov 25, 2019 1:50

Re: OpenCV to capture an image with a webcam?

Post by JohnK_RQ »

This is not native FB code but is relevant if you want to interface FB to OpenCV. FB and RQ are very similar except for GUI

I have uploaded my QOpenCV DLL and interface to the public. It uses the OpenCV 2.2 library (32-bit). This is a powerful image processing library that allows video playback and webcam capture. I uploaded the old library to be compatible with windows XP (32-bit), so that means modern webcams may not be supported!. It comes with pre-compiled binaries and C++ source code.in case you want to compile your own with the updated OpenCV library

You will find it here:
http://rapidq.phatcode.net/examples/vid ... istrib.zip

and the readme here:
http://rapidq.phatcode.net/examples/video/ReadMe.txt

Enjoy
JK
Post Reply