I am currently using YOLOv8 object detection to detect fruits through an external camera. Fruits are being detected successfully, but I need to have the hyperlink of the detected fruit to appear right above the bounding box(near the label),clicking on which redirects me to its corresponding webpage. How do implement this?
I've tried using a function cv2.putText() wherein instead of the label I put t="<a href='"+label+".html'/>
" which I expected to display the hyperlink..but it only shows the text as it is(eg:apple.html,orange.html).
def box_label(image, box, label='', color=(128, 128, 128), txt_color=(255, 255, 255)):
lw = max(round(sum(image.shape) / 2 * 0.003), 2)
p1, p2 = (int(box[0]), int(box[1])), (int(box[2]), int(box[3]))
cv2.rectangle(image, p1, p2, color, thickness=lw, lineType=cv2.LINE_AA)
if label:
tf = max(lw - 1, 1) # font thickness
w, h = cv2.getTextSize(label, 0, fontScale=lw / 3, thickness=tf)[0] # text width, height
outside = p1[1] - h >= 3
p2 = p1[0] + w, p1[1] - h - 3 if outside else p1[1] + h + 3
cv2.rectangle(image, p1, p2, color, -1, cv2.LINE_AA) # filled
t="<a href='"+label+".html'/>"
cv2.putText(image,
t, (p1[0], p1[1] - 2 if outside else p1[1] + h + 2),
0,
lw / 3,
txt_color,
thickness=tf,
lineType=cv2.LINE_AA)