To explain the question a bit. I have an image that already contains a white bounding box as shown here: Input image
What I need is to crop the part of the image surrounded by the bounding box.
FindContours doesn't seem to work here so I tried something using the following code:
import cv2
import numpy as np
bounding_box_image = cv2.imread('PedestrianRectangles/1/grim.pgm')
edges = cv2.Canny(bounding_box_image, 50, 100) # apertureSize=3
cv2.imshow('edge', edges)
cv2.waitKey(0)
lines = cv2.HoughLinesP(edges, rho=0.5, theta=1 * np.pi / 180,
threshold=100, minLineLength=100, maxLineGap=50)
# print(len(lines))
for i in lines:
for x1, y1, x2, y2 in i:
# print(x1, y1, x2, y2)
cv2.line(bounding_box_image, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.imwrite('houghlines5.jpg', bounding_box_image)
without any success. Playing around with the parameters didn't help too much either. The result of my code snippet is show on the following image: Output
I had the idea to do cropping after the line detection etc.
I am relatively new to opencv so help would be appreciated. Is there a good or easy approach to this problem that I'm missing? Googling around didn't help so any links, code snippets would be helpful.