Arduino Image processing CCTV camera system application designing and programming
Description:
Arduino Image processing- In this tutorial you will learn how to use image processing, Arduino Uno and PIR sensor to create your own Arduino based CCTV camera device. “Visual Basic” will be used to create the image processing program in this tutorial vb.net.This application works in conjunction with the Arduino Uno connected PIR sensor. Once both the PIR sensor and the image processing application detect the human, a picture is automatically captured and stored in a folder.
Visual Basic.net will be used for the image processing software. It’s really easy to model image processing applications in vb.net. The Frontal face XML archive is used in this application for human identification.Once the computer application detects the human face and also receives a signal from the Arduino, a picture will be taken automatically and stored in the desired folder.
Amazon links:
Pir motion sensor:Â
night vision camera
Arduino Uno:Â
330-ohm resistors pack:Â
connection wires:Â
Bread Board:
Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
Circuit Diagram:
As you can see, the circuit diagram is really simple, all you need is to link the PIR sensor to the Arduino Uno pin number 4 and the Arduino 5v and ground VCC and ground respectively.
Arduino Programming:
It’s very simple to program Arduino. First I define the PIR sensor pin. The PIR sensor is attached to the number 4 pin of the Arduino. You can use any other Pin if you want. Then the flag variable type integer is specified. Initially this parameter is set to Zero. Use the variable flag to stop unnecessary code repetition.
1 2 |
int pirsensor = 4; // pir sensor connected with 4 int flag = 0; |
If used before the name of the function, the word void means that this function has no type of return. If you look, the parenthesis will also be null, meaning that this function does not take any argument as the output. So there is no return form for the void setup function and it does not take any argument as the output.
For this reason, we use a Serial.begin() function to enable the Serial communication, this is an integrated function and takes one argument as the output, which is the baud rate. Using the pinMode function, the PIR sensor is set to output. Only once the controller is turned on, the void setup function is executed.
1 2 3 4 5 6 7 8 |
void setup() { Serial.begin(9600); pinMode(pirsensor, INPUT); digitalWrite(pirsensor, LOW); Serial.println("hi how are you"); } |
The role of the void loop runs endless times before you stop it. There is also no return form for the void loop function and it does not take any argument as the output.
As you can clearly see, the void loop function consists of only two if conditions, the purpose is to find out if the PIR sensor has been detected in motion and send the desired message using the Serial.print function to the computer application.You may have noticed one thing that changes the status of the flag every time. This is simply to stop the unnecessary repetition and only send the message once the human is detected.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
void loop() { if( (digitalRead(pirsensor) == HIGH)&& (flag == 0)) { Serial.print("intruder detected"); flag = 1; } if( (digitalRead(pirsensor) == LOW)&& (flag == 1)) { Serial.println("no Intruder"); flag = 0; } } |
Computer Image Processing Application Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
Imports Emgu.CV Imports Emgu.CV.Util Imports Emgu.CV.Structure Imports System.Diagnostics Imports System.IO Imports System.IO.Ports Imports System.Threading Public Class Form1 Dim count As Integer = 0 Dim facedetected As Integer Dim facepresent As Integer Dim web As Capture = New Capture(0) ' camera number Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick faces() End Sub Private Sub wait(ByVal interval As Integer) Dim sw As New Stopwatch sw.Start() Do While sw.ElapsedMilliseconds < interval ' Allows UI to remain responsive Application.DoEvents() Loop sw.Stop() End Sub Sub faces() Dim photo As Image(Of Bgr, Byte) photo = web.RetrieveBgrFrame Dim currentCenter As New Point() Dim facedetection As New CascadeClassifier("C:\data\haarcascades\haarcascade_frontalface_default.xml") ' this one is for the face detection facedetected = 0 Try Dim image As Image(Of Gray, Byte) = photo.Convert(Of Gray, Byte)() For Each face As Rectangle In facedetection.DetectMultiScale(image, 1.1, 8, Size.Empty, Size.Empty) ' default 1.1, 8 ( while best values are 1.2 and 17 after checking) photo.Draw(face, New Bgr(Color.White), 4) currentCenter.X = CInt(CDbl(face.X + face.X + face.Width) / 2.0) currentCenter.Y = CInt(CDbl(face.Y + face.Y + face.Height) / 2.0) Label2.Text = (currentCenter.X).ToString Label3.Text = (currentCenter.Y).ToString Dim f = New MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 0.5, 0.5) photo.Draw("Human detected", f, currentCenter, New Bgr(0, 255, 0)) ' New Point(10, 80) Dim f2 = New MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 0.7, 0.7) photo.Draw("human detectioin and tracking system", f2, New Point(10, 20), New Bgr(0, 255, 255)) ' New Point(10, 80) Label4.Text = face.ToString facedetected = 1 ' we are storing 1 if faces are detected. Next PictureBox1.Image = photo.ToBitmap Catch ex As Exception End Try End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.Close() SerialPort1.PortName = "com5" SerialPort1.BaudRate = "9600" SerialPort1.DataBits = 8 SerialPort1.Parity = Parity.None SerialPort1.StopBits = StopBits.One SerialPort1.Handshake = Handshake.None SerialPort1.Encoding = System.Text.Encoding.Default SerialPort1.Open() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click count = count + 1 TextBox1.Text = count Dim photosave As Image(Of Bgr, Byte) photosave = web.RetrieveBgrFrame photosave.Save("E:\youtube tutorials\1 image processing security system\pictures\ fahad" + TextBox1.Text + ".jpg") End Sub Private Sub DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived Try Dim mydata As String = "" mydata = SerialPort1.ReadExisting() If TextBox2.InvokeRequired Then TextBox2.Invoke(DirectCast(Sub() TextBox2.Text &= mydata, MethodInvoker)) Else TextBox2.Text &= mydata End If Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick If (InStr(TextBox2.Text, "intruder detected") And (facedetected = 1)) Then count = count + 1 TextBox1.Text = count Dim photosave As Image(Of Bgr, Byte) photosave = web.RetrieveBgrFrame photosave.Save("E:\youtube tutorials\1 image processing security system\picture pir\ fahad" + TextBox1.Text + ".jpg") TextBox2.Text = "" End If End Sub End Class |
Watch Video Tutorial