Webcam init and get

F

frakie

Hi there,
I need a simple and stupid few line source code to access my webcam.
I found lots of huge projects (c++ c and other) which are so big that
they are impossible to be used.
Does somebody know how to manage a webcam from it's basic functions?
Where can i find a SIMPLE, VERY SIMPLE example project?
Doesn't matter the what is the OS or the language, i just need it is
easy portable source code...
 
W

Walter Roberson

frakie said:
I need a simple and stupid few line source code to access my webcam.
I found lots of huge projects (c++ c and other) which are so big that
they are impossible to be used.
Does somebody know how to manage a webcam from it's basic functions?
Where can i find a SIMPLE, VERY SIMPLE example project?
Doesn't matter the what is the OS or the language, i just need it is
easy portable source code...

You will not be able to find "easy portable source code", as
not all systems provide enough functionality to be able to control
webcams, or provide the functionality in very different ways.
For example on the system I am using right now, it is possible to
add a webcam... if you add in a digital I/O board, the webcam
for which uses a 75 pin connector and transfers data in parallel.
Meanwhile there are ethernet based webcams and USB based webcams
and probably serial and parallel based webcams as well, all of which
need to be controlled in very different ways.

The most common webcams these days are ethernet based or USB based.

The ethernet based ones are often accessible via TCP -- which requires
that the system you are working on has a TCP stack, which is by no
means guaranteed (though it is getting increasingly common except in
some kinds of embedded systems.) The access to such systems is via
an HTTP transaction; that does not require a full HTTP library, but
does require an HTTP framework, complete with some MIME parsing.
Typically to get an image, you would issue an HTTP GET against
a particular file on the system and it would return it in encoded
form. But controlling the camera would generally require HTTP POST
transactions.

The USB cameras... well, those require a USB interface library,
which is going to be operating system dependant.


You might find that someone has written Perl modules and posted
them at cpan.org and you might find that those modules work
for all of the kinds of systems you are interested in. But then
you face the problem that installing Perl itself can be a bear of
a job if you have to install it from source.
 
F

frakie

You will not be able to find "easy portable source code", as
not all systems provide enough functionality to be able to control
webcams, or provide the functionality in very different ways.
For example on the system I am using right now, it is possible to
add a webcam... if you add in a digital I/O board, the webcam
for which uses a 75 pin connector and transfers data in parallel.
Meanwhile there are ethernet based webcams and USB based webcams
and probably serial and parallel based webcams as well, all of which
need to be controlled in very different ways.

The most common webcams these days are ethernet based or USB based.

The ethernet based ones are often accessible via TCP -- which requires
that the system you are working on has a TCP stack, which is by no
means guaranteed (though it is getting increasingly common except in
some kinds of embedded systems.) The access to such systems is via
an HTTP transaction; that does not require a full HTTP library, but
does require an HTTP framework, complete with some MIME parsing.
Typically to get an image, you would issue an HTTP GET against
a particular file on the system and it would return it in encoded
form. But controlling the camera would generally require HTTP POST
transactions.

The USB cameras... well, those require a USB interface library,
which is going to be operating system dependant.

You might find that someone has written Perl modules and posted
them at cpan.org and you might find that those modules work
for all of the kinds of systems you are interested in. But then
you face the problem that installing Perl itself can be a bear of
a job if you have to install it from source.

Thank you very very much Walter!
I know there must be an interface to interact with, but everything I
found is really too confusing since each project is adding more
functions than just init and getImage...
I will try cpan.org Perl module, and I'll tell you! Really thanks!
 
D

domen

You might also want to look at Gstreamer. While the framework is
portable, I don't know about webcam support for operating systems
other than Linux (v4l2src worked great for me in some project).
The big advantage is that changing from reading webcam stream to
reading video file is just a few lines (and this can be very useful in
testing!).

Domen
 
S

Stefano Sabatini

Hi there,
I need a simple and stupid few line source code to access my webcam.
I found lots of huge projects (c++ c and other) which are so big that
they are impossible to be used.
Does somebody know how to manage a webcam from it's basic functions?
Where can i find a SIMPLE, VERY SIMPLE example project?
Doesn't matter the what is the OS or the language, i just need it is
easy portable source code...

You could consider using libavdevice from ffmpeg, video4linux and
video4windows should be supported, it is plain and portable C (but not
trivial to use, but that's the price you have to pay to deal with
multimedia).

Regards.
 
W

Walter Roberson

You could consider using libavdevice from ffmpeg, video4linux and
video4windows should be supported, it is plain and portable C (but not
trivial to use, but that's the price you have to pay to deal with
multimedia).

http://cekirdek.pardus.org.tr/~ismail/ffmpeg-docs/v4l2_8c-source.html

#include "config.h"
#include "libavformat/avformat.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <asm/types.h>
#include <linux/videodev2.h>
#include <time.h>


That's not portable C !

C89 3.8.2 Source File Inclusion
[...]
There shall be an implementation-defined mapping between the
delimited sequence and the external source file name. The
implementation shall provide unique mappings for sequences
consisting of one or more letters (as defined in 2.2.1) followed
by a period (.) and a single letter. The implementation may ignore
distinctions of alphabetical case and restrict the mapping
to six significant characters before the period.


Now "libavformat/avformat.h" has more than six significant characters
before the period, so which, if any, file that will map to is
implementation-defined -- and thus not portable C.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top