title: How to show image to PYQT with opencv
body: <p><strong>Hello I'm new in python and opencv</strong></p>
  
  <p>I want to ask, how to show my image in qlabel (pyqt) and i want to convert qlabel to grayscale. </p>
  
  <pre><code>import sys
  from PyQt5.uic import loadUi
  from PyQt5.QtWidgets import QMainWindow, QApplication, QFileDialog
  import cv2
  from PyQt5 import QtCore, QtGui, QtWidgets
  from PyQt5.QtGui import *
  from PyQt5.QtCore import *
  
  class UIProgram(QMainWindow):
  def __init__(self):
      super(UIProgram,self).__init__()
      loadUi("Backpro2.ui",self)
      #self.image=None
      self.trainLoadImgBtn.clicked.connect(self.loadClicked)
      self.image = QImage()
  @pyqtSlot()
  def loadClicked(self):
      fname,filter=QFileDialog.getOpenFileName(self,'Open File','D:\\',"Image Files(*.jpg)")
      if fname:
          self.loadImage(fname)
      else:
          print('invalid image')
  
  def loadImage(self,fname):
      self.image=cv2.imread(fname,cv2.IMREAD_COLOR)
      self.displayImage()
  
  def displayImage(self):
      qformat =QImage.Format_Indexed8
  
      if len(self.image.shape)==3:
          if(self.image.shape[2])==4:
              qformat=QImage.Format_RGBA8888
          else:
              qformat=QImage.Format_RGB888
          img=QtGui.QImage(self.image.data,self.image.shape[1],self.image[0],QtGui.QImage.Format_RGB888)
  
          img = img.rgbSwapped()
          self.trainOpenImg.setPixmap(QPixmap.fromImage(img))
          self.trainOpenImgn.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignVCenter)
  
  
  
  if __name__ == "__main__":
  
  app=QApplication(sys.argv)
  window=UIProgram()
  window.setWindowTitle('Test')
  window.show()
  sys.exit(app.exec_())
  </code></pre>
  
  <p>it crashed when i click load image button, the image can't show in qlabel
  and this error</p>
  
  <blockquote>
    <p>Process finished with exit code -1073740791 (0xC0000409)</p>
  </blockquote>