Capturing camera with video for windows
recantly ive bought myself small pc camera from creative. ive done some simple experiments using it with flash, where it is easy to create nice effects with just a litte work. mainly i wanted to reproduce incopmet.com experiments. but ive found something that could be more interesting.
my idea was to write application using VfW (video for windows) to capture camera image. in MSDN we can read that it is possible to manipulate image from camera before it is displayed in capture window. this can be done by setting frame callback function, that can be registered for a specified capture window using capSetCallbackOnFrame macro (defined in wfv.h). to use this macro we need to define call back function
LRESULT CALLBACK capVideoStreamCallback(HWND hWnd, LPVIDEOHDR lpVHdr)that we will use to manipulate camera image. second parameter of our function contains image data we want to work on. to manipulate frame we need to know the image format used by camera (that is how many bits are used to define single color). to get this information we can use this function :
DWORD capGetVideoFormat( HWND hwnd, LPBITMAPINFO psVideoFormat, DWORD wSize )here is sample image that has been created using my minimal camera capture application


GCC and functions name mangling
my latest discovery is that gcc in linux does not prepend underscore at the beginning of the names of funcitons, while windows port of gcc compiler does that.
cygwin : gcc -S ble.c
_main: pushl %ebp ... |
linux : gcc -S ble.c
main: pushl %ebp ... |
absence of underscore at the beginning of the name is important when you are trying to use code written and compiled under windows with gcc, or when you write assembler code and compile it with NASM (like in my previous post), this is also way how ive discovered this :) to use function that had been written in assembler and compiled with NASM in my c code (gcc in cygwin, borland) i had to declare it (in asm source) with underscoped name. because both gcc in cygwin and borland expects functions written in c to be preceded with underscore. but when i've tried to compile the same code with gcc under linux i got linker error (underscore)
to use the same assembler code in windows and linux i had to declare function with leading underscore (in linux), or to use
asm() keyword to specify the name to be used in asm code (gcc manual page 281).
i think, the best solution is to add defines so that functions can be imported properly (with underscore) but used in code without it.GCC under linux by default does not add prepend uderscore at the beginning of the function name.
Assembly code in GNU g++
First of all GNU compilers use AT&T assembly syntax, not Intel. Secondly writing inline assembly isnt easy thing to do, especially when you are familiar only with intel syntax. when you need to write function using assembly (for example for complex numbers calculations) there is a better solution, when using inline assembly. As an example i will show sqr function to calculate double number to the power of 2. Assembler code can be seen below, note that doubles are returned via fpu stack
section .text use32 global _sqr _sqr: push ebp mov ebp,esp fld qword [ebp+08h] fmul to st0 pop ebp retassuming that we have saved this code in file fpu.asm, we can compile it using NASM as follows
nasm -f coff fp u.asm (in cygwin)
nasm -f elf fpu.asm (in linux)
this was the first part.. the second is to create code in c++ using our external sqr function, for example:
#include <stdio.h>
extern "C"
{
cpx tst1( const cpx c );
}
int main()
{
double d = 2.0;
printf("%f %f",d,sqr(d));
return 0;
}
to compile this code using g++ compiler we need to pass previously compiled assembler code to the linker.
g++ fpu.o tst.cpp
C++ class in assembler
#include <cstdio> class baseObj { public : int i; baseObj(int o) { i = o + 32; }; }; class childObj : public baseObj { public : childObj(int i):baseObj(i){} }; int main() { baseObj a = childObj(16); a.i += 64; printf("go %d",a.i); };i was expecting (in the time when i was writing this code) compiler to create two functions, that would carry out my constructors. [read more]
previous (newer) , 1 , 2 , 3 , 4 , 5 , 6 , ... , 9 , next (older)