Yolov4Detector
Project description
Introduction
Darknet python interface. Tested only in Python3.6, Jetpack4.4, Ubuntu 16.04 and Ubuntu 18.04.
Pre-Installation
- darknet: please set the DARKNET_PATH with libdarknet.so file in environmental varaible. If you don't know how to compile darknet to generate libdarknet.so, please refer to the following commands.
# in the darknet path
import os
import shutil
shutil.copyfile('Makefile', 'Makefile_copy')
with open('Makefile', 'w') as fw, open('Makefile_copy', 'r') as fr:
for line in fr:
if line in ['GPU=0\n', 'CUDA=0\n', 'CUDNN=0\n' , 'CUDNN_HALF=0\n', 'LIBSO=0\n', 'OPENCV=0\n']: # 'DEBUG=0\n'
fw.write(line.replace('=0', '=1'))
else:
fw.write(line)
exit()
Installation
pip3 install Yolov4Detector
Usage
image
import cv2
from Yolov4Detector import io, Detector
from Yolov4Detector.utils import plot_one_box
# initialize Detector
cfg_fp, names_fp, weights_fp = io.get_test_params()
detector = Detector(cfg_fp, names_fp, weights_fp)
img_fp = io.get_test_data('bus')
image_bgr = cv2.imread(img_fp)
boxes, confs, clses = detector.detect(image_bgr, conf_thres=0.15, iou_thres=0.6)
if len(boxes) != 0:
for xyxy, conf, cls in zip(boxes, confs, clses):
plot_one_box(xyxy, image_bgr, label=cls, color=(255, 0, 0))
print(xyxy, conf, cls)
cv2.imshow('img', image_bgr)
cv2.waitKey(0)
cv2.destroyAllWindows()
video
import cv2
from datetime import datetime, timedelta
from Yolov4Detector import io, Detector
from Yolov4Detector.utils import plot_one_box
cfg_fp, names_fp, weights_fp = io.get_test_params()
detector = Detector(cfg_fp, names_fp, weights_fp)
img_fp = '<video_fp>'
cap = cv2.VideoCapture(img_fp)
count = 0
st = datetime.now()
while(True):
ret, image_bgr = cap.read()
conf_thres = 0.15
iou_thres = 0.6
boxes, confs, clses = detector.detect(image_bgr, conf_thres=conf_thres, iou_thres=iou_thres)
if boxes is not None:
for xyxy, conf, cls in zip(boxes, confs, clses):
plot_one_box(xyxy, image_bgr, label=cls, color=(255, 0, 0))
cv2.imshow('frame', image_bgr)
count += 1
if datetime.now()- st > timedelta(seconds=1):
print("fps:", count)
count = 0
st = datetime.now()
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
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
Yolov4Detector-0.1.2.tar.gz
(23.2 MB
view details)
Built Distribution
File details
Details for the file Yolov4Detector-0.1.2.tar.gz
.
File metadata
- Download URL: Yolov4Detector-0.1.2.tar.gz
- Upload date:
- Size: 23.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.6.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f443afb0fa6c4bdcab09e25938e97d3573ebe5ca13260411d8f208af50e219ed |
|
MD5 | 1a6b5d49054f085f31fec8e7e14f51b8 |
|
BLAKE2b-256 | 539780a46743e93c6a2d0cb0c9ba1a4222ba8eb0a4662a06d054d7749f55fb4e |
File details
Details for the file Yolov4Detector-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: Yolov4Detector-0.1.2-py3-none-any.whl
- Upload date:
- Size: 23.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.6.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 547fc9f428de32637838fdeea4ebbdda01cb723f2c9a664585c7fbbf7517e4e7 |
|
MD5 | 06eaf6b0ea51c1ea91b44a270c90eb8b |
|
BLAKE2b-256 | d1e7bdc19c30c4d2ace4177092d59219969b6ba5d63dbbf0f3dfa55aeeeaca64 |