Intrusion Software
Intrusion Software
Type 1
Type 1
This code is used when there is a change in the background compared to previous frame an alarm should be triggered.
In[]:=
IMAQ`StartCamera[];(*AcessingCamera*)Dynamic[ListLinePlot[data,Mesh->All,MeshStyle->Red,AxesLabel->{"Time in seconds","Intensity"}]](*PlottingIntensityvsTimeDynamically*)Dynamic[diffimag](*ShowingtheDifferencebetweenImages*)data={};(*Datalist*)t=0(*parameter*)While[t<=3000,diffimag=ImageDifference@@ColorConvert[CurrentImage[2],"GrayScale"];(*Findingdifferencebetweenconsecutiveimagesconvertedtograyscale.*)intensevals=Flatten@ImageData[diffimag];(*Flatteningtheimagedataarray*)v=Total[intensevals];(*Totalofallarraystofindintensity*)data=AppendTo[data,{t,v}];(*Appendingnewintensityvaluestodata*)t++;(*Increasingtby1*)If[v>3000,EmitSound[Sound[SoundNote[]]];];(*Emmitingsoundifintensityismorethanthreshold*)(*Thresholdcanbechangedbasedonsurrounding*)];IMAQ`StopCamera[];
Type 2
Type 2
This type is used when there is a change in the initial background an alarm should be triggered.
IMAQ`StartCamera[];(*AcessingCamera*)background=ColorConvert[CurrentImage[],"GrayScale"];(*Takingpictureandusingittocomparewithfutureimages.*)(*Alltheotherframeswillbecomparedtothisone.*)val:=CurrentImage[];(*Toacessthecurrentimagewhenvaliscalled.*)Dynamic[ListLinePlot[data,Mesh->All,MeshStyle->Red,AxesLabel->{"time in seconds","Intensity"}]](*Dynamicallyplotintenstityvstime*)Dynamic[diffimag](*ShowingtheDifferencebetweenImages*)data={};(*Datalist*)t=0(*parameter*)While[t<=3000,gray=ColorConvert[val,"Grayscale"];diffimag=ImageDifference[gray,background];(*Findingdifferencebetweencurrentimageandinitialimageconvertedtograyscale.*)intensevals=Flatten@ImageData[diffimag];(*Flatteningtheimagedataarray*)v=Total[intensevals];(*Totalofallarraystofindintensity*)data=AppendTo[data,{t,v}];(*Appendingintensityvaluestodata*)If[v>3000,EmitSound[Sound[SoundNote[]]];;];(*Emmitingsoundifintensityismorethanthreshold*)(*Thresholdcanbechangedbasedonsurrounding*)t++;(*IncreasingParameter.*)]IMAQ`StopCamera[];