Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traffic_Sign_Recognition & CV_YOLO_Object_Detection_and_Trajectory #28

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
24 changes: 24 additions & 0 deletions CV_YOLO_Object_Detection_and_Trajectory/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# CV Workshop

### Verify python version
```
python --version
```
### Steps to Debug python path issue
1. **Open Environment Variables**
- Press ``Win`` and search for Environment Variables
- Click on Edit the system environment variables.
- In the System Properties window, click the Environment Variables button.
2. **Check path**
- Under the User variables section, find and select the ``Path`` variable, then click Edit.
- Select python path and press ``move up`` till it gets at the top.

### Install ultralytics
```
pip install ultralytics
```

### Colour picker
- [here](https://colorpicker.me/#b0b0b2)


662 changes: 662 additions & 0 deletions CV_YOLO_Object_Detection_and_Trajectory/opencv.ipynb

Large diffs are not rendered by default.

Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions CV_YOLO_Object_Detection_and_Trajectory/trackbar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import cv2
import numpy as np


# cap=cv2.VideoCapture("OpenCV\\Res\\ball_for_tracking.mov")
img = cv2.imread(r"Res\bit1.png")
img = cv2.resize(img, (700, 500))


def Track(x):
pass


cv2.namedWindow("Color detectors")
cv2.resizeWindow("Color detectors", 500, 500)
cv2.createTrackbar("Upper Hue", "Color detectors", 153, 180, Track)
cv2.createTrackbar("Upper Saturation", "Color detectors", 255, 255, Track)
cv2.createTrackbar("Upper Value", "Color detectors", 255, 255, Track)
cv2.createTrackbar("Lower Hue", "Color detectors", 64, 180, Track)
cv2.createTrackbar("Lower Saturation", "Color detectors", 72, 255, Track)
cv2.createTrackbar("Lower Value", "Color detectors", 49, 255, Track)


# imgs=cv2.resize(img,(500,500))
while True:
# success,img = cap.read()
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
u_hue = cv2.getTrackbarPos("Upper Hue", "Color detectors")
u_saturation = cv2.getTrackbarPos("Upper Saturation", "Color detectors")
u_value = cv2.getTrackbarPos("Upper Value", "Color detectors")

l_hue = cv2.getTrackbarPos("Lower Hue", "Color detectors")
l_saturation = cv2.getTrackbarPos("Lower Saturation", "Color detectors")
l_value = cv2.getTrackbarPos("Lower Value", "Color detectors")

print(
f"upper\n",
{u_hue, u_saturation, u_value},
"\n lower",
{l_hue, l_saturation, l_value},
)

Upper_hsv = np.array([u_hue, u_saturation, u_value])
Lower_hsv = np.array([l_hue, l_saturation, l_value])
mask = cv2.inRange(hsv, Lower_hsv, Upper_hsv)
res = cv2.bitwise_and(img, img, mask=mask)
res = cv2.medianBlur(res, 5)

cv2.imshow("video", img)
cv2.imshow("res", res)
if cv2.waitKey(1) & 0xFF == ord("x"):
break

cv2.destroyAllWindows
36 changes: 36 additions & 0 deletions CV_YOLO_Object_Detection_and_Trajectory/tracking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import cv2
import numpy as np

video = cv2.VideoCapture(r"C:\Users\mahek\OneDrive\Desktop\CV Workshop\CV_Workshop-main\res\ball_for_tracking.mov")
cposl = []
while True:
ret, img = video.read()
if not ret:
break

hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

lower_bound = np.array([0, 170, 90])
upper_bound = np.array([4, 255, 255])

mask = cv2.inRange(hsv,lower_bound,upper_bound)
x, y, w, h = cv2.boundingRect(mask)
cv2.rectangle(img, (x - 20, y - 20), (x + w + 20, y + h + 20), (0, 255, 0), 1)



center =( ( x+w ), (y + h))

cposl.append(center)
for pos in cposl:
cv2.circle(img, pos,2, (255,255,255), -1)

cv2.imshow("video", img)
#cv2.imshow("mask", mask)

if cv2.waitKey(1) & 0xFF == ord("x"):
break



cv2.destroyAllWindows()
7 changes: 7 additions & 0 deletions CV_YOLO_Object_Detection_and_Trajectory/yolo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from ultralytics import YOLO

# Load a pretrained YOLO11n model
model = YOLO("yolo11n.pt")

# Run model
model.predict(source=0,conf=0.5,show=True)
46 changes: 46 additions & 0 deletions TARZAN task 2/Greyscale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import cv2
import numpy as np

# Step 1: Read the image (following the dimensions: 800x600x3)
image = cv2.imread("photo.jpg")

# orignal image display
cv2.imshow("Original ", image)

cv2.waitKey(0)
cv2.destroyAllWindows()

# image ko Resize kiya -> 800*600
image = cv2.resize(image, (800, 600))
cv2.imshow("Resized", image)

cv2.waitKey(0)
cv2.destroyAllWindows()

# Step 2: Convert to grayscale (800x600)
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow("Grayscale", gray_image)
cv2.waitKey(0)
cv2.destroyAllWindows()

# Step 3: Reduce resolution (Resizing grayscale image)
low_res_gray_image = cv2.resize(gray_image, (128, 128), interpolation=cv2.INTER_LINEAR)

cv2.imshow("Reduced Resolution Grayscale", low_res_gray_image)
cv2.waitKey(0)
cv2.destroyAllWindows()


# Step 4: Normalize the image (not grayscale) to range [0,1]
normalized_image = cv2.cvtColor(low_res_gray_image, cv2.COLOR_GRAY2BGR)
cv2.imshow("Normalized [0-1]", (normalized_image * 255).astype(np.uint8))
cv2.waitKey(0)
cv2.destroyAllWindows()


# Step 5: Optionally normalize to range [-1,1]
normalized_minus1_to_1 = (normalized_image - 0.5) * 2 # Scale to [-1,1]
cv2.imshow("Normalized [-1,1]", normalized_minus1_to_1)

cv2.waitKey(0)
cv2.destroyAllWindows()
59 changes: 59 additions & 0 deletions TARZAN task 2/Image proccessing optimization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import cv2
import numpy as np

# Step 1: Read the image (following the dimensions: 800x600x3)
image = cv2.imread("photo.jpg")

# orignal image display
cv2.imshow("Original ", image)

cv2.waitKey(0)
cv2.destroyAllWindows()

# image ko Resize kiya -> 800*600
image = cv2.resize(image, (800, 600))
cv2.imshow("Resized", image)

cv2.waitKey(0)
cv2.destroyAllWindows()

# Step 2: Convert to grayscale (800x600)
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow("Grayscale", gray_image)

cv2.waitKey(0)
cv2.destroyAllWindows()


# Step 3: Reduce resolution (Resizing grayscale image)
low_res_gray_image = cv2.resize(gray_image, (128, 128), interpolation=cv2.INTER_LINEAR)
cv2.imshow("Reduced Resolution Grayscale", low_res_gray_image)

cv2.waitKey(0)
cv2.destroyAllWindows()

# Step 3: Reduce resolution (Resizing to lower size for faster processing)
low_res_image = cv2.resize(image, (128, 128), interpolation=cv2.INTER_LINEAR)
cv2.imshow("Reduced Resolution", low_res_image)

cv2.waitKey(0)
cv2.destroyAllWindows()

# Step 4: Normalize the image (not grayscale) to range [0,1]
normalized_image = low_res_image.astype(np.float32) / 255.0
cv2.imshow("Normalized [0-1]", normalized_image)

cv2.waitKey(0)
cv2.destroyAllWindows()

# Step 5: Optionally normalize to range [-1,1]
normalized_minus1_to_1 = (normalized_image - 0.5) * 2 # Scale to [-1,1]
cv2.imshow("Normalized [-1,1]", normalized_minus1_to_1)
cv2.waitKey(0)
cv2.destroyAllWindows()






Binary file added TARZAN task 2/photo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TARZAN task 2/photo2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading