Open Startonix opened 1 month ago
yolo_detection.py
import cv2
net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg") layer_names = net.getLayerNames() output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
def detect_objects(image_path): img = cv2.imread(image_path) height, width, channels = img.shape blob = cv2.dnn.blobFromImage(img, 0.00392, (416, 416), (0, 0, 0), True, crop=False) net.setInput(blob) outs = net.forward(output_layers) return outs
outs = detect_objects("example.jpg") print(outs)
yolo_detection.py
import cv2
net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg") layer_names = net.getLayerNames() output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
def detect_objects(image_path): img = cv2.imread(image_path) height, width, channels = img.shape blob = cv2.dnn.blobFromImage(img, 0.00392, (416, 416), (0, 0, 0), True, crop=False) net.setInput(blob) outs = net.forward(output_layers) return outs
Example usage
outs = detect_objects("example.jpg") print(outs)