예제 #1
0
 def cameraOpen(self):
     """Open camera following the source given.
     """
     self.videoStreamURL = self.winOpenCam.video_source()
     if self.videoStreamURL is None:
         pass
     else:
         self.cap = cv2.VideoCapture(self.videoStreamURL)
         self.coordinate_point = None
         self.ret, self.image = self.cap.read()
         if self.image is None:
             QtWidgets.QMessageBox.information(self, "Information",
                                               "No source camera founded")
         else:
             QtWidgets.QMessageBox.information(
                 self, "Information", "Select Parameter Camera !!")
             file_name = select_file("Select Left Parameter", "../",
                                     "Parameter Files (*.json)")
             if file_name:
                 self.moildev = Moildev(file_name)
                 self.videoControl.videoButtonCamera()
                 self.fps = self.cap.get(cv2.CAP_PROP_FPS)
                 self.cam = True
                 self.next_frame_slot()
             else:
                 self.cap.release()
    def importMoildev(self):
        """Create moildev instance from moildev SDK share object library

        :return: None
        :rtype: None
        """
        self.moildev = Moildev(
            self.camera, self.sensor_width, self.sensor_height, self.Icx,
            self.Icy, self.ratio, self.imageWidth, self.imageHeight,
            self.calibrationRatio, self.parameter0, self.parameter1,
            self.parameter2, self.parameter3, self.parameter4, self.parameter5)
        self.map_x = np.zeros((self.imageHeight, self.imageWidth),
                              dtype=np.float32)
        self.map_y = np.zeros((self.imageHeight, self.imageWidth),
                              dtype=np.float32)
        self.res = self.create_map_result_image()
예제 #3
0
 def open_video_file(self):
     """Load video file.
     """
     videoFile = select_file("Select Video Files", "../",
                             "Image Files (*.mp4 *.avi *.mpg *.gif *.mov)")
     if videoFile:
         paramName = select_file("Select Parameter", "../",
                                 "Parameter Files (*.json)")
         if paramName:
             self.anypoint.resetAlphaBeta()
             self.videoControl.videoButtonEnable()
             self.coordinate_point = None
             self.moildev = Moildev(paramName)
             self.cap = cv2.VideoCapture(videoFile)
             self.fps = self.cap.get(cv2.CAP_PROP_FPS)
             self.cam = True
             self.next_frame_slot()
예제 #4
0
 def importMoildev(self):
     """Instantiate moildev library
     """
     self.init_parameter()
     self.moildev = Moildev(
         self.camera, self.sensor_width, self.sensor_height, self.Icx,
         self.Icy, self.ratio, self.imageWidth, self.imageHeight,
         self.parameter0, self.parameter1, self.parameter2, self.parameter3,
         self.parameter4, self.parameter5, self.calibrationRatio)
예제 #5
0
 def onclick_open_image(self):
     """Open Dialog to search the file image on local directory.
     """
     filename = select_file("Select Image", "../", "Image Files (*.jpeg *.jpg *.png *.gif *.bmg)")
     if filename:
         param_name = select_file("Select Parameter", "../", "Parameter Files (*.json)")
         if param_name:
             self.moildev = Moildev(param_name)
             self.image = read_image(filename)
             self.show_image.show_result_image(self.image, self.width_result_image)
             self.show_image.show_original_image(self.image, self.width_original_image)
예제 #6
0
 def open_image(self):
     """Load image frame
     """
     self.filename = select_file(
         "Select Image", "../",
         "Image Files (*.jpeg *.jpg *.png *.gif *.bmg)")
     if self.filename:
         file_name = select_file("Select Parameter", "../",
                                 "Parameter Files (*.json)")
         if file_name:
             self.ui.btn_Anypoint.setChecked(False)
             self.ui.btn_Panorama.setChecked(False)
             self.image = read_image(self.filename)
             self.h, self.w = self.image.shape[:2]
             image = self.image.copy()
             self.showing.view_result(image)
             self.ratio_x, self.ratio_y, self.center = self.init_ori_ratio(
                 self.image)
             self.cam = False
             self.moildev = Moildev(file_name)
             self.anypoint.resetAlphaBeta()
class Moildev_config(object):
    def __init__(self, filename):
        """This is the initial configuration that you need provide the parameter. The camera parameter is the result
        from calibration camera by MOIL laboratory. before the successive functions can work correctly,configuration
        is necessary in the beginning of program.

        :param filename: .json file
        :type filename: dictionary
        """
        super(Moildev_config, self).__init__()
        self.PI = 3.1415926
        self.alphaToRho_Table = []
        self.rhoToAlpha_Table = []
        if filename is None:
            pass
        else:
            with open(filename) as f:
                data = json.load(f)
            self.camera = data["cameraName"]
            self.sensor_width = data['cameraSensorWidth']
            self.sensor_height = data['cameraSensorHeight']
            self.Icx = data['iCx']
            self.Icy = data['iCy']
            self.ratio = data['ratio']
            self.imageWidth = data['imageWidth']
            self.imageHeight = data['imageHeight']
            self.calibrationRatio = data['calibrationRatio']
            self.parameter0 = data['parameter0']
            self.parameter1 = data['parameter1']
            self.parameter2 = data['parameter2']
            self.parameter3 = data['parameter3']
            self.parameter4 = data['parameter4']
            self.parameter5 = data['parameter5']

        self.initAlphaRho_Table()
        self.importMoildev()

    def get_cameraName(self):
        """Get camera name.

        :return: Camera name
        :rtype: string
        """
        return self.camera

    def get_sensorWidth(self):
        """Get sensor width of camera.

        :return: sensor_width
        :rtype: float
        """
        return self.sensor_width

    def get_sensor_height(self):
        """Get sensor height of camera.

        :return: sensor_height
        :rtype: float
        """
        return self.sensor_height

    def get_Icx(self):
        """Get center image from width image.

        :return: Image center X
        :rtype: int
        """
        return self.Icx

    def get_Icy(self):
        """Get center image from height image.

        :return: Image center Y
        :rtype: int
        """
        return self.Icy

    def get_ratio(self):
        """Get ratio camera.

        :return: ratio
        :rtype: float
        """
        return self.ratio

    def get_imageWidth(self):
        """Get image width.

        :return: image width
        :rtype: int
        """
        return self.imageWidth

    def get_imageHeight(self):
        """Get image height.

        :return: image height
        :rtype: int
        """
        return self.imageHeight

    def get_calibrationRatio(self):
        """Get calibration ratio of camera.

        :return: calibration ratio
        :rtype: float
        """
        return self.calibrationRatio

    def get_parameter0(self):
        """Get camera parameter.

        :return: Parameter 0
        :rtype: float
        """
        return self.parameter0

    def get_parameter1(self):
        """Get camera parameter.

        :return: Parameter 1
        :rtype: float
        """
        return self.parameter1

    def get_parameter2(self):
        """Get camera parameter.

        :return: Parameter 2
        :rtype: float
        """
        return self.parameter2

    def get_parameter3(self):
        """Get camera parameter.

        :return: Parameter 3
        :rtype: float
        """
        return self.parameter3

    def get_parameter4(self):
        """Get camera parameter.

        :return: Parameter 4
        :rtype: float
        """
        return self.parameter4

    def get_parameter5(self):
        """Get camera parameter.

        :return: Parameter 5
        :rtype: float
        """
        return self.parameter5

    def importMoildev(self):
        """Create moildev instance from moildev SDK share object library

        :return: None
        :rtype: None
        """
        self.moildev = Moildev(
            self.camera, self.sensor_width, self.sensor_height, self.Icx,
            self.Icy, self.ratio, self.imageWidth, self.imageHeight,
            self.calibrationRatio, self.parameter0, self.parameter1,
            self.parameter2, self.parameter3, self.parameter4, self.parameter5)
        self.map_x = np.zeros((self.imageHeight, self.imageWidth),
                              dtype=np.float32)
        self.map_y = np.zeros((self.imageHeight, self.imageWidth),
                              dtype=np.float32)
        self.res = self.create_map_result_image()

    def create_map_result_image(self):
        """Create Maps image from zeroes matrix for result image

        :return: Matrix
        :rtype: float
        """
        size = self.imageHeight, self.imageWidth, 3
        return np.zeros(size, dtype=np.uint8)

    def get_anypoint_maps(self, alpha, beta, zoom, mode=1):
        """The purpose is to generate a pair of X-Y Maps for the specified alpha, beta and zoom parameters,
        the result X-Y Maps can be used later to remap the original fisheye image to the target angle image.

        :param alpha: alpha
        :type alpha: float
        :param beta: beta
        :type beta: float
        :param zoom: decimal zoom factor, normally 1..12
        :type zoom: int
        :param mode: selection anypoint mode(1 or 2)
        :type mode: int
        :return: map_x, map_y
        :rtype: float
        """
        if mode == 1:
            if beta < 0:
                beta = beta + 360
            if alpha < -90 or alpha > 90 or beta < 0 or beta > 360:
                alpha = 0
                beta = 0

            else:
                alpha = -90 if alpha < -90 else alpha
                alpha = 90 if alpha > 90 else alpha
                beta = 0 if beta < 0 else beta
                beta = 360 if beta > 360 else beta
            self.moildev.AnyPointM(self.map_x, self.map_y, alpha, beta, zoom)

        else:
            if alpha < -90 or alpha > 90 or beta < -90 or beta > 90:
                alpha = 0
                beta = 0

            else:
                alpha = -90 if alpha < -90 else alpha
                alpha = 90 if alpha > 90 else alpha
                beta = -90 if beta < -90 else beta
                beta = 90 if beta > 90 else beta
            self.moildev.AnyPointM2(self.map_x, self.map_y, alpha, beta, zoom)
        return self.map_x, self.map_y

    def get_panorama_maps(self, alpha_min, alpha_max):
        """ To generate a pair of X-Y Maps for alpha within 0..alpha_max degree, the result X-Y Maps can be used later
        to generate a panorama image from the original fisheye image..

        :param alpha_min: alpha min
        :type alpha_min: float
        :param alpha_max: alpha max
        :type alpha_max: float
        :return: pair maps x-y
        :rtype: array
        """
        self.moildev.Panorama(self.map_x, self.map_y, alpha_min, alpha_max)
        return self.map_x, self.map_y

    def anypoint_view(self, image, alpha, beta, zoom, mode=1):
        """Generate anypoint view.for mode 1, the result rotation is betaOffset degree rotation around the
        Z-axis(roll) after alphaOffset degree rotation around the X-axis(pitch). for mode 2, The result rotation
        is thetaY degree rotation around the Y-axis(yaw) after thetaX degree rotation around the X-axis(pitch).

        :param image: source image
        :type image: array
        :param alpha: alpha
        :type alpha: float
        :param beta: beta
        :type beta: float
        :param zoom: zoom
        :type zoom: int
        :param mode: mode anypoint view
        :type mode: int
        :return: anypoint view
        :rtype: array
        """
        map_x, map_y = self.get_anypoint_maps(alpha, beta, zoom, mode)
        image = cv2.remap(image, map_x, map_y, cv2.INTER_CUBIC)
        return image

    def panorama(self, image, alpha_min, alpha_max):
        """The panorama image centered at the 3D direction with alpha = iC_alpha_degree and beta = iC_beta_degree

        :param image:
        :type image:
        :param alpha_min:
        :type alpha_min:
        :param alpha_max:
        :type alpha_max:
        :return:
        :rtype:
        """
        map_x, map_y = self.get_panorama_maps(alpha_min, alpha_max)
        image = cv2.remap(image, map_x, map_y, cv2.INTER_CUBIC)
        return image

    def reverse_image(self, image, alpha_max, alpha, beta):
        """To generate the image reverse image from panorama that can change the focus direction from the original
        images. The panorama reverse image centered at the 3D direction with alpha_max = max of alpha and beta =
        iC_beta_degree.

        :param image: source image
        :type image: array
        :param alpha_max: alpha max
        :type alpha_max: float
        :param alpha: alpha
        :type alpha: float
        :param beta: beta
        :type beta: float
        :return: reverse image
        :rtype: array
        """
        self.moildev.PanoramaM_Rt(self.map_x, self.map_y, alpha_max, alpha,
                                  beta)
        result = cv2.remap(image, self.map_x, self.map_y, cv2.INTER_CUBIC)
        self.moildev.revPanorama(result, self.res, alpha_max, beta)
        return self.res

    def initAlphaRho_Table(self):
        """Create list for initial alpha to rho(height image)

        :return:-
        :rtype:-
        """
        for i in range(1800):
            alpha = i / 10 * 3.1415926 / 180
            self.alphaToRho_Table.append(
                (self.parameter0 * alpha * alpha * alpha * alpha * alpha *
                 alpha + self.parameter1 * alpha * alpha * alpha * alpha *
                 alpha + self.parameter2 * alpha * alpha * alpha * alpha +
                 self.parameter3 * alpha * alpha * alpha +
                 self.parameter4 * alpha * alpha + self.parameter5 * alpha) *
                self.calibrationRatio)
            i += 1

        i = 0
        index = 0
        while i < 1800:
            while index < self.alphaToRho_Table[i]:
                self.rhoToAlpha_Table.append(i)
                index += 1
            i += 1

        while index < 3600:
            self.rhoToAlpha_Table.append(i)
            index += 1

    def getAlphaFromRho(self, rho):
        """Return the alpha from rho image

        :param rho: rho image
        :type rho: int
        :return: alpha
        :rtype: int
        """
        if rho >= 0:
            return self.rhoToAlpha_Table[rho] / 10
        else:
            return -self.rhoToAlpha_Table[-rho] / 10

    def getRhoFromAlpha(self, alpha):
        """return rho image from alpha given

        :param alpha:alpha
        :type alpha: float
        :return: rho image
        :rtype: int
        """
        return self.alphaToRho_Table[round(alpha * 10)]

    def get_alpha_beta(self, mode, delta_x, delta_y):
        """calculate the alpha beta from specific coordinate image.
        Args:
            mode = the anypoint mode.
            mode = integer.
            delta_x = the coordinate point in quadrant 1 X axis.
            delta_x = integer.
            delta_y = the coordinate point in quadrant 1 Y axis.
            delta_y = integer.

        return:
            alpha
            beta.
        """
        if mode == 0:
            r = round(math.sqrt(math.pow(delta_x, 2) + math.pow(delta_y, 2)))
            alpha = self.getAlphaFromRho(r)

            if delta_x == 0:
                angle = 0
            else:
                angle = (math.atan2(delta_y, delta_x) * 180) / self.PI

            beta = 90 - angle

        else:
            alpha = self.getAlphaFromRho(delta_y)
            beta = self.getAlphaFromRho(delta_x)

        return alpha, beta
예제 #8
0
from Moildev import Moildev
import numpy as np
import cv2

moildev = Moildev("raspicam", 1.4, 1.4, 1298.0, 966.0, 1.048, 2592, 1944, 0, 0,
                  0, 0, -47.96, 222.86, 4.05)
image_input = cv2.imread("./Image/image.jpg")
h, w = image_input.shape[:2]
sensor_width = 2592
image_width = w
m_ratio = image_width / sensor_width
mapX = np.zeros((h, w), dtype=np.float32)
mapY = np.zeros((h, w), dtype=np.float32)
alpha = 0
beta = 0
zoom = 4

moildev.AnyPointM(mapX, mapY, w, h, alpha, beta, zoom, m_ratio)
result = cv2.remap(image_input, mapX, mapY, cv2.INTER_CUBIC)
result = cv2.resize(result, (800, 600), interpolation=cv2.INTER_AREA)
cv2.imshow("Result", result)
cv2.waitKey(0)
예제 #9
0
class Controller(QtWidgets.QMainWindow):
    """The controller class to control UI MainWindow
    """
    def __init__(self, MainWindow):
        """construction method
        """
        super().__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.parent = MainWindow
        self.ui.frame_4.hide()
        self.ui.frame_5.hide()
        self.ui.frame.hide()
        self.ui.labelRecenter.hide()
        self.ui.labelImagerecenter.hide()
        self.image = None
        self.coordinate_point = None
        self.revImage = None
        self.resultImage = None
        self.cap = None
        self.dir_save = None
        self.anypointState = 1
        self.angle = 0
        self.alpha = 0
        self.beta = 0
        self.zoom = 4
        self.width_img = 1400
        self.connect_button()

        # self.imageWidth = self.moildev.get_imageWidth()
        # self.imageHeight = self.moildev.get_imageHeight()

        self.showing = ShowImageResult(self)
        self.view = ViewWindow(self)
        self.videoControl = Video_Controler(self)
        self.videoControl.videoButtonDisable()
        self.anypoint = AnyPoint(self)
        self.panorama = Panorama(self)
        self.dialogOpenCam = QtWidgets.QDialog()
        self.winOpenCam = OpenCameras(self, self.dialogOpenCam)

    def connect_button(self):
        """Connect the button and event to the function
        """
        self.ui.actionLoad_video.triggered.connect(self.open_video_file)
        self.ui.actionLoad_Image.triggered.connect(self.open_image)
        self.ui.actionOpen_Cam.triggered.connect(self.onclick_open_camera)
        self.ui.actionAbout_Us.triggered.connect(self.aboutUs)
        self.ui.windowOri.mousePressEvent = self.mouse_event
        self.ui.windowOri.mouseMoveEvent = self.mouseMovedOriImage
        self.ui.windowOri.wheelEvent = self.mouse_wheelEvent
        self.ui.windowOri.mouseReleaseEvent = self.mouse_release_event
        self.ui.PlussIcon.mouseReleaseEvent = self.mouse_release_event
        self.ui.PlussIcon.mouseDoubleClickEvent = self.mouseDoubleclic_event
        self.ui.PlussIcon.wheelEvent = self.mouse_wheelEvent
        self.ui.closeEvent = self.closeEvent
        self.ui.backtoHome.triggered.connect(self.back_to_home)
        self.ui.actionHelp.triggered.connect(self.help)
        self.ui.actionExit.triggered.connect(self.exit)

    # def init_parameter(self):
    #     """create initial parameter
    #     """
    #     self.camera = self.config.get_cameraName()
    #     self.sensor_width = self.config.get_sensorWidth()
    #     self.sensor_height = self.config.get_sensor_height()
    #     self.Icx = self.config.get_Icx()
    #     self.Icy = self.config.get_Icy()
    #     self.ratio = self.config.get_ratio()
    #     self.imageWidth = self.config.get_imageWidth()
    #     self.imageHeight = self.config.get_imageHeight()
    #     self.calibrationRatio = self.config.get_calibrationRatio()
    #     self.parameter0 = self.config.get_parameter0()
    #     self.parameter1 = self.config.get_parameter1()
    #     self.parameter2 = self.config.get_parameter2()
    #     self.parameter3 = self.config.get_parameter3()
    #     self.parameter4 = self.config.get_parameter4()
    #     self.parameter5 = self.config.get_parameter5()
    #     self.coorX = self.Icx
    #     self.coorY = self.Icy

    # def init_Map(self):
    #     """
    #     create initial mapX and mapY
    #     """
    #     self.mapX = np.zeros((self.imageHeight, self.imageWidth), dtype=np.float32)
    #     self.mapY = np.zeros((self.imageHeight, self.imageWidth), dtype=np.float32)
    #     size = self.imageHeight, self.imageWidth, 3
    #     self.m_ratio = self.ratio
    #     self.res = np.zeros(size, dtype=np.uint8)

    # def importMoildev(self):
    #     """Instantiate moildev library
    #     """
    #     self.init_parameter()
    #     self.moildev = Moildev(self.camera, self.sensor_width, self.sensor_height, self.Icx, self.Icy, self.ratio,
    #                            self.imageWidth, self.imageHeight, self.parameter0, self.parameter1, self.parameter2,
    #                            self.parameter3, self.parameter4, self.parameter5, self.calibrationRatio)

    def open_image(self):
        """Load image frame
        """
        self.filename = select_file(
            "Select Image", "../",
            "Image Files (*.jpeg *.jpg *.png *.gif *.bmg)")
        if self.filename:
            file_name = select_file("Select Parameter", "../",
                                    "Parameter Files (*.json)")
            if file_name:
                self.ui.btn_Anypoint.setChecked(False)
                self.ui.btn_Panorama.setChecked(False)
                self.image = read_image(self.filename)
                self.h, self.w = self.image.shape[:2]
                image = self.image.copy()
                self.showing.view_result(image)
                self.ratio_x, self.ratio_y, self.center = self.init_ori_ratio(
                    self.image)
                self.cam = False
                self.moildev = Moildev(file_name)
                self.anypoint.resetAlphaBeta()

    def open_video_file(self):
        """Load video file.
        """
        videoFile = select_file("Select Video Files", "../",
                                "Image Files (*.mp4 *.avi *.mpg *.gif *.mov)")
        if videoFile:
            paramName = select_file("Select Parameter", "../",
                                    "Parameter Files (*.json)")
            if paramName:
                self.anypoint.resetAlphaBeta()
                self.videoControl.videoButtonEnable()
                self.coordinate_point = None
                self.moildev = Moildev(paramName)
                self.cap = cv2.VideoCapture(videoFile)
                self.fps = self.cap.get(cv2.CAP_PROP_FPS)
                self.cam = True
                self.next_frame_slot()

    def onclick_open_camera(self):
        """showing the window to select the source camera
        """
        self.dialogOpenCam.show()

    def cameraOpen(self):
        """Open camera following the source given.
        """
        self.videoStreamURL = self.winOpenCam.video_source()
        if self.videoStreamURL is None:
            pass
        else:
            self.cap = cv2.VideoCapture(self.videoStreamURL)
            self.coordinate_point = None
            self.ret, self.image = self.cap.read()
            if self.image is None:
                QtWidgets.QMessageBox.information(self, "Information",
                                                  "No source camera founded")
            else:
                QtWidgets.QMessageBox.information(
                    self, "Information", "Select Parameter Camera !!")
                file_name = select_file("Select Left Parameter", "../",
                                        "Parameter Files (*.json)")
                if file_name:
                    self.moildev = Moildev(file_name)
                    self.videoControl.videoButtonCamera()
                    self.fps = self.cap.get(cv2.CAP_PROP_FPS)
                    self.cam = True
                    self.next_frame_slot()
                else:
                    self.cap.release()

    def next_frame_slot(self):
        """Control video frame.
        """
        self.ret, self.image = self.cap.read()
        if self.image is None:
            pass
        else:
            self.oriImage = self.image.copy()
            self.h, self.w = self.image.shape[:2]
            self.fps = self.cap.get(cv2.CAP_PROP_FPS)
            self.pos_frame = self.cap.get(cv2.CAP_PROP_POS_FRAMES)
            self.pos_msec = self.cap.get(cv2.CAP_PROP_POS_MSEC)
            self.frame_count = float(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))
            duration_sec = int(self.frame_count / self.fps)
            self.minutes = duration_sec // 60
            duration_sec %= 60
            self.seconds = duration_sec
            sec_pos = int(self.pos_frame / self.fps)
            self.minute = int(sec_pos // 60)
            sec_pos %= 60
            self.sec = sec_pos
            self.videoControl.controler()
            self.ratio_x, self.ratio_y, self.center = self.init_ori_ratio(
                self.image)
            image = self.image.copy()
            self.showing.view_result(image)
            if self.videoControl.record:
                if self.ui.btn_Anypoint.isChecked(
                ) or self.ui.btn_Panorama.isChecked():
                    self.videoControl.video_writer.write(
                        self.showing.resultImage)
                else:
                    self.videoControl.video_writer.write(self.image)

    def init_ori_ratio(self, image):
        """Calculate the initial ratio of the image.
        Args:
            ratio_x = ratio width between image and ui window.
            ratio_y = ratio height between image and ui window.
            center = find the center image on window user interface.
        return:
            ratio_x:
            ratio_y:
            center:
        """
        h = self.ui.windowOri.height()
        w = self.ui.windowOri.width()
        height, width = image.shape[:2]
        ratio_x = width / w
        ratio_y = height / h
        center = (round((w / 2) * ratio_x), round((h / 2) * ratio_y))
        return ratio_x, ratio_y, center

    def mouse_event(self, e):
        """Specify coordinate from mouse left event.
        """
        if self.image is None:
            pass
        else:
            if e.button() == QtCore.Qt.LeftButton:
                self.currPos = e.pos()
                self.pos_x = round(e.x())
                self.pos_y = round(e.y())
                delta_x = round(self.pos_x * self.ratio_x - self.w * 0.5)
                delta_y = round(-(self.pos_y * self.ratio_y - self.h * 0.5))
                self.coordinate_point = (round(self.pos_x * self.ratio_x),
                                         round(self.pos_y * self.ratio_y))
                self.coorX = round(self.pos_x * self.ratio_x)
                self.coorY = round(self.pos_y * self.ratio_y)
                if self.ui.btn_Anypoint.isChecked():
                    self.alpha, self.beta = self.moildev.get_alpha_beta(
                        delta_x, delta_y, self.anypointState)
                    self.anypoint.anypoint_view()
                elif self.ui.checkBox_ShowRecenterImage.isChecked():
                    self.alpha, self.beta = self.moildev.get_alpha_beta(
                        delta_x, delta_y, 1)
                    self.panorama.recenterImage()
                else:
                    print("coming soon")

    def mouseDoubleclic_event(self, e):
        """Reset to default by mouse event.
        """
        self.anypoint.resetAlphaBeta()
        if self.ui.btn_Anypoint.isChecked():
            self.anypoint.anypoint_view()
        elif self.ui.btn_Panorama.isChecked():
            self.panorama.resetCenter()
            self.panorama.recenterImage()
        else:
            pass

    def mouse_wheelEvent(self, e):
        """Resize image using mouse wheel event.
        """
        if self.image is None:
            pass
        else:
            modifiers = QtWidgets.QApplication.keyboardModifiers()
            if modifiers == QtCore.Qt.ControlModifier:
                wheelcounter = e.angleDelta()
                if wheelcounter.y() / 120 == -1:
                    if self.width_img == 1100:
                        pass
                    else:
                        self.width_img -= 100

                if wheelcounter.y() / 120 == 1:
                    if self.width_img == 4000:
                        pass
                    else:
                        self.width_img += 100
                self.showing.view_result(self.image)

    def mouseMovedOriImage(self, e):
        """Mouse move event to look in surrounding view in original label image
        """
        self.currPos = e.pos()
        self.pos_x = round(e.x())
        self.pos_y = round(e.y())
        delta_x = round(self.pos_x * self.ratio_x - self.w * 0.5)
        delta_y = round(-(self.pos_y * self.ratio_y - self.h * 0.5))
        print(delta_x, delta_y)
        self.coordinate_point = (round(self.pos_x * self.ratio_x),
                                 round(self.pos_y * self.ratio_y))
        self.coorX = round(self.pos_x * self.ratio_x)
        self.coorY = round(self.pos_y * self.ratio_y)
        if self.ui.btn_Anypoint.isChecked():
            self.alpha, self.beta = self.moildev.get_alpha_beta(
                delta_x, delta_y, self.anypointState)
            self.anypoint.anypoint_view()

    def mouse_release_event(self, e):
        """Mouse release event left click to show menu.
        """
        if e.button() == QtCore.Qt.LeftButton:
            pass
        else:
            if self.image is None:
                pass
            else:
                self.menuMouseEvent(e)

    def menuMouseEvent(self, e):
        """showing the menu image when release left click.
        """
        menu = QtWidgets.QMenu()
        maxi = menu.addAction("Show Maximized")
        maxi.triggered.connect(self.view.show_Maximized)
        mini = menu.addAction("Show Minimized")
        mini.triggered.connect(self.view.show_Minimized)
        save = menu.addAction("Save Image")
        info = menu.addAction("Show Info")
        save.triggered.connect(self.saveImage)
        info.triggered.connect(self.help)
        menu.exec_(e.globalPos())

    def saveImage(self):
        """Save image on local directory
        """
        ss = datetime.datetime.now().strftime("%m_%d_%H_%M_%S")
        name_image = "Original"
        image = self.image
        if self.ui.btn_Panorama.isChecked() or self.ui.btn_Anypoint.isChecked(
        ):
            name_image = "result"
            image = self.resultImage
        if self.dir_save is None or self.dir_save == "":
            self.selectDir()
        else:
            name = self.dir_save + "/" + name_image + "_" + str(ss) + ".png"
            cv2.imwrite(name, image)
            QtWidgets.QMessageBox.information(
                self, "Information",
                "Image saved !!\n\nLoc @: " + self.dir_save)

    def selectDir(self):
        """Select directory to save object such as image and video.
        """
        self.dir_save = QtWidgets.QFileDialog.getExistingDirectory(
            self, 'Select Save Folder')
        if self.dir_save:
            self.saveImage()

    def aboutUs(self):
        """showing prompt About us information (MOIL LAB)
        """
        self.dialogOpenCam.close()
        msgbox = QtWidgets.QMessageBox()
        msgbox.setWindowTitle("About Us")
        msgbox.setText(
            "MOIL \n\nOmnidirectional Imaging & Surveillance Lab\nMing Chi University of Technology\n\n"
        )
        msgbox.setIconPixmap(QtGui.QPixmap('./assets/128.png'))
        msgbox.exec()

    def help(self):
        """showing the message box to show help information obout this application
        """
        self.dialogOpenCam.close()
        msgbox = QtWidgets.QMessageBox()
        msgbox.setWindowTitle("Help !!")
        msgbox.setText(
            "Moildev-Apps\n\n"
            "Moildev-Apps is software to process fisheye "
            "image with the result panorama view and Anypoint"
            " view. \n\nThe panoramic view may present a horizontal"
            "view in a specific immersed environment to meet the"
            "common human visual perception, while the Anypoint"
            "view is an image that has been undistorted in a certain"
            "area according to the input coordinates."
            "\n\nMore reference about Moildev, contact us\n\n")
        msgbox.setIconPixmap(QtGui.QPixmap('./assets/128.png'))
        msgbox.exec()

    def back_to_home(self):
        self.parent.show()
        self.hide()

    def exit(self):
        """Exit the apps with showing the QMessageBox.
        """
        self.dialogOpenCam.close()
        self.close()

    def closeEvent(self, event):
        """Control exit application by ask yes or no question.
        """
        reply = QtWidgets.QMessageBox.question(
            self, 'Message', "Are you sure to quit?",
            QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
            QtWidgets.QMessageBox.No)

        if reply == QtWidgets.QMessageBox.Yes:
            self.exit()
            event.accept()
        else:
            event.ignore()