OBJECT DETECTION WITH A WEBCAM USING THE PYTHON PROGRAMMING LANGUAGE

Technology developed rapidly along the times, various ways are done to make works easier. One of them is by utilizing artificial intelligence, likes the use of a webcam as a sensor in detecting an object through several stages of image processing. There was research on object recognition previously using three measurement parameters based on color, shape, and size of objects. It is used a webcam as the sensing sensor, and image processing is processed with python programming. In this article, writer described about image processing for the detection of objects used in the research. The results of this device have been tested and are able to detect objects properly based on predetermined color, shape and size. Object detection using a webcam can work properly according to what the author wants.


Introduction
Technology is developing so rapidly along the times, so various ways are done to make it easier for humans to do a task. One of which is by utilizing artificial intelligence (Prayitno & Harianto, 2011;Mubarrok & Rahmawati, 2020). Many people are competing to make new innovations to be able to create tools that can make the task easier. One of the innovations in the newest technology is the use of a webcam. Currently, webcams have been widely used in industry; ranging from quality control, sorting, security (Juliando & Husin, 2019). Moreover, it can also be developed as a sensor in detecting an object through several stages of image processing (Prayitno & Harianto, 2011).
The stage of image processing is also called object detection. Object detection is the process of recognizing objects in a digital image. The image is obtained from a camera with certain specifications which processed by the object detection method, so that the classification of the object can be recognized (Najmurrokhman et al., 2017). In several previous studies, the detection of this object only used two parameters for its recognition, namely shape-color recognition and color-size recognition. These two object recognition parameters are worth already. If object recognition used three recognition parameters, i.e. color, shape, and size; then the object sorting process is more selective accordingly (Purwanti, et. al., 2021).
The previous research used three measurement parameters thas is already available, i.e. measurement parameters based on color, shape, and size of objects using a webcam as a sensing sensor, and the image processing is processed with python programming (Pulungan & Nafis, 2021). Thus, the author will account about image processing for the detection of objects used in research with three object recognition parameters using a webcam as a sensing sensor, and image processing is processed with the Python programming language.

Literature Review 2.1. The Digital Image
A digital image is a two-dimensional image that can be displayed on a computer monitor screen as a finite (discrete) set of digital values called pixels (picture elements). The pixel is an image element that has a value that indicates the intensity of the color (Norfazlinda Binti Daud, 2007). The image processing is the process for processing an image quality or image that has been taken by a camera or webcam so that the image can be recognized and has certain values. The values that have been obtained are then processed to classify the images(Alfaro- Almagro, et. al., 2018).
The digital image is composed of a digital number that represents the intensity of light represented by a 2-dimensional array at a certain point in a grid. The points in this 2-dimensional grid are called pixels or mops, which stands for the word picture element.

HSV (Hue, Saturation, and Value )
The image processing for color recognition is RGB to HSV color segmentation. HSV is a color model which derived from RGB color, so to get HSV color which have to do a color conversion process from RGB to HSV (Fauzi and Mayasari, 2011). HSV stands for Hue Saturation and Value. Hue is a measure of the wavelength of the color, hue has a size ranging from 0 until 255. The number of 0 represents the red color until through a spectrum it returns 256 or returns to red again. The sturation is a process to increase the brightness of the color based on the amount of pure hue in the final color. The value is a measure of how much brightness a color is.
If the color has a size of 100%, then it will look very bright. If it is 0%, then it will look dark (Aditya et al., 2020). Thus, the process will form an area segment with the desired color tolerance (Zarwani, 2019). A literature review is a survey of scholarly sources (such as books, journal articles, and theses) on a particular topic. It gives an overview of key findings, concepts and developments in relation to a research problem or question.

Thresholding
Thresholding is the conversion of a color image to a binary image which is done by grouping the grayscale value of each pixel into 2 classes, black and white. In the floating operation, the pixel intensity value is mapped to one of two values, α₁ or α₂ (Handoyo, 2006). Contour is a state caused by changes in intensity at different pixels. Because of this change in intensity, the edges of the object in the image are detected (Andrizal et al., 2016).

Python
Python is a multipurpose interpretive programming language that is easy to read and understand, and it places more emphasis on code readability to make it easier to understand the syntax. The modest and implemented code of phyton make it easy to learn, both for beginners and those who have mastered the programming language. Various operating system platforms and software development requirements can use Python. Python programming language is defined as a language that combines capabilities, which with a very clear code syntax and also comes with a large comprehensive standard library functionality. Python is a free tool, there are no restrictions on how to distribute it. Equipped with automatic memory management, python is a dynamic programming language. Python is a programming language that is easy to understand because of the clear form of the language used (Aviolita, 2019).

OpenCV
OpenCV (Open Source Computer Vision Library) is a software that aim to process dynamic images in real-time (Januar, 2016). OpenCV is an API (Application Programming Interface) library which is very familiar in image processing designed for real-time applications, has good acquisition functions for image / video (M. Syafriandi, 2017). OpenCV has many functionalities that can help in making image processing applications easier and less complicated (Edward, Ghanie and Setiawan, 2020). OpenCV can be used with various programming languages such as Python, Java and C language (Bradski and Kaeler, 2008).

Webcam
This study used the Night Hawk a80 webcam with HD960p resolution. The functions is as a sensing sensor for image capture of objects to be detected in color, size and shape. The output of the data image obtained will be carried out by the object detection process using the PYTHON programming language OpenCV library. The function of each block diagram as follow: • Objects are objects that will detect color, shape, and size.
• Webcam functions as a sensing sensor that will take pictures of objects.
• Python is a programming language that has been installed on a PC which functions to proceed image data on objects by detecting objects based on the object's color, shape, and size. The nomenclature must be appeared at the end of the paper (if included). The SI units are highly recommended for this journal.

Procedure
The first process is color recognition of object through the HSV segmentation process, where the color range processed is red. If the object's color is in the red range, then it will be detected. Thus proceed with the thresholding process, which is a segmentation technique to change the RGB color to the bine color. After that, the process is carried out to find out the outline of the object by drawing the contour to detect the edges of the object in the image. The last process is to describe the mid-point on each contour line to find out the size of the object. After the color, shape and size of the object are known, it can be concluded whether the object conforms to the classification or not. The result of this detection will be in the form of a logic 1 or 0 which will be sent to the actuator controller via a USB connection. The range of colors detected by this tool is objects in red. If the object is red, then it will be processed for shape and size detection. Conversely, if the object is not red, then the object will be considered a reject without detection of its shape and size.

Design of Hardware
The device is designed with an overall length and width of 20 x 20 x 30 cm, with the webcam stand at a height of 22 cm. The device is tested using 8 different objects. The classification of objects to be tested can be seen in Table 1.

GUI Display
Graphic User Interface (GUI) or graphical user interface is a display system of a program or application that functions to provide information or access to users. In this study also uses a GUI which serves as a display of information from the detection of objects that are being carried out. There are several parts of the GUI in this article: • The start button functions to activate the camera • Stop button functions to turn off the camera • Track button functions to start object detection • Object display window which functions to provide information on object detection.
• Display binary image of detected objects in red.

Results and Discussions
The following are some tests that have been carried out several times to obtain data and evidence that can be analyzed on the performance process of the device. The test of device using 8 objects of different colors, shapes, and sizes. The classification of the objects to be tested can be seen in Table 1.

Object Detection
This object detection is the result of object detection by the webcam using the python programming language with the OpenCV library. Testing was carried out with 8 different objects, where this detection includes detecting the color, shape, and size of the object. The results obtained are in Table 2 below From the results of the detection of objects, data can be taken from each object, which will be grouped based on the detection data of color, shape and size in Table 3, Table 4, and Table 5.

Color Detection
The color detection in this article is based on a predetermined range of HSV values, while the specified HSV ranges can be seen in Table 3. If the color of an object has an HSV value in the range of values in the table above, then the object will be detected, and will carry out the next process for shape and size recognition. With the listing program: The results of color detection on this device using the HSV color segmentation process can be seen in Table 4. This color recognition works as expected, because this device was able to detect red objects. It can be seen in the object classification table. Red objects are objects 1,3,5,7 these objects are detected and can be processed to recognize the shape and size of objects .

Shape Detection
After color detection, then the shape recognition processed. In this system device can only recognize square objects, with the following listing program.
if len(approx) == 4: cv2.putText(img, "Persegi", (x, y), Fig. 8. Listing program The results of shape detection are in Table 5 below. Object 3 Square 4 Object 4 -5 Object 5 -6 Object 6 -7 Object 7 -8 Object 8 - The recognition of object shapes can work as expected. The objects that can carry out the next process are only red objects, so objects detected by squares are only objects 1 and 3.

Size Detection
In the process of object detection, the last process is the size of the object. After the color and shape known, the next step is to test the size of the object. Objects that comply with the classification are objects with sides of 6x6cm with a tolerance of 0.2cm. This detection uses listing program like the one below. Fig. 9. Listing program hsv = cv2.cvtColor(self.image, cv2.COLOR_BGR2HSV) mask = cv2.inRange (hsv, lower_red1, upper_red1) The results of size detection are as shown in Table 6. Object 3 7,0 x 7,0cm 4 Object 4 -5 Object 5 5,9 x 5,9cm 6 Object 6 -7 Object 7 7,9 x 6,9cm 8 Object 8 -Same as the previous object shape detection, only objects that are red in the process of detecting the size of this object. So, the recognition of the size of this object can only work on objects 1,3,5, and 7. In the object classification table, the the size detection of the object can work as expected, because the results obtained are in accordance with the classification of objects.

Object qualification have been tested
From some of the tables above, it can be seen the results of testing objects, from testing the color, shape, and size of objects. Next is to determine the object according to specifications or not with the listing program below. As for the results of the qualification of objects that have been tested can be seen in Table  7 below. Object 4 Reject 5 Object 5 Reject 6 Object 6 Reject 7 Object 7 Reject 8 Object 8 Reject

Conclusion
Based on testing and analysis that has been carried out on object detections based on color, shape and size with a webcam, it can be concluded that: • The manufacture of hardware can be made in accordance with the planning device that have been made. • This device can work properly as expected, because in testing all these components can work in accordance with a predetermined system. • Object detection by webcam can detect objects based on color, shape, and size. • This test used 8 objects that have been prepared with different colors, shapes and sizes each other, and have been tested several times. There is minimum error, either the object recognition error by the webcam or other tests