# Code Analysis

```python
greenLower = (29, 86, 6)
greenUpper = (64, 255, 255)
pts = 64
```

define the green's range (29, 86, 6) \~ (64, 255, 255). **pts** is buffer maximum size, i use 64 dequeue's size &#x20;

```python
blurred = cv2.GaussianBlur(frame, (11, 11), 0)
hsv = cv2.cvtColor(blurred, cv2.COLOR_BGR2HSV)
```

For processing the frame faster, blur the frame to reduce high frequency noise and allow to focus on the structural objects inside the frame.&#x20;

```python
	mask = cv2.inRange(hsv, greenLower, greenUpper)
	mask = cv2.erode(mask, None, iterations=2)
	mask = cv2.dilate(mask, None, iterations=2)
```

### **Ref**

> [**https://opencv-python-tutroals.readthedocs.io/en/latest/py\_tutorials/py\_imgproc/py\_morphological\_ops/py\_morphological\_ops.html**](https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_morphological_ops/py_morphological_ops.html)

**\<cv2.erode()>**

thickness or size of the foreground object decreases or simply white region decreases in the image. It is useful for removing small white noises.

**\<cv2.dilate()>**

**It is just opposite of erosion.** erosion removes white noises, but it also shrinks our object. So we dilate it.

<div align="left"><img src="https://3145865572-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWS9GJNGS8qhQK5QahB%2F-MXFlR2tuES16tYf2SrJ%2F-MXFoJfyQbwa2meClE9F%2Fimage.png?alt=media&#x26;token=9c874681-9045-4aba-992e-6469ec2d5926" alt="cv2. erosion()"></div>

<div align="left"><img src="https://3145865572-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWS9GJNGS8qhQK5QahB%2F-MXFlR2tuES16tYf2SrJ%2F-MXFoPw43kRsOETjznNw%2Fimage.png?alt=media&#x26;token=6c03cf0b-5d40-4e0e-b618-7a55363559ac" alt="cv2.dilation()"></div>

erosion, dilation is use to remove any small noise

```python
c = max(cnts, key=cv2.contourArea)
((x, y), radius) = cv2.minEnclosingCircle(c)
M = cv2.moments(c)
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
```

I find the largest contour inthe cnts list. -> compute minimum enclosing circle of the blob.  -> compute the center *(x, y)*-coordinates

If complete computing (x,y)-coordinate, append value in dequeu "pts"

```python
thickness = int(np.sqrt(args["buffer"] / float(i + 1)) * 2.5)
cv2.line(frame, pts[i - 1], pts[i], (0, 0, 255), thickness)
```

compute the thickness of the contrail and then draw it on the frame using cv2.line()
