Skip to content

Commit

Permalink
Move library to lib, fix detection c struct, fix cv2.imshow() can't u…
Browse files Browse the repository at this point in the history
…se on a thread
  • Loading branch information
culdo committed Apr 2, 2022
1 parent 604f055 commit fc1938f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
20 changes: 7 additions & 13 deletions darknet_video/core/darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Requires DLL compilation
Both the GPU and no-GPU version should be compiled; the no-GPU version should be renamed "yolo_cpp_dll_nogpu.dll".
Both the GPU and no-GPU version should be compiled; the no-GPU version should be renamed "yolo_cpp_dll_nogpu.lib".
On a GPU system, you can force CPU evaluation by any of:
Expand Down Expand Up @@ -66,11 +66,7 @@ class DETECTION(Structure):
("objectness", c_float),
("sort_class", c_int),
("uc", POINTER(c_float)),
("points", c_int),
("embeddings", POINTER(c_float)),
("embedding_size", c_int),
("sim", c_float),
("track_id", c_int)]
("points", c_int)]


class IMAGE(Structure):
Expand All @@ -89,13 +85,11 @@ class METADATA(Structure):
# lib = CDLL("libdarknet.so", RTLD_GLOBAL)
hasGPU = True
if os.name == "nt":
cwd = os.path.dirname(__file__)
cwd = os.path.join(cwd, "..", "..", "..", "darknet", "build", "darknet", "x64")
os.add_dll_directory('c:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin')
os.add_dll_directory(cwd)
os.environ['PATH'] = cwd + ';' + os.environ['PATH']
winGPUdll = os.path.join(cwd, "yolo_cpp_dll.dll")
winNoGPUdll = os.path.join(cwd, "yolo_cpp_dll_nogpu.dll")
libPath = os.path.dirname(__file__)
libPath = os.path.join(libPath, "..", "..", "lib")
os.environ['PATH'] = libPath + ';' + os.environ['PATH']
winGPUdll = os.path.join(libPath, "yolo_cpp_dll.dll")
winNoGPUdll = os.path.join(libPath, "yolo_cpp_dll_nogpu.lib")
envKeys = list()
for k, v in os.environ.items():
envKeys.append(k)
Expand Down
8 changes: 3 additions & 5 deletions darknet_video/core/thread_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ def __init__(self, url, is_stream_result=False, blocking=True, **kwargs):
def _run(self):
cap_th = self._captrue_stream()
cap_th.start()
detect_th = self._detect_frame()
detect_th.start()
if self.is_stream_result:
server_th = self._stream_result()
server_th.start()
self.yolo.detect_stream()
if self.blocking:
detect_th.join()
cap_th.join()
self._after_clear()
self._check_after_clear()

def _detect_frame(self):
def thread():
Expand All @@ -49,7 +47,7 @@ def thread():

return Thread(target=thread)

def _after_clear(self):
def _check_after_clear(self):
def thread():
while not self.stream.is_stop:
time.sleep(0.01)
Expand Down
Binary file removed darknet_video/libdarknet.so
Binary file not shown.
Binary file added lib/libdarknet.so
Binary file not shown.
6 changes: 3 additions & 3 deletions test/test_darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def mango_yolo(url, weights, **kwargs):
indoor_lab = "rtsp://192.168.0.60:554/user=admin&password=&channel=1&stream=0.sdp?real_stream--rtp-caching=1"
op3_camera = "http://192.168.0.101:8080/stream?topic=/usb_cam_node/image_raw&type=ros_compressed"
gg_phone_ip = "http://203.64.134.168:8000/video"
phone_ip = "http://192.168.0.249:8080/video"
phone_ip = "http://192.168.13.246:8080/video"
wan_phone_ip = "http://203.64.134.168:8082/video"

v4_weights = "bin/yolov4.weights"
Expand All @@ -62,7 +62,7 @@ def mango_yolo(url, weights, **kwargs):
yt_video = get_yt_vid("https://www.youtube.com/watch?v=9XPBNaLXzPo")
# os.environ["CUDA_VISIBLE_DEVICES"] = "1"
if not labeling:
coco_yolo(yt_video, enet_weights, is_realtime=False, is_tracking=False,
meta_file="coco_cht.data", thresh=0.25, show_gui=True)
coco_yolo(phone_ip, enet_weights, is_realtime=True, is_tracking=False,
meta_file="coco_cht.data", thresh=0.25, show_gui=True, is_stream_result=False)
else:
pass

0 comments on commit fc1938f

Please sign in to comment.