anais_test
This commit is contained in:
BIN
mid_image.jpg
Normal file
BIN
mid_image.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 468 KiB |
BIN
rectangle_edges.jpg
Normal file
BIN
rectangle_edges.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
43
shapeDetectionImageCrop.py
Normal file
43
shapeDetectionImageCrop.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import cv2
|
||||
|
||||
# Load the image
|
||||
image = cv2.imread("mid_image.jpg")
|
||||
|
||||
# Convert image to grayscale
|
||||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
# Resize the image to half its original size for display (pop up window)
|
||||
scale_percent = 20 # percent of original size
|
||||
width = int(gray.shape[1] * scale_percent / 100)
|
||||
height = int(gray.shape[0] * scale_percent / 100)
|
||||
dim = (width, height)
|
||||
|
||||
resized_gray = cv2.resize(gray, dim, interpolation=cv2.INTER_AREA)
|
||||
|
||||
# Show resized image
|
||||
cv2.imshow("Detected Rectangle", resized_gray)
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
|
||||
"""# Apply Gaussian blur
|
||||
blur = cv2.GaussianBlur(gray, (5, 5), 0)
|
||||
|
||||
# Run Canny edge detector
|
||||
edges = cv2.Canny(blur, 50, 150)
|
||||
|
||||
# Find contours
|
||||
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
|
||||
# Select the largest contour (presumed to be the rectangle)
|
||||
contour = max(contours, key=cv2.contourArea)
|
||||
|
||||
# Draw the detected contour on a copy of the original image
|
||||
output = image.copy()
|
||||
cv2.drawContours(output, [contour], -1, (0, 255, 0), 3)
|
||||
|
||||
# Save or show the result
|
||||
cv2.imwrite("rectangle_edges.jpg", output)
|
||||
cv2.imshow("Detected Rectangle", output)
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()"""
|
||||
BIN
spotify_template.png
Normal file
BIN
spotify_template.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
44
stream_logo.py
Normal file
44
stream_logo.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import cv2
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO('yolov5s.pt') # Replace with your trained logo detection model path
|
||||
cap = cv2.VideoCapture(0) # Webcam input
|
||||
|
||||
if not cap.isOpened():
|
||||
print("Error: Could not open video stream.")
|
||||
exit()
|
||||
|
||||
while True:
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
|
||||
results = model(frame)
|
||||
|
||||
for result in results:
|
||||
boxes = result.boxes.xyxy.cpu().numpy()
|
||||
scores = result.boxes.conf.cpu().numpy()
|
||||
class_ids = result.boxes.cls.cpu().numpy()
|
||||
|
||||
for box, score, cls_id in zip(boxes, scores, class_ids):
|
||||
if score < 0.3:
|
||||
continue
|
||||
|
||||
x1, y1, x2, y2 = map(int, box)
|
||||
label = model.names[int(cls_id)]
|
||||
|
||||
# Draw bounding box and label
|
||||
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
||||
cv2.putText(frame, f'{label} {score:.2f}', (x1, y1 - 10),
|
||||
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
|
||||
|
||||
# Log detection to console
|
||||
print(f"Detected: {label} | Confidence: {score:.2f} | Box: ({x1}, {y1}), ({x2}, {y2})")
|
||||
|
||||
cv2.imshow('Logo Detection', frame)
|
||||
|
||||
if cv2.waitKey(1) & 0xFF == 27:
|
||||
break
|
||||
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
41
video.py
41
video.py
@@ -1,41 +0,0 @@
|
||||
import cv2
|
||||
from pyzbar import pyzbar
|
||||
import subprocess
|
||||
|
||||
def detect_qr_code(frame):
|
||||
detected_barcodes = pyzbar.decode(frame)
|
||||
for barcode in detected_barcodes:
|
||||
if barcode.type == 'QRCODE':
|
||||
return barcode.data.decode('utf-8')
|
||||
return None
|
||||
|
||||
def main():
|
||||
cap = cv2.VideoCapture(0) # open default USB camera (index 0)
|
||||
if not cap.isOpened():
|
||||
print('Error: Cannot access camera')
|
||||
return
|
||||
|
||||
print('Starting camera. Press q to quit.')
|
||||
|
||||
while True:
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
print('Error: Cannot read frame')
|
||||
break
|
||||
|
||||
qr_data = detect_qr_code(frame)
|
||||
if qr_data:
|
||||
print(f'Detected QR Code: {qr_data}')
|
||||
# Call the play script with this QR code data as argument
|
||||
subprocess.Popen(['python3', 'play_spotify.py', qr_data])
|
||||
break
|
||||
|
||||
cv2.imshow('QR Code Detector', frame)
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
BIN
yolov5su.pt
Normal file
BIN
yolov5su.pt
Normal file
Binary file not shown.
Reference in New Issue
Block a user