Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Here I tried, but it's not working. What the correct way to do this? Here's my attempt:

What I have tried:

<pre>import cv2
with open("annotationfile\\orange.txt") as iostream:
content = iostream.read()
color = (0, 0, 255) # RED
for line in content.split("\\n"):
image_path = "images\\orange.jpg"
label, xmin, ymin, xmax, ymax = line.split(",")
image = cv2.imread(image_path)
pt1 = (int(xmin), int(ymin))
pt2 = (int(xmax), int(ymax))
cv2.rectangle(image, pt1, pt2, color)
cv2.imshow("Visualization bounding box", image)
cv2.waitKey()
outfile = image_path\[:-4\] + "\_bbox.jpg"
outimage = image\[int(ymin):int(ymax), int(xmin):int(xmax)\]
cv2.imwrite(outfile, outimage)
Posted
Updated 11-Jun-23 21:38pm
v2
Comments
OriginalGriff 12-Jun-23 1:05am    
"It doesn't work" is probably the most useless problem report we get - and we get it a lot. It tells us nothing about what is happening, or when it happens.
So tell us what it is doing that you didn't expect, or not doing that you did.
Tell us what you did to get it to happen.
Tell us any error messages.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

I usually convert the txt format to a file, convert it to PDF and output from that file in any language, even Python. .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900