Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Webcam capturing without saving the image to HDD

Author
Message
C0wbox
19
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 7th Nov 2010 18:46 Edited at: 7th Nov 2010 18:53
Hai peoples,

I've done some searches on the forums for capturing data from a webcam and I can't seem to find what I'm looking for.

I found 2 reasonable methods but both have their drawbacks:

Method 1 was to use dbpcap.dll by Jukuma but this not only crashes when closed, it also doesn't seem to like being syncd and appears not to be rendering it through a proper method like sprites or images. (However it works in DBP) So I can't use point on the capture area or display anything else with the capture area.

Method 2 was to use windows DLLs to save the image to HDD and reload it before rendering. (Via DLLs like avicap32.dll and user32.dll) (Original code found through searching in threads like this)

So far I've been using method 2 but because my camera was on its last legs I just went out and bought a new 1 (with double the resolution). Doubling the resolution is making the program lag and I hate to think of the damage it's doing to my hard drive, constantly reading and writing to it. See full code here:
(It basically just tells me the RGB parts of the centre of the picture)

So my question really is, how can I achieve the same effect as the program in that code does, without constantly reading and writing a file. - I.E. How can I get DBP to directly access the webcam output.

Thanx

(If I get this all working, I intend to use it to experiment with augmented reality AI and things. - I built a frame out of deodorant cans and a ruler to hold my webcam above a black mousemat. ):


Attachments

Login to view attachments
C0wbox
19
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 11th Nov 2010 03:48
I guess no one uses DBP for anything but making games huh?

C0wbox
19
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 24th Nov 2010 16:41
?

Howcome other people get responses for this kinda thing. xD

I still have this stoopid rig set up on the side of my desk in the vain hope I might get it working one of these days.

baxslash
Valued Member
Bronze Codemaster
18
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Nov 2010 17:14
Sorry CB, maybe nobody knows?

I've never used it for such, however I may look into it as it might come in useful for a netbook game or two...

I'll let you know if I end up using any webcam stuff

sladeiw
16
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 24th Nov 2010 17:33 Edited at: 24th Nov 2010 17:40
I cobbled this together by modifying your code to copy a frame to the clipboard, and then copy the image to a memblock using a function I'm writing. It works but it's still buggy and dosen't handle all kinds of bitmap. Frame rate was much better on my pc using a Microsoft VX-5000 webcam. Hope that helps!

HowDo
22
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 24th Nov 2010 17:36
Not sure if this will help, Like you I seen all thses attemps to make a webcam work with DBP, some work but crash on exit or do not start.

now my thinking is that every webcam out there has a different driver but all the programes that use a webcam probaly use the same code to do there trick, meaning programs like AIM Yahoo im, Google talk/webcam must be talking to part of driver and connect though that bit.

just thinking out loud, might get someone to think AH that how you could do it.

cheers.

Dark Physics makes any hot drink go cold.
Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 24th Nov 2010 18:28
I've used avicap from DBPro with no problems before. It doesn't require saving to the hard drive. However, I wrote a C++ wrapper for it as a plugin, I didn't call the commands directly from DBPro which would be more difficult. I'm afraid that the plugin was not really releasable, as it was tailored specifically for what I needed the images for. I may be able to help if you need to understand the API though.

[b]
C0wbox
19
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 25th Nov 2010 00:00 Edited at: 25th Nov 2010 00:04
! Everyone suddenly helped at once. xD Thanks guys

@ baxslash
Undoubtedly we'll see each other in the WIP board about all this some day. (That's if I ever make a WIP for this WOR is still my priority though, I was just messing with this on the side.)

@ sladeiw
Thanks man, I'll maybe have a sift through the code in a bit.
EDIT:
Fail, I tried the code but it's moaning about the word peek (lines 126 - 130) - Is this from another command set or a newer version of DBP? (I see a poke as well further down, I'm unfamiliar with these commands xD)

@ HowDo
Yeah, you'd think there'd be some kind of standard way for apps to read camera data that all the major companies making IMs and things know about. Some of the attempts to access webcam stuff seem to be bordering on a reliable method but still lack things.

@ Diggsey
Well, if sladeiw's code is what I need then you're probably safe for now, but you could always see about making a plugin for DBP using some of that. They've made DarkInk - why not DarkCam too?

sladeiw
16
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 25th Nov 2010 00:05
Sorry, forgot to mention those commands are from IanM's matrix1 plugin.
C0wbox
19
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 25th Nov 2010 01:34 Edited at: 25th Nov 2010 02:07
@ sladeiw
K, I'll look into getting that sorted.

(I've never had to use memblocks, words and dwords so I'm unfamiliar with a load of that code xD)

EDIT:
!!!! I can't believe how nicely it works now.

Now I've just gota figure out a quicker way to check colour values than point. xD - But I'll leave that for the time being (unless anyone can suggest something straight out) it's fast enough for me to be able to work with it.

I was going to include a picture of what the app does now, but I used Prt_Scrn to get it... xD! - All I got was what the clipboard was being spammed with. (Funny that )

Regardless, this new version basically splits up the picture into a number of segments and checks for red at set places in the image according to the number of X and Y segments and moves a little box to wherever the red is. - Previously it would clonk out at about 4x4 divisions, but I just tested it at 16x16 and it was smooth as anything.

Mugen Wizardry
User Banned
Posted: 25th Nov 2010 06:52
Can somebody stop this stupid thing from crashing when u dont have a webcam plugged in plz & thx?

That has been driving me crazy for YEARS.

LOL XD

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Neuro Fuzzy
18
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 25th Nov 2010 06:57
Image to memblock might be faster than point. Just change your image to a memblock, then figure out the color at the point

sladeiw
16
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 25th Nov 2010 12:36
All the getclipboard function does is copy the data from a clipboard image to a memblock (creating the memblock image header info). Then you can use `make image from memblock`. So if you don't actually need the webcam picture as a dbpro image you can sidestep all that completely and as neuro fuzzy said, just get the rgb values directly from the clipboard image data.
I can post an example when I get home if you want one, no webcam at work.
C0wbox
19
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 25th Nov 2010 14:26 Edited at: 25th Nov 2010 15:08
@ Mugen Wizardry
I think you can do that with just ordinary code and DLL calls. - I'm sure I saw a way to find out the numbers of webcams plugged in, so you could just make it quit or show an error before trying to use a webcam that's not there.

But as I'm using this mainly for testing augmented reality and AI at the moment I'm just going to assume I always have my cam plugged in.

@ Neuro Fuzzy & sladeiw
Aye yeah, it sounds like that's what I'm after, and it would be faster than point for sure, but I have never used memblocks so I don't really know what they are, let alone how to use them.
(In all the projects I've made I've never ever had to use memblocks )

Sidenote - If I'm using this for augmented reality and AI I'd prefer to do the processing on the memblock but still have a live image for the user to view things with. - But that won't be any trouble to achieve.

Pics and stuff

I just felt like taking some pics
(It just illustrates (badly) the red blob onscreen follows where the pointy device thing's red square goes in the camera's viewing area.)

I used
Yellow Bluetack !
Blue Bluetack !
A mousemat !
An MS HD 5000 webcam because my previous James Bond minicam sucked balls, so I went out and bought a new 1 specially for this !
A 30cm metal ruler !
2 cans of Lynx Click !
A cable tie ! - For the pointy-device
A small square of red cardboard cut from the packaging of the new webcam - For the end of the pointy-device

Hockeykid
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 25th Nov 2010 17:15
Hmm,
I would love to try this and help out a bit but for some reason GetClipboardData is returning a handle of 0. Anyone know why?

C0wbox
19
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 25th Nov 2010 18:28
@ hockeykid
You obviously have no clipboard. xD

sladeiw
16
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 26th Nov 2010 10:45
I looked at the avicap functions a bit more and it looks very restrictive. (Like having to have a preview window open) Maybe someone else would know with more experience using it how you can just copy the bitmap (dib) from the capture window to your own memblock. (I tried GetDC then GetPixel which works but that is also slow for lots of pixels) Diggsey sounds favourite

@hockeykid - No handle means couldn't provide the clipboard data in the requested format. (Unless it fails on the first call to open the clipboard which could mean it's locked to another process) Possibly the webcam image format, I don't really know sorry.
C0wbox
19
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 29th Nov 2010 22:26
! Right, well, I can get a red dot to follow a real red dot around a mouse mat, onto Kinectimals.

First I think I should learn how to use memblocks

Anyone wana link me to a tutorial or something based on the fact I only really need to be able to understand how to access colour information from the clipboard data retrieved in the code sladeiw provided.

Original code snippet:


The code for my application (which makes a red dot follow a red square around on a black background):


!

sladeiw
16
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 30th Nov 2010 00:21 Edited at: 30th Nov 2010 00:27
Here's a simple example:



Just search the forum for `memblock` and other people have created tutorials and image manipulation examples.

edit: Even simpler, a quick function to get a pixel from a memblock. (Which you can then use rgbr/rgbg/rgbb to get colours from) Remember that memblocks store pixels as BGR not RGB

WizardP
14
Years of Service
User Offline
Joined: 20th Dec 2010
Location: UK
Posted: 21st Dec 2010 04:29
Thanks COwbox and everyone else, you've just pre-empted one of my needs for a college project, saving me a lot of heartache trying to import live camera feed.
Recently learnt to use memblocks myself, quite easy once you get the hang of them, and so much quicker for getting pixel data from.
Cheers everyone
C0wbox
19
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 21st Dec 2010 12:38
Aye, I started this because I figured I could use it later on in university (I'm only in first year at the moment, so nothing interesting happens) but when it comes time for projects I'll dig this up again. !

WizardP
14
Years of Service
User Offline
Joined: 20th Dec 2010
Location: UK
Posted: 31st Dec 2010 05:28
Useful stuff - do any of you have a fuller list of the function codes available (ie a list of all possible 1024+ codes for avicap32)?
Many thanks if you can help
WizardP
14
Years of Service
User Offline
Joined: 20th Dec 2010
Location: UK
Posted: 31st Dec 2010 05:44
Hi,
Anyone have a longer list of the codes for avicap32? (what other internal functions can be called with the codes 1024+).
Many thanks
WizardP
14
Years of Service
User Offline
Joined: 20th Dec 2010
Location: UK
Posted: 31st Dec 2010 05:44
Hi,
Anyone have a longer list of the codes for avicap32? (what other internal functions can be called with the codes 1024+).
Many thanks
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 31st Dec 2010 13:45
M M M M M M M M MULTIPOST! lol

My signature is NOT a moderator plaything! Stop changing it!
C0wbox
19
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 31st Dec 2010 19:21
Yeah seriously WizardP, don't bump threads like that... I'm pretty sure it's against the rules (or the law or something xD)

WizardP
14
Years of Service
User Offline
Joined: 20th Dec 2010
Location: UK
Posted: 19th Jan 2011 00:16
Hi Folks,
Sorry about that I was working on a flaky connection which kept cutting me off; had assumed the message had not been posted when in fact it was held with moderator.
Got my webcam linked in nicely, thanks.

Login to post a reply

Server time is: 2025-06-24 06:07:28
Your offset time is: 2025-06-24 06:07:28