CV Task
CV Task
Task-5
Classify the vehicles on the road and calculate the total count of vehicles moving along the roadway
in the traffic monitoring video
import cv2
import numpy as np
# Load YOLO
layer_names = net.getLayerNames()
classes = open("coco.names").read().strip().split("\n")
# Load video
cap = cv2.VideoCapture('traffic_video.mp4')
while cap.isOpened():
if not ret:
break
net.setInput(blob)
outs = net.forward(output_layers)
vehicle_count = 0
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]
x, y = center_x - w // 2, center_y - h // 2
label = str(classes[class_id])
if label in vehicle_classes:
vehicle_count += 1
break
cap.release()
cv2.destroyAllWindows()
__________________________________________________________________________________
Task-6
Apply image segmentation to identify and locate the people present in the Video Surveillance
import cv2
import numpy as np
import tensorflow as tf
# Load the DeepLabV3 model from TensorFlow Hub
model = tf.saved_model.load("https://tfhub.dev/tensorflow/deeplabv3/1")
def run_model(image):
result = model(image)
return result['semantic_predictions'][0]
# Load video
cap = cv2.VideoCapture('surveillance_video.mp4')
while cap.isOpened():
if not ret:
break
# Preprocess frame
input_tensor = tf.convert_to_tensor(frame)
# Run model
seg_map = run_model(input_tensor)
break
cap.release()
cv2.destroyAllWindows()
Task-7
Build a computer vision-based QR Code Scanner designed for seamless contactless transactions,
ensuring the security and efficiency of mobile payments
import cv2
def decode_qr_code(frame):
qr_codes = pyzbar.decode(frame)
x, y, w, h = qr_code.rect
qr_data = qr_code.data.decode('utf-8')
qr_type = qr_code.type
process_qr_data(qr_data)
return frame
def process_qr_data(qr_data):
cap = cv2.VideoCapture(0)
while True:
if not ret:
break
frame = decode_qr_code(frame)
break
cap.release()
cv2.destroyAllWindows()