def drawSingleImage(self, modelPoints, scale, ax, rays='no', ): """ draws the rays to the modelpoints from the perspective center of the two images :param modelPoints: points in the model system [ model units] :param scale: scale of image frame :param ax: axes of the plot :param rays: rays from perspective center to model points :type modelPoints: np.array nx3 :type scale: float :type ax: plot axes :type rays: 'yes' or 'no' :return: none """ pixel_size = 0.0000024 # [m] # images coordinate systems pv.drawOrientation(self.RotationMatrix, self.PerspectiveCenter, 1, ax) # images frames pv.drawImageFrame(self.camera.sensorSize / 1000 * scale, self.camera.sensorSize / 1000 * scale, self.RotationMatrix, self.PerspectiveCenter, self.camera.focalLength / 1000, 1, ax) if rays == 'yes': # draw rays from perspective center to model points pv.drawRays(modelPoints, self.PerspectiveCenter, ax)
def LoadProfilePoints(self, fname): if fname == None or fname == '': fname = os.path.join(self.profilerootpath, self.DirSub(index), self.profile.profilename + ".txt") if os.path.exists(fname): self.profilepoints = [] with open(fname) as f: for line in f: words = line.split() roi_0 = int(words[1][:-1]) roi_1 = int(words[2][:-1]) roi_2 = int(words[3][:-1]) roi_3 = int(words[4]) self.profilepoints.append( PhotoViewer.ProfilePoint(roi_0, roi_2, roi_1, roi_3)) #x = roi_0 + int((roi_1 - roi_0 + 1)/2) #y = roi_2 + int((roi_3 - roi_2 + 1)/2) #centerpoint.append((x,y)) return True return False
def drawImagePair(self, modelPoints, ax): """ draws the rays to the modelpoints from the perspective center of the two images :param modelPoints: points in the model system [ model units] :param ax: axes of the plot :type modelPoints: np.array nx3 :type ax: plot axes :return: none """ pixel_size = 0.0000024 # [m] # images coordinate systems pv.drawOrientation(self.RotationMatrix_Image1, self.PerspectiveCenter_Image1, 1, ax) pv.drawOrientation(self.RotationMatrix_Image2, self.PerspectiveCenter_Image2, 1, ax) # images frames pv.drawImageFrame((self.__image1.camera.principalPoint[0] * 2), self.__image1.camera.principalPoint[1] * 2, self.RotationMatrix_Image1, self.PerspectiveCenter_Image1, self.__image1.camera.focalLength, 0.1, ax) pv.drawImageFrame(self.__image2.camera.principalPoint[0] * 2, self.__image2.camera.principalPoint[1] * 2, self.RotationMatrix_Image2, self.PerspectiveCenter_Image2, self.__image2.camera.focalLength, 0.1, ax) # draw rays from perspective centers to model points pv.drawRays(modelPoints, self.PerspectiveCenter_Image1, ax) pv.drawRays(modelPoints, self.PerspectiveCenter_Image2, ax)
def drawImagePair(self, ImagePair, modelPoints, fig2, ax2): """ Drawing 3D output of given imgPair :param ImagePair: ImagePair object :param modelPoints: Points In Model :type ImagePair: np.array nx2 :type modelPoints: np.array nx2 :return: fig,axis """ fig = fig2 # ax = fig.add_subplot(111, projection='3d') ax = ax2 pix_size = 2.4e-3 photo.drawOrientation(self.RotationMatrix_Image1,\ np.reshape(self.PerspectiveCenter_Image1,\ (self.PerspectiveCenter_Image1.size, 1)),\ 3,ax) photo.drawOrientation(self.RotationMatrix_Image2,\ np.reshape(self.PerspectiveCenter_Image2,\ (self.PerspectiveCenter_Image2.size, 1)),\ 3, ax) photo.drawImageFrame(5472 * pix_size, 3648 * pix_size, self.RotationMatrix_Image1,\ np.reshape(self.PerspectiveCenter_Image1,\ (self.PerspectiveCenter_Image1.size, 1)),\ 4248.06 * pix_size, 0.8, ax) photo.drawImageFrame(5472 * pix_size, 3648 * pix_size, self.RotationMatrix_Image2,\ np.reshape(self.PerspectiveCenter_Image2,\ (self.PerspectiveCenter_Image2.size, 1)),\ 4248.06 * pix_size, 0.8, ax) photo.drawRays(modelPoints*100,\ np.reshape(self.PerspectiveCenter_Image1,\ (self.PerspectiveCenter_Image1.size, 1)), ax) photo.drawRays(modelPoints*100,\ np.reshape(self.PerspectiveCenter_Image2,\ (self.PerspectiveCenter_Image2.size, 1)), ax) modelPoints = modelPoints*100 for i in range(0, modelPoints.shape[0]-2, 1): ax.plot([modelPoints[i, 0], modelPoints[i + 1, 0]], \ [modelPoints[i, 1], modelPoints[i + 1, 1]], \ [modelPoints[i, 2], modelPoints[i + 1, 2]], color='blue') # Delete in case of diffrent object than this lab ax.plot([modelPoints[0, 0], modelPoints[8, 0]], \ [modelPoints[0, 1], modelPoints[8, 1]], \ [modelPoints[0, 2], modelPoints[8, 2]], color='blue') ax.plot([modelPoints[3, 0], modelPoints[6, 0]], \ [modelPoints[3, 1], modelPoints[6, 1]], \ [modelPoints[3, 2], modelPoints[6, 2]], color='blue') ax.plot([modelPoints[2, 0], modelPoints[7, 0]], \ [modelPoints[2, 1], modelPoints[7, 1]], \ [modelPoints[2, 2], modelPoints[7, 2]], color='blue') ax.view_init(20, 80) return fig, ax
# pv.DrawCube(obj.CreateCube(10),ax) import Camera # ======= from Camera import Camera from SingleImage import SingleImage # B fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # create synthetic data cube = obj.CreateCube(6) pv.DrawCube(cube, ax) # define camera focal_length = 35 sensor_size = 25 camera1 = Camera(focal_length, np.array([0, 0]), None, None, None, sensor_size) # define image omega = 0 phi = 0 kappa = 0 Z = 50 img1 = SingleImage(camera1) img1.exteriorOrientationParameters = np.array([[0, 0, Z, omega, phi, kappa]])
def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(1920, 1080) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget) self.horizontalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 1921, 51)) self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget") self.horizontalLayout = QtWidgets.QHBoxLayout( self.horizontalLayoutWidget) self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout.setObjectName("horizontalLayout") self.clear_button = QtWidgets.QPushButton(self.horizontalLayoutWidget) self.clear_button.setObjectName("clear_button") self.horizontalLayout.addWidget(self.clear_button) self.mask_button = QtWidgets.QPushButton(self.horizontalLayoutWidget) self.mask_button.setObjectName("mask_button") self.horizontalLayout.addWidget(self.mask_button) self.reload_button = QtWidgets.QPushButton(self.horizontalLayoutWidget) self.reload_button.setObjectName("reload_button") self.horizontalLayout.addWidget(self.reload_button) self.clear_button.setDisabled(True) self.mask_button.setDisabled(True) self.reload_button.setDisabled(True) self.drop_label = QtWidgets.QLabel(self.horizontalLayoutWidget) self.drop_label.setObjectName("drop_label") self.horizontalLayout.addWidget(self.drop_label) self.dropout_combo = QtWidgets.QComboBox(self.horizontalLayoutWidget) self.dropout_combo.setObjectName("dropout_combo") self.horizontalLayout.addWidget(self.dropout_combo) self.crop_label = QtWidgets.QLabel(self.horizontalLayoutWidget) self.crop_label.setObjectName("crop_label") self.horizontalLayout.addWidget(self.crop_label) self.crop_combo = QtWidgets.QComboBox(self.horizontalLayoutWidget) self.crop_combo.setObjectName("crop_combo") self.horizontalLayout.addWidget(self.crop_combo) self.iter_label = QtWidgets.QLabel(self.horizontalLayoutWidget) self.iter_label.setObjectName("iter_label") self.horizontalLayout.addWidget(self.iter_label) self.iter_combo = QtWidgets.QComboBox(self.horizontalLayoutWidget) self.iter_combo.setObjectName("iter_combo") self.horizontalLayout.addWidget(self.iter_combo) self.main_label = QtWidgets.QLabel(self.horizontalLayoutWidget) self.main_label.setObjectName("main_label") self.horizontalLayout.addWidget(self.main_label) self.label = QtWidgets.QLabel(self.horizontalLayoutWidget) self.label.setObjectName("label") self.horizontalLayout.addWidget(self.label) self.legend_viewer = PhotoViewer.PhotoViewer(self.centralwidget) self.legend_viewer.setObjectName("legend_viewer") self.horizontalLayout.addWidget(self.legend_viewer) self.label_2 = QtWidgets.QLabel(self.horizontalLayoutWidget) self.label_2.setObjectName("label_2") self.horizontalLayout.addWidget(self.label_2) spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.viewer = PhotoViewer.PhotoViewer(self.centralwidget) self.viewer.setGeometry(QtCore.QRect(0, 50, 1941, 981)) self.viewer.setObjectName("viewer") MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 1920, 22)) self.menubar.setObjectName("menubar") self.menuFile = QtWidgets.QMenu(self.menubar) self.menuFile.setObjectName("menuFile") MainWindow.setMenuBar(self.menubar) self.actionOpen = QtWidgets.QAction(MainWindow) self.actionOpen.setObjectName("actionOpen") # self.actionSavePNG = QtWidgets.QAction(MainWindow) # self.actionSavePNG.setObjectName("actionSavePNG") self.actionQuit = QtWidgets.QAction(MainWindow) self.actionQuit.setObjectName("actionQuit") self.menuFile.addAction(self.actionOpen) self.menuFile.addSeparator() self.menuFile.addAction(self.actionQuit) self.menubar.addAction(self.menuFile.menuAction()) # self.menuFile.addAction(self.actionSavePNG) # self.menuFile.addSeparator() self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
print('camera Points=', '\n', camera_points) # draw fig = plt.figure() ax = fig.add_subplot(111, projection='3d') scale = 100 img1.drawSingleImage(calibration_field, scale, ax, 'yes') ax.scatter(calibration_field[:, 0], calibration_field[:, 1], calibration_field[:, 2], c='g', s=50, marker='*') plt.figure() pv.drawImageFrame2D(img1.camera.sensorSize, img1.camera.sensorSize) plt.scatter(camera_points[:, 0], camera_points[:, 1]) # Part B # calibration # Approximate values f = 35 # [mm] xp2 = 0 # in camera space [mm] yp2 = 0 # in camera space [mm] k1 = 0. k2 = 0. X0 = 0 Y0 = 0 Z0 = 0 omega2 = np.radians(90) phi2 = 0
def drawImagePair(self, modelPoints, ax): """ Drawing the model images plane, perspective centers and ray intersection :param modelPoints: the points that were computed in the model system :type modelPoints: np.array nx3 :return: None (plotting) """ pv.drawOrientation( self.RotationMatrix_Image1, np.reshape(self.PerspectiveCenter_Image1, (self.PerspectiveCenter_Image1.size, 1)), 100, ax) pv.drawOrientation( self.RotationMatrix_Image2, np.reshape(self.PerspectiveCenter_Image2, (self.PerspectiveCenter_Image2.size, 1)), 100, ax) pv.drawImageFrame( 5472 * 2.4e-3, 3648 * 2.4e-3, self.RotationMatrix_Image1, np.reshape(self.PerspectiveCenter_Image1, (self.PerspectiveCenter_Image1.size, 1)), 4248.06 * 2.4e-3, 100, ax) pv.drawImageFrame( 5472 * 2.4e-3, 3648 * 2.4e-3, self.RotationMatrix_Image2, np.reshape(self.PerspectiveCenter_Image2, (self.PerspectiveCenter_Image2.size, 1)), 4248.06 * 2.4e-3, 100, ax) pv.drawRays( modelPoints * 1000, np.reshape(self.PerspectiveCenter_Image1, (self.PerspectiveCenter_Image1.size, 1)), ax, 'gray') pv.drawRays( modelPoints * 1000, np.reshape(self.PerspectiveCenter_Image2, (self.PerspectiveCenter_Image2.size, 1)), ax, 'gray')
def drawImageTriple(self, modelPoints, ax): """ Drawing the model images plane, perspective centers and ray intersection :param modelPoints: the points that were computed in the model system :param ax: the ax :type modelPoints: np.array nx3 :return: None (plotting) """ pv.drawOrientation(self.__R1, np.reshape(self.__o1 * 1000, (self.__o1.size, 1)), 500, ax) pv.drawOrientation(self.__R2, np.reshape(self.__o2 * 1000, (self.__o2.size, 1)), 500, ax) pv.drawOrientation(self.__R3, np.reshape(self.__o3 * 1000, (self.__o3.size, 1)), 500, ax) pv.drawImageFrame(5472 * 2.4e-3, 3648 * 2.4e-3, self.__R1, np.reshape(self.__o1 * 1000, (self.__o1.size, 1)), 4248.06 * 2.4e-3, 100, ax) pv.drawImageFrame(5472 * 2.4e-3, 3648 * 2.4e-3, self.__R2, np.reshape(self.__o2 * 1000, (self.__o2.size, 1)), 4248.06 * 2.4e-3, 100, ax) pv.drawImageFrame(5472 * 2.4e-3, 3648 * 2.4e-3, self.__R3, np.reshape(self.__o3 * 1000, (self.__o3.size, 1)), 4248.06 * 2.4e-3, 100, ax) pv.drawRays(modelPoints * 1000, np.reshape(self.__o1 * 1000, (self.__o1.size, 1)), ax, 'gray') pv.drawRays(modelPoints * 1000, np.reshape(self.__o2 * 1000, (self.__o2.size, 1)), ax, 'gray') pv.drawRays(modelPoints * 1000, np.reshape(self.__o3 * 1000, (self.__o3.size, 1)), ax, 'gray')