PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

How to use the camera as the input?

I am the new one to study edgelib. I do not know how to use the camera as the input.

I am using Windows desktop workstation and one camera. I am going to create a small game using the camera. Any example code? Thank you.
:( no one helps me :?:
Lol? :P
Why did you laugh at me? I need to finish this as my final project. Sign, too cold here.
Hi Gar,

Camera capturing is currently not supported by EDGELIB. You need to program your own camera capturing module using DirectShow, a sample is available here: http://www.codeguru.com/cpp/g-m/directx ... php/c7243/

When you're able to capture camera images, you can lock the backbuffer and manually copy the pixel data to the surface.
helo gar

yuo could also try existing technology like gesturetek: http://www.gesturetekmobile.com

good lcuk!!

petre
I can capture camera images now, but the type is char.
How can I copy them to the surface? Is it using the following?
ERESULT CreateSurface(E2DSurface *surface, void *imgmem, unsigned long memsize, unsigned long usetype = EST_DEFAULT)

If so, how can I get the memory size?

Thanks.
Hi Gar,

Is the data returned a char or char *? If it's a char *, you can copy it to an EDGELIB surface. To determine the size of the picture you need to find out it's width, height and bitdepth. If you have a pitch member as well, we recommend using that instead of width (because the pitch can be larger when it padds memory on each scanline).

Here is a sample to copy data to an EDGELIB surface:

Code:

E2DSURFACEINFO info;
unsigned char *memptr = surface.Lock(&info);
if (memptr)
{
E2DSURFACEINFO info;
unsigned char *memptr = surface.Lock(&info);
if (memptr)
{
unsigned long yctr;
for (yctr = 0; yctr < cameraimage_height; yctr++)
{
ClassEMemory::Copy(&memptr[yctr * info.realpitch],
&cameraimage_memory[yctr * cameraimage_pitch],
cameraimage_width * cameraimage_bitdepth / 8);
}
surface.Unlock();
}
}


The cameraimage_ variables need to be replaced by your own variables to determine the properties of the captured image. The EDGELIB surface width and height should be equal or greater than the width and height of the camera image (otherwise it writes outside of its allocated image memory).
Thank you, Edge.

The data returned is a char *, and I do not have a pitch member. I have modified the code you gave to me.

The result is not what I expected. You can easily to see the difference between two images as below. The first image is the 320 X 240 (RGBA)which from the camera. The second one is from the program. They should be the same, but they are quite different.

According to the width, some parts are missing, and divided into 4 parts. Some of the height parts are still missing.
Image

Image

Image



unsigned char *memptr = background.Lock(&info);
if (memptr)
{
unsigned long yctr;
for (yctr = 0; yctr <= (unsigned long)cparam.ysize; yctr++){
ClassEMemory::Copy(&memptr[yctr*info.width],&dataPtr[yctr*cparam.xsize],cparam.xsize*32/8);

}
background.Unlock();
}
DrawBackground(display);


cparam.ysize - height of the image (in pixels).
cparam.xsize - length of the image (in pixels).

I also find that info.width=256. info.height=256.
Therefore,the width is smaller than 320, and the height is larger than 240.

How can I fix such problem?

Thank you so much.
Hi Gar,

The info structure is returning the width and height of your background surface. Did you specify a size of 256x256 to the CreateSurface call?

Also, change your memcopy routine to this:

Code:

ClassEMemory::Copy( &memptr;[yctr * info.realpitch], &dataPtr;[yctr * cparam.xsize * info.bitwidth / 8], cparam.xsize * 32 / 8 );
Hi Edge,

Thank you so much. I used the background image which is 256 X 256.
if (display->CreateSurface(&background;, "background.jpg") != E_OK)
return (E_ERROR);

I changed it to
if (display->CreateSurface(&background;, 320,240) != E_OK)
return(E_ERROR);

It works, is it correct? Do I need to modify some code in DrawBackground(ClassEDisplay *display)?
Because I am not quite understand this function.

void ClassMain::DrawBackground(ClassEDisplay *display)
{
#if defined(EGL_USEGL)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
display->Perspective2D(256, 256, false);
//display->Perspective2D(320, 240, false);
display->BltFast(0, 0, &background;, NULL);
#else
E2DBLTFX bltfx;
bltfx.flags = 0;
bltfx.property = 0;
bltfx.xscale = 65536 * display->buffer.GetWidth() / background.GetWidth();
bltfx.yscale = 65536 * display->buffer.GetHeight() / background.GetHeight();
bltfx.rotation = 0;
bltfx.flipflags = 0;
display->buffer.BltFx(display->buffer.GetWidth() / 2, display->buffer.GetHeight() / 2, &background;, NULL, &bltfx;);
#endif
}


Thank you so much!
Hi Gar,

Are you using OpenGL? If not, you can remove the #ifdef EGL_USEGL and the code between them. This makes your code more readable.

Because the image doesn't need to be stretched (because it has the same size as the screen, 320x240), you can make a simple call to BltFast:

Code:

display->buffer.BltFast(0, 0, &background;, NULL);
Thank you, Edge.