'Display image without shape pyqt

I am trying to create a pyqt application which contains three windows.

  1. Display video stream from camera as BGR format using QPixmap and opencv.
  2. Display Masked image using QPixmap and opencv.
  3. Display screen grab using PIL library, opencv and QPixmap.

The error that I face while displaying masked & screen grab frame is given below.

screen_grab_height, screen_grab_width, screen_grab_channel = image_grab_frame.shape ValueError: not enough values to unpack (expected 3, got 2)

When I checked the frame.shape I found that it has only two values, i.e. image_height and image_width. It does not have image_channel value.

I am attaching the code for both the functions below,

  1. Masked image
mask = cv2.inRange(hsv, lower_hue, upper_hue)
mask1=cv2.bitwise_not(mask)
hsv_height, hsv_width, hsv_channel = hsv_image.shape
hsv_step = hsv_channel * hsv_width
mask_height, mask_width, mask_channel = mask_frame.shape
mask_step = mask_channel * mask_width
convertToQFormat = QImage(mask_frame.data, mask_frame.shape[1], mask_frame.shape[0], QImage.Format_RGB888)
pic = convertToQFormat.scaled(1280, 720, Qt.KeepAspectRatio)
self.normal_screen.setPixmap(QPixmap.fromImage(pic))

and

  1. screen grab
screen_grab_height, screen_grab_width, screen_grab_channel = image_grab_frame.shape
screen_grab_step = screen_grab_channel * screen_grab_width

#Display image grab#
convertToQFormat = QImage(image_grab_frame.data,image_grab_frame.shape[1], image_grab_frame.shape[0], QImage.Format_RGB888)
image_grab_pic = convertToQFormat.scaled(1280, 720, Qt.KeepAspectRatio)     

self.normal_screen.setPixmap(QPixmap.fromImage(image_grab_pic))


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source