Webcam game, like Eye Toy Camera of PSX2

Developed or developing a new product in PureBasic? Tell the world about it.
BalrogSoft
Enthusiast
Enthusiast
Posts: 203
Joined: Sat Apr 26, 2003 6:33 pm
Location: Spain
Contact:

Webcam game, like Eye Toy Camera of PSX2

Post by BalrogSoft »

Hi...
im developing a game like Eye Toy of PSX 2, Eye Toy is a game that uses a USB camera for PSX 2 and you interact with the game, you are the player, with the avi capture code ported by James, the program gets all objects that dont exist on a previous captured image of the background without the player, and gets some pixels where the movement is detected, in the window the objects that dont exist on background are drawed on red color, and motion detection on green color, exists two options, Chroma range that is the range of color to eat the background, and noise detection eliminate some pixels noise, change this values to get a similar images that the screenshot. With F1, F2, F3 you can
enable or disable the previews of motion detection image, objects detection, and background chroma image, this are only usefull when you must configure the chroma and the noise. If you move the camera when you are playing press f12 to get a new background image, but you must not appear on the image. The game dont use the motion detection, only the objects detection, but the motion detection will be usefull for future games to detect if you attack or if you are touched by an enemy.

Download here: http://www.balrogsoftware.com/kosas/icamgame.zip

and a screenshot for users that dont have a webcam:
Image

The source isnt available, i must optimize the code a little more...

Bye, and enjoy.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

great, that's an original project...
Take us informed !
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
plouf
Enthusiast
Enthusiast
Posts: 281
Joined: Fri Apr 25, 2003 6:35 pm
Location: Athens,Greece

Post by plouf »

it starts shows a picture in the down left box and crash immediatly :(
(wnXP home )
Christos
BalrogSoft
Enthusiast
Enthusiast
Posts: 203
Joined: Sat Apr 26, 2003 6:33 pm
Location: Spain
Contact:

Post by BalrogSoft »

Try a new version, now its a little game, with points and life, and now you can select the capture driver, for people that have differents video capture devices, the keys are the same, but now with f10 you can start the game.

http://www.balrogsoftware.com/kosas/icamgame.zip

bye.
hteamspy
User
User
Posts: 12
Joined: Mon May 05, 2003 4:54 pm
Location: Aix en provence
Contact:

It don't works

Post by hteamspy »

:cry: The project starts, I choise my webcam on the list box, then when I clik on OK it crash...

I'am on Win Xp : Pro

Thx for your project

Spy
Toris
User
User
Posts: 16
Joined: Mon May 05, 2003 6:59 pm

Post by Toris »

Yep, the same happens for me (crashes once I've selected my webcam), I hope you fix this bug though, it sounds interesting...

I was once going to do something along the lines of this, when I found out about all the security motion detection software you can use your webcam for, but never got round to it, so it will be interesting to see what you come up with :)

[EDIT] I'm using Win2k Pro [/EDIT]
BalrogSoft
Enthusiast
Enthusiast
Posts: 203
Joined: Sat Apr 26, 2003 6:33 pm
Location: Spain
Contact:

Post by BalrogSoft »

Hi...

Try to download again, i upload a new update, i make changes to be sure that the camera is showing the preview image before any access to image of webcam, the link is the same:

http://www.balrogsoftware.com/kosas/icamgame.zip
Toris
User
User
Posts: 16
Joined: Mon May 05, 2003 6:59 pm

Post by Toris »

Nope, unfortunately it still crashes.

I open it up, select my webcam, about half a second passes, and the window turns into a large (about 800x600?) window, then it crashes. "iCamGame has generated errors, and will be closed by windows"

Still, good luck :)
BalrogSoft
Enthusiast
Enthusiast
Posts: 203
Joined: Sat Apr 26, 2003 6:33 pm
Location: Spain
Contact:

Post by BalrogSoft »

This is the last test that i make, if dont work after this, i will send to you the source code to say me where is located the error. But i think that i found the error on the arrays where the movement tracking is stored, the problem, an array outs of bounds, i think this for the info about the window size more than 800*600, the arrays accept 320*240, i put now 640*480 as max size, but if works now, i recommend to click on format menu and take a small size like 176x144 or 320x240, because the program is optimized to 176x144 at the moment... the download link is the same....

bye...
Toris
User
User
Posts: 16
Joined: Mon May 05, 2003 6:59 pm

Post by Toris »

Yep, that's done it :)

I can now see the webcam output, and the motion detection, but the game part, appeared once, in the bottom right corner of the window, but seems to have disappeared now :?

Looking good :)
BalrogSoft
Enthusiast
Enthusiast
Posts: 203
Joined: Sat Apr 26, 2003 6:33 pm
Location: Spain
Contact:

Post by BalrogSoft »

The image in the bottom right corner is really the motion detection, and the image on the top right corner is the object detection, the game image are located on center, now you must take a background image with f12, you dont must appear on the background image (the background image is located on bottom left corner), after this configure chroma and noise, and then press f10 to start the game... when you will start the game to get more fps, disable with f1, f2 and f3 the background, object detection, and motion detection image preview, this is only to help you to configure the chroma, and disable preview on Control menu.
hteamspy
User
User
Posts: 12
Joined: Mon May 05, 2003 4:54 pm
Location: Aix en provence
Contact:

I'am Ok

Post by hteamspy »

Now it works, I don't see the little bug to catch but i saw me on the screen

Great

Spy
Ralf
Enthusiast
Enthusiast
Posts: 203
Joined: Fri May 30, 2003 1:29 pm
Location: Germany

Re: I'am Ok

Post by Ralf »

the application crash every time on my win2k machine and i dont know why :? is there any source available for testing purposes? can someone post an example how to catch the images direct from webcam for comparing i.e.?
BalrogSoft
Enthusiast
Enthusiast
Posts: 203
Joined: Sat Apr 26, 2003 6:33 pm
Location: Spain
Contact:

Post by BalrogSoft »

Hi Ralf...
first you must be sure that your camera works with the video capture source of hi-toro, search on this forum for video capture and download it, before, you must remove on avicapincs.pb the procedure called StartCaptureWindow and replace for this procedure that allows to select the video capture driver...

Code: Select all

Procedure StartCaptureWindow (parentwindow.l)
  lpszName = AllocateMemory (0, 100)
  lpszVer = AllocateMemory (1, 100)
  Dim Names.s(10)
  
  x.l=0
  lResult.l=0
  DefType.CAPDRIVERCAPS Caps
  
  Repeat
    lResult = capGetDriverDescriptionA(x, lpszName, 100, lpszVer, 100)   ;// Retrieves driver info
    
    x = x + 1
    Names.s(x)=PeekS (lpszName)
  Until Asc(Left(PeekS (lpszName),1))=0

  If OpenWindow(9, 200, 100, 227, 98,0, "Select driver")
    If CreateGadgetList(WindowID())
      Frame3DGadget(0, 10, 10, 210, 80, "Select driver")
      ComboBoxGadget(1, 20, 30, 190, 60)
      ButtonGadget(2, 60, 60, 110, 20, "Ok")
      For Xs=1 To x-1
        AddGadgetItem(1,-1,Names.s(Xs))
      Next Xs
      SetGadgetState(1,0)
      QuitDriver=#FALSE
      Repeat
        
        Ev=WindowEvent()
        WE=EventWindowID()
        If WE=9
          If Ev=#PB_Event_Gadget
            Gd=EventGadgetID()
            If Gd=1
              Selected=GetGadgetState(1)
            EndIf
            If Gd=2
              QuitDriver=#TRUE
              Selected=GetGadgetState(1)
            EndIf
          EndIf
        EndIf
      Until QuitDriver=#TRUE
    EndIf
    CloseWindow(9)
  EndIf
  UseWindow(0)

  lwndC = capCreateCaptureWindowA (name$, #WS_CHILD | #WS_VISIBLE, 0, 0, 160, 120, parentwindow, 0)
  ;// Set the preview rate in milliseconds

  ;// Connect the capture window to the driver
  capDriverConnect (lwndC, selected)
  
  ;// Get the capabilities of the capture driver
  capDriverGetCaps (lwndC, @Caps, SizeOf (CAPDRIVERCAPS))
  
  ;// If the capture driver does not support a dialog, grey it out
  ;// in the menu bar.
  
  If Caps\fHasDlgVideoSource = 0
  ;  dlgSource = False
  EndIf
  
  If Caps\fHasDlgVideoFormat = 0
  ;  dlgFormat = False
  EndIf
  
  If Caps\fHasDlgVideoDisplay = 0
   ; dlgDisplay = False
  EndIf
  
  
  ;Caps.wNumVideoRequested=128
  ;// Set the video stream callback function
  capSetCallbackOnVideoStream (lwndC, @MyVideoStreamCallback ())
  
  capSetCallbackOnFrame (lwndC, @MyFrameCallback ())
  
  ;// Start previewing the image from the camera
  capPreview (lwndC, #True)
  capPreviewRate (lwndC,1)
  ;// Resize the capture window to show the whole image
  ResizeCaptureWindow (lwndC)
  
EndProcedure
if your webcam dont work, please wait a few to finish the first version of the scripting language that im making to make webcam games that will have an error log for this things, and probably is more bug free that the little game that is available now... about source code, i think that i dont finally publish the source... if i finnish the webcam game creator such as Game Maker, the source code will be dont published... but i made the first little demo on two days only... is a very simple algorithm like the chroma color used on TV.
Ralf
Enthusiast
Enthusiast
Posts: 203
Joined: Fri May 30, 2003 1:29 pm
Location: Germany

Post by Ralf »

ohhhh cool to have a source. many thanks for sharing your codesnip and showing me where to find the other stuff... have downloaded and changed original source but crashes every time here... sad
Post Reply