OBJECT DETECTION AND TRACKING USING OPENCV, VISUAL STUDIO C++ 2010 AND ARDUINO

Intro: OBJECT DETECTION AND TRACKING USING OPENCV, VISUAL STUDIO C++ 2010 AND ARDUINO

INTRODUCTION
 
In this project the Webcam sends video frames to the Visual Studio C++ which contains Open CV library running on our computer.
If Visual Studio C++ program detects the image of the object from the webcam then it calculates the co ordinates of X, Y axis and radius of the object.The co ordinates are sent accordingly to the arduino Mega/UNO via Serial communication between the arduino and visual studio c++. 
After receiving the co-ordinates the servo motors moves in X and Y direction and follows the object.

Here is the video of it :) Sorry for the dull video i was tired at that time :)


MATERIAL REQUIRED:

HARDWARE:

1. Servo Motors x 2
2. Webcam ( any webcam) x 1
3. Arduino Mega/Uno x 1
4. External Power Supply 5V x 1
5. BreadBoard x 1
6. Single Core connecting wires

SOFTWARE:

1. Arduino IDE
2. OpenCV 2.3.1
3. Visual Studio C++ 2010 Express SP1


CODE :

1. Visual Studio C++ Code (attached)
2. Arduino Program Code (attached)


Step 1: Software Installation



1) Download and install the OpenCV -2.3.1. OpenCV contains all the important files needed for the making of the project.

link::http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.3.1/

OpenCV installation can cause some problems, So see this video it would help alot. This video shows proper installation of OpenCV.

http://www.youtube.com/watch?v=cgo0UitHfp8

2) Download and install the Microsoft VisualStudio C++ 2010 Express.

link::http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express

3) Download and install Arduino IDE

link::http://arduino.cc/en/Main/Software

Step 2: Attaching Servo Motors AND WebCam

Construction is rather simple...

First Servo Motors:


Project i have made is temporary so i have fixed the servos with Galvanised Sheets, they are easy to cut and use and can be drilled easily plus they are flexible.

You can use various jigs of different material to attach the servos to make them permanent or temporary as suited by you.

Once you have attached the servo motors now its time to attach the Webcam.

Webcam:

At the horn of the second servo controlling the Y direction as shown in the pic.

Connect the webcam using J-Locks.

It surely isn't the most beautiful looking project but it does the work :P



Step 3: Connections

SERVO MOTOR CONNECTION:

1.Connect Lower Servo motor yellow wire with the PIN No - 9 of the arduino UNO.(controls x axis)
2.Connect Upper Servo motor yellow wire with the PIN No -10 of the arduino UNO(controls y axis)
3.Connect the red wire of the servo motor with 5v coming from arduino UNO as shown in the figure above.
4.Connect the black wire of the servos with the GND(Ground) coming from the arduino UNO as shown in figure above.

WEB CAM CONNECTION:

Connect the webcam with the usb port of the computer.

ARDUINO UNO:

Connect the arduino UNO with the usb port of the computer.
Before uploading code in you arduino select proper COM Port and Board accordingly.

 You must change the C++ code to match the PC's com port and baud rate with Arduino UNO/MEGA. Also, the C++ code must be told which USB port the webcam is using.

Step 4: FINAL STEP :D UPLOADING

Arduino UNO

Upload the program in arduino UNO


VISUAL STUDIO C++

If everything was done correctly then. 

Start the program and 4 screens would open up...

1. First screen would be for selecting the appropriate HSV values so that u can opt for particular object you want to track for.
2.Second screen would show the original image of your webcam.
3.Third screen would show the processed image of your webcam usually a binary image.
4.Fourth screen would show u the x axis, y axis and radius of that image.

Step 5: Sources

Some of the links i followed and helped me alot.

https://www.instructables.com/id/Face-detection-and-tracking-with-Arduino-and-OpenC/

http://aleksandarkrstikj.com/tracking-a-ball-and-rotating-camera-with-opencv-and-arduino/

http://www.youtube.com/watch?v=cgo0UitHfp8

http://www.youtube.com/watch?v=bSeFrPrqZ2A

If you need more help feel free to contact me
email ID: shamsheerverma10@gmail.com

I hope u enjoyed my instructable :P

Thank you :D :D




Share

Recommendations

  • Audio Contest 2018

    Audio Contest 2018
  • Furniture Contest 2018

    Furniture Contest 2018
  • Tiny Home Contest

    Tiny Home Contest

60 Discussions

0
None
Muhammad HafidK

9 months ago

hey can you give me the correct code please

here is my email muhammadhafid13@gmail.com

thank you :)

0
None
msameer39

10 months ago

Such a great project and tutorial Shamsheer. I hope you have finished your studies and joined some top company. I will try your project and let you know

0
None
PedroW1

1 year ago

hey can you give me the correct code please

here is my email pwasto@gmail.com

0
None
kumar kumar

1 year ago

I cant find the code:( i can just see that it is attached

0
None
AmitN33

1 year ago

sir, I am new to all these and I followed your instructions and put the open cv code in visual studio it worked but the output is coming that no serial port is being made and I have also uploded the aurdino code in aurdino but how to link these two ... please help me out to create a serial port... email id is amit.nayal24@gmail.com

0
None
anjith

1 year ago

hi.. the code worked well for me.. its a great project... i need to know if i can adjust the values of the track bar permanently so that every time i do not need to adjust it and the camera starts to detect the object right when i start running the program...

0
None
ZiedB10

1 year ago

Hello, this is my first arduino project: sending a file (jpeg, pdf, txt)
from an arduino sd card module to android phone using arduino uno and
bluetooth module HC-05
It's possible with this hardware?

If it's possible can someone please send me the source code and android app use it to receive the file
thank you

0
None
saileshz

2 years ago

can you please give me complete description on my mail?

my mail id is: atulzalke@yahoo.com

0
None
arash1371

2 years ago

Hi. I have following error. Please help.

Unhandled exception at 0x766e40f8 in projectbs01.exe: Microsoft C++ exception: cv::Exception at memory location 0x00eff5f0..

0
None
leahjoyce77

2 years ago

請給我的源代碼

leahjoyce77@yahoo.com.tw

0
None
sciencegirl777

2 years ago

Hello!

I was wondering if you can tell me how to chose my camera from my USB port. I have Visual Studio 2015 downloaded, along with Arduino and Open CV.

Please let me know ASAP. Thank you.

0
None
TimcoV

2 years ago

Hi, please can you help me? I have a problem - it write me error C2872:'ACCESS_MASK'
Please help me! :(

0
None
MilapJ

3 years ago on Introduction

I want to integrate the object identification into robot arm gripper. The robot arm will move as soon as the object is detected and try to grab it. Any suggestions how to make it?

Hello,

I am trying to build this project but my track bars are not working can you please send me the codes for visual studio. my e mail buddhi.charitha@gmail.com

This is what my track bars look like.

Please help me

Capture.PNG
0
None
Jorge HugoE

3 years ago

I think your proyect is awesome and i would like to practice but i don't know where i can download the sources. I'll be gratefully if you post the links.

Thanks a lot.

4 replies

Hi; would you please send me these code :
1.visual studio c++ code

2.arduino program code

3.opencv code for color detection

Thanks a lot :)

My email address : nafiseh.ghafarnia@gmail.com