Object detection using opencv

Introduction

This report presents the results of our image processing assignment, which involves various image processing techniques applied to the input image named "Coins.png." The assignment consists of the following steps:

  • Importing the image
  • Resizing the image
  • Converting the image to grayscale
  • Converting the grayscale image to binary
  • Counting and segmenting the coins in the image

Each step is explained and demonstrated in detail in the following sections.

Step 1: Importing the image

In the first step, we imported the input image "Coins.png" using the OpenCV library function imread(). The original image is displayed below:

download

Step 2: Resizing the Image

The second step involved resizing the image to a 256x256 pixel resolution using the OpenCV library function resize() and Inter Area resampling algorithm. The resized image is displayed below:

download

Step 3: RGB to Grayscale Conversion

In this step, we converted the resized RGB image to grayscale using the function cvtColor(). Grayscale conversion simplifies further image processing operations. The grayscale image is displayed below:

download

Step 4: RGB to Binary Conversion

The next step involved converting the grayscale image to binary using a thresholding technique done using function threshold(). Pixels with values above a certain threshold which we set to 160, are set to white, while those below the threshold 160 are set to black. The resulting binary image is displayed below:

download

Step 5: Coin Counting & Segmentation

In the final step, we performed coin counting and segmentation using functions such as dilate() and findContours(). This involved the following sub-steps:

  • Edge detection using the Canny algorithm.
  • Contour detection to identify individual coins.
  • Drawing contours around the detected coins on the original image.

The resulting image is displayed below:

download

download

The number of coins in the picture is 8