コード例 #1
0
ファイル: calibrator.py プロジェクト: bosforox/SeekurJr
    def cal_fromcorners(self, good):
        # Perform monocular calibrations
        lcorners = [(l, b) for (l, r, b) in good]
        rcorners = [(r, b) for (l, r, b) in good]
        self.l.cal_fromcorners(lcorners)
        self.r.cal_fromcorners(rcorners)

        lipts = self.mk_image_points(lcorners)
        ripts = self.mk_image_points(rcorners)
        boards = [ b for (_, _, b) in good]
        
        opts = self.mk_object_points(boards, True)
        npts = self.mk_point_counts(boards)

        flags = cv2.CALIB_FIX_INTRINSIC

        self.T = cv.CreateMat(3, 1, cv.CV_64FC1)
        self.R = cv.CreateMat(3, 3, cv.CV_64FC1)
        cv.SetIdentity(self.T)
        cv.SetIdentity(self.R)
        cv.StereoCalibrate(opts, lipts, ripts, npts,
                           self.l.intrinsics, self.l.distortion,
                           self.r.intrinsics, self.r.distortion,
                           self.size,
                           self.R,                            # R
                           self.T,                            # T
                           cv.CreateMat(3, 3, cv.CV_32FC1),   # E
                           cv.CreateMat(3, 3, cv.CV_32FC1),   # F
                           (cv.CV_TERMCRIT_ITER + cv.CV_TERMCRIT_EPS, 1, 1e-5),
                           flags)

        self.set_alpha(0.0)
コード例 #2
0
           flags = (cv.CV_CALIB_ZERO_TANGENT_DIST)) #cv.CV_CALIB_ZERO_TANGENT_DIST) # 0) 

cv.CalibrateCamera2(opts, ipts2, npts,
           cv.GetSize(images2[0]),
           intrinsics2,
           distortion2,
           exR2,
           exT2,
           flags = cv.CV_CALIB_ZERO_TANGENT_DIST) #cv.CV_CALIB_ZERO_TANGENT_DIST) # 0) 

#term_crit =(cv.CV_TERMCRIT_ITER | cv.CV_TERMCRIT_EPS,  50, 0.00000001) 
term_crit = (cv.CV_TERMCRIT_ITER+cv.CV_TERMCRIT_EPS, 50, 1e-6)

cv.StereoCalibrate(opts, ipts1, ipts2, npts, 
                   intrinsics1, distortion1, intrinsics2, distortion2, 
                   cv.GetSize(images1[0]), R, T, E, F, 
                   term_crit, 
                   cv.CV_CALIB_FIX_INTRINSIC)


#print "E =",list(cvmat_iterator(E))
#print "F =",list(cvmat_iterator(F))
print "D1 =", list(cvmat_iterator(distortion1))
print "K1 =", list(cvmat_iterator(intrinsics1))

print "D2 =", list(cvmat_iterator(distortion2))
print "K2 =", list(cvmat_iterator(intrinsics2))

print "R =", list(cvmat_iterator(R))
print "T =", list(cvmat_iterator(T))
コード例 #3
0
ファイル: calibrator.py プロジェクト: muyimolin/calibration
    def do_calibration(self):
        if not self.goodenough:
            print "Can not calibrate yet!"
            return
        #append all things in db
        good_l_corners = [
            lcorners for (lparams, rparams, lcorners, rcorners, lobject_points,
                          robject_points) in self.db
        ]
        good_l_points = [
            lobject_points for (lparams, rparams, lcorners, rcorners,
                                lobject_points, robject_points) in self.db
        ]
        good_r_corners = [
            rcorners for (lparams, rparams, lcorners, rcorners, lobject_points,
                          robject_points) in self.db
        ]
        good_r_points = [
            robject_points for (lparams, rparams, lcorners, rcorners,
                                lobject_points, robject_points) in self.db
        ]

        # Perform monocular calibrations
        self.l.do_calibration()
        self.r.do_calibration()

        ##        print "left intrinsics"
        ##        print numpy.asarray(self.l.intrinsics)
        ##        print "left distortion"
        ##        print numpy.asarray(self.l.distortion)
        ##        print "left projection"
        ##        print numpy.asarray(self.l.P)
        ##
        ##        print "right intrinsics"
        ##        print numpy.asarray(self.r.intrinsics)
        ##        print "right distortion"
        ##        print numpy.asarray(self.r.distortion)
        ##        print "right projection"
        ##        print numpy.asarray(self.r.P)

        flags = cv2.CALIB_FIX_INTRINSIC

        self.T = cv.CreateMat(3, 1, cv.CV_64FC1)
        self.R = cv.CreateMat(3, 3, cv.CV_64FC1)
        cv.SetIdentity(self.T)
        cv.SetIdentity(self.R)

        opts = self.mk_object_points(good_l_points)
        l_ipts = self.mk_image_points(good_l_corners)
        r_ipts = self.mk_image_points(good_r_corners)
        npts = self.mk_point_counts(good_l_points)

        cv.StereoCalibrate(
            opts,
            l_ipts,
            r_ipts,
            npts,
            self.l.intrinsics,
            self.l.distortion,
            self.r.intrinsics,
            self.r.distortion,
            self.size,
            self.R,  # R
            self.T,  # T
            cv.CreateMat(3, 3, cv.CV_32FC1),  # E
            cv.CreateMat(3, 3, cv.CV_32FC1),  # F
            (cv.CV_TERMCRIT_ITER + cv.CV_TERMCRIT_EPS, 1, 1e-5),
            flags)

        ##        print "after cal left intrinsics"
        ##        print numpy.asarray(self.l.intrinsics)
        ##        print "after cal left distortion"
        ##        print numpy.asarray(self.l.distortion)
        ##
        ##        print "after cal right intrinsics"
        ##        print numpy.asarray(self.r.intrinsics)
        ##        print "after cal right distortion"
        ##        print numpy.asarray(self.r.distortion)
        ##
        ##        print "after cal R"
        ##        print numpy.asarray(self.R)
        ##        print "after cal T"
        ##        print numpy.asarray(self.T)

        cv.StereoRectify(self.l.intrinsics,
                         self.r.intrinsics,
                         self.l.distortion,
                         self.r.distortion,
                         self.size,
                         self.R,
                         self.T,
                         self.l.R,
                         self.r.R,
                         self.l.P,
                         self.r.P,
                         alpha=self.alpha)

        ##        print "after rectify left intrinsics"
        ##        print numpy.asarray(self.l.intrinsics)
        ##        print "after rectify left distortion"
        ##        print numpy.asarray(self.l.distortion)
        ##
        ##        print "after rectify right intrinsics"
        ##        print numpy.asarray(self.r.intrinsics)
        ##        print "after rectify right distortion"
        ##        print numpy.asarray(self.r.distortion)
        ##
        ##        print "after rectify left R"
        ##        print numpy.asarray(self.l.R)
        ##        print "after rectify left P"
        ##        print numpy.asarray(self.l.P)
        ##        print "after rectify right R"
        ##        print numpy.asarray(self.r.R)
        ##        print "after rectify right P"
        ##        print numpy.asarray(self.r.P)

        return (self.l.distortion, self.l.intrinsics, self.l.R, self.l.P,
                self.r.distortion, self.r.intrinsics, self.r.R, self.r.P)