Edit: Webcam, not digital camera.
The following code enables your digital camera to detect motion. Expect a crash at the end and do not run in exclusive mode unless you like crashing Windows:
rem Project: WebCam
Rem Created: 10-08-2004 12:05:07
Rem ***** Main Source File *****
GLOBAL MEM_POINTRED as byte
GLOBAL MEM_POINTGREEN as byte
GLOBAL MEM_POINTBLUE as byte
load dll "c:windowssystem32avicap32.dll",1
load dll "c:windowssystem32user32.dll",2
Name$="a"
Ver$=""
while Name$<>""
iReturn = call dll (1,"capGetDriverDescriptionA",x,Name$,100,Ver$,100)
if iReturn=1
print "Driver Number ",x," )"
print "Name: ",Name$
print Ver$
print " "
inc x
endif
endwhile
WS_CHILD=1073741824
WS_VISIBLE=268435456
WM_CAP_SET_SCALE = 1024+53
wm_cap_driver_connect=1024+10
wm_cap_set_preview=1024+50
WM_CAP_SET_PREVIEWRATE=1024+52
WM_CAP_EDIT_COPY=1024+30
WM_CAP_SEQUENCE=1024+62
WM_CAP_FILE_SAVEDIB=1024+25
WM_CAP_DLG_VIDEODISPLAY=1024+43
WM_CAP_SET_OVERLAY=1024+51
driver=0
input "Please select which driver you want to use - 0 usualy works the best: ",driver
visible=1
picid = call dll (2,"GetActiveWindow")
hHwnd = call dll (1,"capCreateCaptureWindowA","driver",WS_VISIBLE Or WS_CHILD,0,0,1,1,picid,0)
overlay=1
call dll 2,"SendMessageA",hHwnd,wm_cap_driver_connect,0,0
call dll 2,"SendMessageA",hHwnd,wm_cap_set_preview,overlay,0
call dll 2,"SendMessageA",hHwnd,WM_CAP_SET_PREVIEWRATE,30,0
rem Copy the current image to the Clipboard - as BMP
rem call dll 2,"SendMessageA",hHwnd,WM_CAP_EDIT_COPY,1,0
rem record an AVI to c:capture.avi
rem call dll 2,"SendMessageA",hHwnd,WM_CAP_SEQUENCE,1,0
`make object cube 1,50
sync on
do
cls
if file exist("c:img2.dib") then delete file "c:img2.dib"
if file exist("c:img.dib") then rename file "c:img.dib","c:img2.dib"
call dll 2,"SendMessageA",hHwnd,WM_CAP_FILE_SAVEDIB,0,"c:img.dib"
rem load bitmap "c:navn.dib",0
load image "c:img.dib",1,1
load image "c:img2.dib",2,1
gosub getdif
paste image 1,0,0
`line w,0,w,h
`line 0,h,w,h
`if diffs>500 then text 100,100,"Motion."
sync
loop
getdif:
diffs=0
make memblock from image 1,1
make memblock from image 2,2
w=image width(1)-1
h=image height(1)-1
for x=0 to w
for y=0 to h
MEM_setup(2,w,h,1)
MEM_pointRGB(x,y)
`r2=MEM_POINTRED
`g2=MEM_POINTGREEN
`b2=MEM_POINTBLUE
c2=(MEM_POINTRED+MEM_POINTGREEN+MEM_POINTBLUE)/3
MEM_setup(1,w,h,1)
MEM_setup(1,w,h,2)
MEM_pointRGB(x,y)
c1=(MEM_POINTRED+MEM_POINTGREEN+MEM_POINTBLUE)/3
if c2<c1-15 or c2>c1+15 then MEM_dotRGB(x,y,255,0,0) : diffs=diffs+1
next y
next x
make image from memblock 1,1
delete image 2
delete memblock 1
delete memblock 2
return
FUNCTION MEM_setup(memblockNum,width,height,setType)
SELECT setType
CASE 1
GLOBAL MEM_ATT_READ_MBN : MEM_ATT_READ_MBN = memblockNum
GLOBAL MEM_ATT_READ_WIDTH : MEM_ATT_READ_WIDTH = width
GLOBAL MEM_ATT_READ_HEIGHT : MEM_ATT_READ_HEIGHT = height
ENDCASE
CASE 2
GLOBAL MEM_ATT_WRITE_MBN : MEM_ATT_WRITE_MBN = memblockNum
GLOBAL MEM_ATT_WRITE_WIDTH : MEM_ATT_WRITE_WIDTH = width
GLOBAL MEM_ATT_WRITE_HEIGHT : MEM_ATT_WRITE_HEIGHT = height
ENDCASE
ENDSELECT
ENDFUNCTION
FUNCTION MEM_dot(x,y,value)
memPos = (y*MEM_ATT_WRITE_WIDTH*4)+(x*4)
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+12,rgbb(value)
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+13,rgbg(value)
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+14,rgbr(value)
ENDFUNCTION
FUNCTION MEM_dotRGB(x,y,red,green,blue)
memPos = (y*MEM_ATT_WRITE_WIDTH*4)+(x*4)
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+12,blue
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+13,green
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+14,red
ENDFUNCTION
FUNCTION MEM_circle(xPos,yPos,size,value)
for xLoop=0 to 360
x=xPos+cos(xLoop)*size
y=yPos+sin(xLoop)*size
if x>0 and x=<MEM_ATT_WRITE_WIDTH-1 and y>0 and y=<MEM_ATT_WRITE_HEIGHT-1
memPos = (y*MEM_ATT_WRITE_WIDTH*4)+(x*4)
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+12,rgbb(value)
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+13,rgbg(value)
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+14,rgbr(value)
endif
next xLoop
ENDFUNCTION
FUNCTION MEM_circlefilled(xPos,yPos,size,value)
size#=size
for x=xPos-(size/2) to xPos+(size/2)
for y=yPos-(size/2) to yPos+(size/2)
if sqrt((xPos-x)^2+(yPos-y)^2)*2<size#
memPos = (y*MEM_ATT_WRITE_WIDTH*4)+(x*4)
if x>0 and x=<MEM_ATT_WRITE_WIDTH-1 and y>0 and y=<MEM_ATT_WRITE_HEIGHT-1
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+12,rgbb(value)
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+13,rgbg(value)
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+14,rgbr(value)
endif
endif
next y
next x
ENDFUNCTION
FUNCTION MEM_circle3(xPos,yPos,size,value,front)
size#=size
for x=xPos-(size/2) to xPos+(size/2)
for y=yPos-(size/2) to yPos+(size/2)
if sqrt((xPos-x)^2+(yPos-y)^2)*2<size#
memPos = (y*MEM_ATT_WRITE_WIDTH*4)+(x*4)
if x>0 and x=<MEM_ATT_WRITE_WIDTH-1 and y>0 and y=<MEM_ATT_WRITE_HEIGHT-1 and MEM_point(x,y)<>front
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+12,rgbb(value)
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+13,rgbg(value)
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+14,rgbr(value)
endif
endif
next y
next x
ENDFUNCTION
FUNCTION MEM_dome(xPos,yPos,size,value)
size#=size
for x=xPos-(size/2) to xPos+(size/2)
for y=yPos-(size/2) to yPos
if sqrt((xPos-x)^2+(yPos-y)^2)*2<size#
memPos = (y*MEM_ATT_WRITE_WIDTH*4)+(x*4)
if x>0 and x=<MEM_ATT_WRITE_WIDTH-1 and y>0 and y=<MEM_ATT_WRITE_HEIGHT-1
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+12,rgbb(value)
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+13,rgbg(value)
WRITE MEMBLOCK BYTE MEM_ATT_WRITE_MBN,memPos+14,rgbr(value)
endif
endif
next y
next x
ENDFUNCTION
FUNCTION MEM_point(x,y)
memPos = (y*MEM_ATT_READ_WIDTH*4)+(x*4)
r = MEMBLOCK BYTE(MEM_ATT_READ_MBN,memPos+12)
g = MEMBLOCK BYTE(MEM_ATT_READ_MBN,memPos+13)
b = MEMBLOCK BYTE(MEM_ATT_READ_MBN,memPos+14)
value=rgb(b,g,r)
ENDFUNCTION value
FUNCTION MEM_pointRGB(x,y)
memPos = (y*MEM_ATT_READ_WIDTH*4)+(x*4)
MEM_POINTBLUE = MEMBLOCK BYTE(MEM_ATT_READ_MBN,memPos+12)
MEM_POINTGREEN = MEMBLOCK BYTE(MEM_ATT_READ_MBN,memPos+13)
MEM_POINTRED = MEMBLOCK BYTE(MEM_ATT_READ_MBN,memPos+14)
ENDFUNCTION
FUNCTION MEM_cls(memNum,value)
FILL MEMORY GET MEMBLOCK PTR(memNum)+12,value,GET MEMBLOCK SIZE(1)-12
ENDFUNCTION
FUNCTION MEM_copytoscreen(memNum)
LOCK PIXELS
ptrTo = GET PIXELS POINTER()
ptrFrom = GET MEMBLOCK PTR(memNum)+12
COPY MEMORY ptrTo,ptrFrom,GET MEMBLOCK SIZE(1)-12
UNLOCK PIXELS
ENDFUNCTION
Credits:
http://forum.thegamecreators.com/?m=forum_view&t=43257&b=1
|Image Memblock Functions|
http://forum.thegamecreators.com/?m=forum_view&t=37053&b=6
|Digital Camera Code|
http://forum.thegamecreators.com/?m=forum_view&t=38587&b=6
|Menu Code|
(Will probably use it)
Todo:
Detect Weither There Is a Lot of Motion or Not - Easy
Save Image If So - Easy
Allow a Limit to Image Saves - Easy
Allow Modification of How Much a Lot Is - Easy
Option to Greyscale Image - Easy
Modification of Range that diffrence is not significant - Easy
Color Diffrencing Mode - Easy(using greyscale now)
Menu System - Hard(never did it before)
Readme/Help Files(HTML) - Easy to Medium
Quote: "I've seen the word programming and I'm not sure what it means. Anybody please explain?"
Quote: "We shouldn't sacrifice the truth to preserve "balance"."