YOLOv4 read by OpenCV DNN.
Project description
YOLOv4 darknet by OpenCV DNN.
Install package
pip install yolov4-cv
Code example:
import numpy as np
from yolov4_cv import YOLOv4_CV
import cv2
# Just inherit YOLOv4_CV and define your class_names and class_colors
class YOLOv4(YOLOv4_CV):
# Define coco class names
class_names = [
'person', 'bicycle', 'car', 'motorcycle', 'airplane',
'bus', 'train', 'truck', 'boat', 'traffic light',
'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird',
'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear',
'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag',
'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball',
'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
'tennis racket', 'bottle', 'wine glass', 'cup', 'fork',
'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich',
'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut',
'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table',
'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book',
'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'
]
# Random to generate colors
class_colors = [(int(i[0]), int(i[1]), int(i[2])) for i in np.random.randint(256, size=(len(class_names), 3))]
# Simple camera read
def load_capture():
capture = cv2.VideoCapture(1)
capture.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
return capture
if __name__ == '__main__':
# Load camera
capture = load_capture()
# Load checkpoint from any path. (onnx only)
model = YOLOv4('tests/yolov4-tiny.weights', 'tests/yolov4-tiny.cfg', (416, 416))
while True:
# Get camera frame
success, frame = capture.read()
if not success:
print('Open camera fail.')
break
# Inference all of output result
preds = model(frame)
for pred in preds:
print(pred.id, pred.name, pred.conf, pred.box)
# Show labeled box result
model.show_label_boxes()
# or you can get labeled box result
# img = model.get_label_boxes_image()
# Any key to quit.
if cv2.waitKey(1) > -1:
print('finished by user')
break
capture.release()
Demo example:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
yolov4_cv-0.0.1.tar.gz
(4.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yolov4_cv-0.0.1.tar.gz.
File metadata
- Download URL: yolov4_cv-0.0.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f326a65c10bd9a5eb3aaf81cec9eaf9fe70356ba35b8beaed58153ee3cf6d29
|
|
| MD5 |
b39bcbef5a334cf1854d56732d5c58cb
|
|
| BLAKE2b-256 |
848d3dd7b59a7e664d002279b86c57634c24939309bb18b51735bb171dd7492c
|
File details
Details for the file yolov4_cv-0.0.1-py3-none-any.whl.
File metadata
- Download URL: yolov4_cv-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d3094a4f6096524d8d9eb2fa4f328af9cbd78408559c0304cf39f70df8bd001
|
|
| MD5 |
6e84763fee964e5a6d8af0fcdf0a141b
|
|
| BLAKE2b-256 |
6c05e840adde71ab77997fb1eda54685ac8fdc5adff8f3e53813d518da4578f9
|