Home > other >  Editing image in Python via OpenCV and displaying it in PyQt5 ImageView?
Editing image in Python via OpenCV and displaying it in PyQt5 ImageView?

Time:10-21

I am taking a live image from a camera in Python and displaying it in an ImageView in my PyQt5 GUI, presenting it as a live feed. Is is displaying fine, but I would like to draw a red crosshair on the center of the image to help the user know where the object of focus moved, relative to the center of the frame.

I tried drawing on it using "cv2.line(params)" but I do not see the lines. This is strange to me because in C , when you draw on an image, it takes the mat and changes that mat in the code going forward. How can I display this on the UI window without having to make a separate call to cv2.imshow()?

This is the signal from the worker thread that changes the image, it emits an ndarray and a bool:

def pipeline_camera_acquire(self):
    while True:     
        self.mutex.lock()
        #get data and pass them from camera to img object
        self.ximeaCam.get_image(self.img)

        #get data from camera as numpy array
        data_pic = self.img.get_image_data_numpy()

        #Edits
        cv2.line(data_pic, (-10,0), (10,0), (0,0,255), 1)
        cv2.line(data_pic, (0,10), (0,-10), (0,0,255), 1)
        self.editedIMG = np.rot90(data_pic, 3)

        self.mutex.unlock()

        #send signal to update GUI
        self.imageChanged.emit(self.editedIMG, False)

CodePudding user response:

I don't think that it isn't drawing the line, I think it just is drawing it out of the visible area. (0,0) is the upper right hand corner of the image, so (0,10),(0,-10), would be a thin line right at the edge of the image.

If you are trying to draw in the center then you should calculate it from the center of the numpy array.

For example:

x, y = data_pic.shape[0]//2, data_pic.shape[1]//2
cv2.line(data_pic, (x-10,y), (x 10,y), (0,0,255), 1)
cv2.line(data_pic, (x, y-10), (x, y 10), (0,0,255), 1)

That should draw the

  • Related