1 | initial version |
so, solved with kind help from @dkurt, as always ;)
each detection row looks like: [batchId, classId, confidence, left, top, right, bottom]
given, you start with a list of images:
imgs = [image, image2, image3]
net = cv2.dnn.readNetFromCaffe("face_detector.prototxt", "res10_300x300_ssd_iter_140000_fp16.caffemodel")
blob = cv2.dnn.blobFromImages(imgs, 1.0, (128,96), [104., 117., 123.], False, False)
you have to check the 1st element of each detection, to find out, which image it belongs to:
net.setInput(blob)
detections = net.forward()
for i in range(0, detections.shape[2]):
confidence = detections[0, 0, i, 2]
imgid = int(detections[0, 0, i, 0])
if confidence > 0.7:
(h, w) = imgs[imgid].shape[:2] # also, your imges will have different sizes !
box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
(startX, startY, endX, endY) = box.astype("int")
text = "{:.2f}%".format(confidence * 100)
y = startY - 10 if startY - 10 > 10 else startY + 10
cv2.rectangle(imgs[imgid], (startX, startY), (endX, endY), (0, 0, 255), 2)
cv2.putText(imgs[imgid], text, (startX, y), cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)
for i in range(len(imgs)):
cv2.imshow("img%d" % i, imgs[i])
cv2.waitKey()
2 | No.2 Revision |
so, solved with kind help from @dkurt, as always ;)
each detection row looks like: [batchId, classId, confidence, left, top, right, bottom]
given, you start with a list of images:
imgs = [image, image2, image3]
net = cv2.dnn.readNetFromCaffe("face_detector.prototxt", "res10_300x300_ssd_iter_140000_fp16.caffemodel")
blob = cv2.dnn.blobFromImages(imgs, 1.0, (128,96), [104., 117., 123.], False, False)
you have to check the 1st element of each detection, to find out, which image it belongs to:
net.setInput(blob)
detections = net.forward()
for i in range(0, detections.shape[2]):
imgid = int(detections[0, 0, i, 0]) # here we go !
confidence = detections[0, 0, i, 2]
imgid = int(detections[0, 0, i, 0])
if confidence > 0.7:
(h, w) = imgs[imgid].shape[:2] # also, your imges will have different sizes !
box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
(startX, startY, endX, endY) = box.astype("int")
text = "{:.2f}%".format(confidence * 100)
y = startY - 10 if startY - 10 > 10 else startY + 10
cv2.rectangle(imgs[imgid], (startX, startY), (endX, endY), (0, 0, 255), 2)
cv2.putText(imgs[imgid], text, (startX, y), cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)
for i in range(len(imgs)):
cv2.imshow("img%d" % i, imgs[i])
cv2.waitKey()
3 | No.3 Revision |
so, solved with kind help from @dkurt, as always ;)
each detection row looks like: [batchId, classId, confidence, left, top, right, bottom]
given, you start with a list of images:
imgs = [image, image2, image3]
net = cv2.dnn.readNetFromCaffe("face_detector.prototxt", "res10_300x300_ssd_iter_140000_fp16.caffemodel")
blob = cv2.dnn.blobFromImages(imgs, 1.0, (128,96), [104., 117., 123.], False, False)
you have to check the 1st element of each detection, to find out, which image it belongs to:
net.setInput(blob)
detections = net.forward()
for i in range(0, detections.shape[2]):
imgid = int(detections[0, 0, i, 0]) # here we go !
confidence = detections[0, 0, i, 2]
if confidence > 0.7:
(h, w) = imgs[imgid].shape[:2] # also, your imges images will have different sizes !
box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
(startX, startY, endX, endY) = box.astype("int")
text = "{:.2f}%".format(confidence * 100)
y = startY - 10 if startY - 10 > 10 else startY + 10
cv2.rectangle(imgs[imgid], (startX, startY), (endX, endY), (0, 0, 255), 2)
cv2.putText(imgs[imgid], text, (startX, y), cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)
for i in range(len(imgs)):
cv2.imshow("img%d" % i, imgs[i])
cv2.waitKey()