diff --git a/src/__pycache__/detector.cpython-310.pyc b/src/__pycache__/detector.cpython-310.pyc deleted file mode 100644 index 24458ca..0000000 Binary files a/src/__pycache__/detector.cpython-310.pyc and /dev/null differ diff --git a/src/__pycache__/objectifier.cpython-310.pyc b/src/__pycache__/objectifier.cpython-310.pyc deleted file mode 100644 index 16c8986..0000000 Binary files a/src/__pycache__/objectifier.cpython-310.pyc and /dev/null differ diff --git a/src/detector.py b/src/detector.py old mode 100755 new mode 100644 index 5c61aed..26567be --- a/src/detector.py +++ b/src/detector.py @@ -85,129 +85,3 @@ class Detector: out_file = output_filename if output_filename else self.output_filename(filename) cv.imwrite(out_file, marked) return AnalyzedImage(filename, detections, str(out_file)) - - - - -# net = cv.dnn.readNet("/home/niten/Projects/yolo/yolov3.weights", "/home/niten/Projects/yolo/yolov3.cfg") - -# classes = [] - -# with open("/home/niten/Projects/yolo/coco.names") as f: -# classes = [line.strip() for line in f.readlines()] - -# layer_names = net.getLayerNames() -# output_layer = [layer_names[i - 1] for i in net.getUnconnectedOutLayers()] -# colors = np.random.uniform(0, 255, size=(len(classes), 3)) - -# def scale_int(o, s, m): -# return (m / s) * o - -# def scale_box(orig, scaled, box): -# o_h, o_w, _ = orig.shape -# s_h, s_w, _ = scaled.shape -# x, y, w, h = box -# return [scale_int(o_w, s_w, x), -# scale_int(o_h, s_h, y), -# scale_int(o_w, o_h, w), -# scale_int(o_h, s_h, h)] - -# tmpdir = Path(tempfile.mkdtemp()) - -# def detect_objects(filename): -# simplename = path.splitext(path.basename(filename))[0] -# out_filename = tmpdir / ("processed_" + simplename + ".png") - -# orig = cv.imread(str(filename)) -# img = cv.imread(str(filename)) -# # img = cv.resize(img, None, fx=0.4, fy=0.4) -# height, width, channel = img.shape -# # TODO: Change scale factor? -# blob = cv.dnn.blobFromImage(img, 0.00392, (416, 416), (0, 0, 0), True, crop=False) -# net.setInput(blob) -# outs = net.forward(output_layer) - -# class_ids = [] -# confidences = [] -# boxes = [] - -# detections = [] - -# for out in outs: -# for detection in out: -# scores = detection[5:] -# class_id = np.argmax(scores) -# confidence = scores[class_id] -# if confidence > 0.6: -# center_x = int(detection[0] * width) -# center_y = int(detection[1] * height) -# w = int(detection[2] * width) -# h = int(detection[3] * height) -# x = int(center_x - w/2) -# y = int(center_y - h/2) -# boxes.append([x, y, w, h]) -# confidences.append(float(confidence)) -# class_ids.append(class_id) - -# indexes = cv.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4) - -# font = cv.FONT_HERSHEY_PLAIN -# for i in range(len(boxes)): -# if i in indexes: -# label = str(classes[class_ids[i]]) -# color = colors[i] -# scaled_box = scale_box(orig, img, boxes[i]) -# x, y, w, h = [int(n) for n in scaled_box] -# detections.append(Detection(label, confidences[i], scaled_box)) -# # cv.rectangle(out, (x, y), (x + w, y + h), color, 2) -# # cv.putText(out, label, (x, y + 30), font, 3, color, 3) - -# #cv.imwrite(str(out_filename), out) -# marked = cv.imread(filename) -# for detection in detections: -# x, y, w, h = [int(n) for n in detection.box] -# cv.rectangle(marked, (x,y), (x + w, y + h), (255,255,255,0), 2) -# cv.putText(marked, detection.label, (x, y + 30), font, 3, (255,255,255,0), 1) - -# cv.imwrite(str(out_filename), marked) -# return AnalyzedImage(filename, detections, str(out_filename)) - -# # cv.imshow("IMG", img) -# # cv.waitKey(0) -# # cv.destroyAllWindows() - -# for filename in sys.argv[1:]: -# print(filename + ":") -# output = detect_objects(filename) -# print(" OUTPUT: " + str(output.outfile)) -# for detection in output.detections: -# print(" " + detection.label + -# " (" + str(detection.confidence) + ")" + -# " [" + -# str(detection.box[0]) + ", " + -# str(detection.box[1]) + ", " + -# str(detection.box[2]) + ", " + -# str(detection.box[3]) + -# "]") - - -# classes = [] - -# with open("/home/niten/Projects/yolo/coco.names") as f: -# classes = [line.strip() for line in f.readlines()] - -# detector = Detector("/home/niten/Projects/yolo/yolov3.weights", "/home/niten/Projects/yolo/yolov3.cfg", classes, Path(tempfile.mkdtemp())) - -# for filename in sys.argv[1:]: -# print(filename + ":") -# output = detector.detect_objects(filename) -# print(" OUTPUT: " + str(output.outfile)) -# for detection in output.detections: -# print(" " + detection.label + -# " (" + str(detection.confidence) + ")" + -# " [" + -# str(detection.box[0]) + ", " + -# str(detection.box[1]) + ", " + -# str(detection.box[2]) + ", " + -# str(detection.box[3]) + -# "]")