Linked Questions

Popular Questions

Is it possible to set OpenCV to use the bottom-left corner of the image as the origin?

I'm using cv2.imshow() to display an image in a window that allows me to click on the image and get coordinates on mouseclick events. I can use part of the answer from this question to get the image displayed how I would like it (inverted on the x-axis) however when I click on the image to retrieve coordinates the origin is still in the top-left corner of the image.

import cv2 # Version 3.4.5
import imutils as im
import numpy as np
import matplotlib.pyplot as plt

list_of_coords = []
def store_mouse_coords(event, x, y, flags, params):
    global list_of_coords
    if event == cv2.EVENT_LBUTTONDOWN:
        list_of_coords.append((x, y))
    return list_of_coords

def select_points_on_im(image, window_name='Select points'):
    image = image.copy()
    image = image[::-1, :, :]
    while True:
        cv2.setMouseCallback(window_name, store_mouse_coords)
        cv2.imshow(window_name, image)
        #plt.imshow(window_name, image, plt.gca().invert_yaxis,
        key = cv2.waitKey(0) & 0xFF
        if key == ord("q"):


The line commented out line plt.imshow(window_name, image, plt.gca().invert_yaxis, is what I'd like to acheive but using imshow from OpenCV so that I can use is with my callback function. I'm using Python3 and OpenCV version 3.4.5.

Related Questions