Basic Examples (4)
Sometimes ROIs (regions of interest) are provided in terms of width and height:
Having to switch between coordinate systems with a top or bottom origin is a very common. When converting to a "TopLeft" or "BottomRight" origin, you need to supply the original image (or its dimensions):
As a convenience, ImageROIConvert handles regions given in XYWH form. They can be given as real pixel coordinate values in the range [0,w]⨯[0,h] or as scaled coordinates in the range [0,1]⨯[0,1]:
To run this example, you first need to connect to a python executable in an environment (e.g. here my environment is named dl) where both opencv and pyzmq are installed (for more details see this workflow):
Now let's draw a rectangle on an image with the python computer vision library OpenCV (which is named cv2 in code):
Convert the coordinate system's origin to "BottomLeft" to plot it:
Create a Rectangle region of interest and highlight it:
To use this in OpenCV (whose python library is named cv2), we ask for a "TopLeft" origin coordinate transform:
Now we can send it to a session for drawing (requires a python installation):
Options (2)
Create a Rectangle with scaled coordinates for use in OpenCV (this example requires a python installation):
If setting the option "ScaledCoordinates"→True, the coordinates of the input are assumed to lie between zero and one:
Applications (5)
Convert object detections from the Wolfram Language to Python (this example requires a python installation):
Highlight the identified bounding boxes:
Convert the bird's bounding boxes to have top left origin:
Export the variables to the python session:
Draw the boxes: