Reputation: 25
I am reading images and finding region of interest by passing top left corner coordinates and bottom right coordinates of rectangle then croping the image.Some client provides samples like 100 dpi, 200 dpi or 400 dpi images of same image. In these kind of images, input coordinates lie somewhere else when images having different dpi. I am doing template matching task where i have given small template which contain text. After finding text, bounding box is drawn to that matched part. From that bounding box reference, i have to find parent rectangle from image then save in folder. For 100 dpi image, it is working but once i change image with different dpi rectangle shrinks. Images are:
Below code is updated in template matching link:
startX = abs(startX - 113)
startY = abs(startY - 5)
endX = abs(endX + 117)
endY = abs(endY + 208)
cv2.rectangle(image, (startX, startY), (endX, endY), (0, 0, 255), 2)
Below code is for finding rectangle and cropping:
first = [660,1000]
last = [1030,1400]
i = 1
for imagePath in glob.glob(args["images"] + "/*.jpg"):
print imagePath
image = cv2.imread(imagePath)
cropped = ROI_extract(first,last,image)
savingName = "SGBAU_pink/pnr" + str(i) + ".jpg"
cv2.imwrite(savingName, cropped)
i = i + 1
cv2.imshow("Cropped",cropped)
cv2.waitKey(0)
How can i fix a problem to find actual area of interest for different dpi of images and find exact ROI? Give some rough idea to solve it.
Upvotes: 2
Views: 868
Reputation: 434
OpenCV doesn't really care about DPI, it simply uses Mat to contain an image. I'm not really sure I understand what you're trying to acompilish but if you have coordinates in inches and you know source DPI you can convert them in rows and cols:
x_px = x_inch * DPI
y_px = y_inch * DPI
Otherwise, if all the images have the same proportions but different resolutions, you can simply scale them to one reference size (i.e. the 100dpi resolution which is working). In order to do that, you can use resize function in OpenCV.
Upvotes: 1