示例#1
0
    def get_refimage(self,R,THRESH,MIN,MAX,NPTS,save=0,out_dir='',TIME=0,loop=''):
        ''' Finds reference position in image using perspective.imagepoints()

        _Parameters_:

        R,NPTS,THRESH,MIN,MAX: parameters used by perspective.imagepoints()

        save: set to 1 if you wish to save results (images)

        out_dir: directory where to save images.

        TIME: start time of program (for file naming)

        _Returns_:

        Nothing
        '''
        img_org,circ_org,pts_img,th_org = persp.imagepoints(self.img,R,NPTS,THRESH,
                                                            MIN,MAX)
        self.ref_img=pts_img
        if save:
            h,s,__ = cv2.split(cv2.cvtColor(self.img,cv2.COLOR_BGR2HSV))
            imgs={'img_h_'+str(self.n)+'_'+TIME:h,'img_s_'+str(self.n)+'_'+TIME:s}
            persp.visualization(imgs,self.n,1)
            imgs={'img_org_'+str(self.n)+'_'+TIME:img_org,
                  'circ_org_'+str(self.n)+'_'+TIME:circ_org,
                  'img_'+str(self.n)+'_'+TIME:self.img}
            persp.visualization(imgs,self.n)
            persp.save_open_images(out_dir,loop)
            plt.close('all')
示例#2
0
    def get_refimage(self,R,THRESH,MIN,MAX,NPTS,save=0,out_dir='',TIME=0,loop=''):
        ''' Finds reference position in image using perspective.imagepoints()

        _Parameters_:

        R,NPTS,THRESH,MIN,MAX: parameters used by perspective.imagepoints()

        save: set to 1 if you wish to save results (images)

        out_dir: directory where to save images.

        TIME: start time of program (for file naming)

        _Returns_:

        Nothing
        '''
        img_org,circ_org,pts_img,th_org = persp.imagepoints(self.img,R,NPTS,THRESH,
                                                            MIN,MAX)
        self.ref_img=pts_img
        if save:
            h,s,__ = cv2.split(cv2.cvtColor(self.img,cv2.COLOR_BGR2HSV))
            imgs={'img_h_'+str(self.n)+'_'+TIME:h,'img_s_'+str(self.n)+'_'+TIME:s}
            persp.visualization(imgs,self.n,1)
            imgs={'img_org_'+str(self.n)+'_'+TIME:img_org,
                  'circ_org_'+str(self.n)+'_'+TIME:circ_org,
                  'img_'+str(self.n)+'_'+TIME:self.img}
            persp.visualization(imgs,self.n)
            persp.save_open_images(out_dir,loop)
            plt.close('all')
示例#3
0
    def get_robotimage(self,R,THRESH,MIN,MAX,save=0,out_dir='',TIME=0,loop=''):
        ''' Finds robot position in image using perspective.imagepoints().

        _Parameters_:

        R,THRESH,MIN,MAX: parameters used by perspective.imagepoints().

        save: set to 1 if you wish to save results (images)

        out_dir: directory where to save images.

        TIME: start time of program (for file naming)

        _Returns_:

        Nothing
        '''
        img_red,circ_red,p,__ = persp.imagepoints(self.img,R,1,THRESH,MIN,MAX)
        self.r_img=p
        if save:
            imgs={'img_red_'+str(self.n)+'_'+TIME:img_red,
                  'circ_red_'+str(self.n)+'_'+TIME:circ_red,
                  'img_'+str(self.n)+'_'+TIME:self.img}
            persp.visualization(imgs,self.n)
            persp.save_open_images(out_dir,loop)
            plt.close('all')
示例#4
0
    def get_robotimage(self,R,THRESH,MIN,MAX,save=0,out_dir='',TIME=0,loop=''):
        ''' Finds robot position in image using perspective.imagepoints().

        _Parameters_:

        R,THRESH,MIN,MAX: parameters used by perspective.imagepoints().

        save: set to 1 if you wish to save results (images)

        out_dir: directory where to save images.

        TIME: start time of program (for file naming)

        _Returns_:

        Nothing
        '''
        img_red,circ_red,p,__ = persp.imagepoints(self.img,R,1,THRESH,MIN,MAX)
        self.r_img=p
        if save:
            imgs={'img_red_'+str(self.n)+'_'+TIME:img_red,
                  'circ_red_'+str(self.n)+'_'+TIME:circ_red,
                  'img_'+str(self.n)+'_'+TIME:self.img}
            persp.visualization(imgs,self.n)
            persp.save_open_images(out_dir,loop)
            plt.close('all')
示例#5
0
 def get_refobject(self,input_obj,NPTS,MARGIN,save=0,out_dir='',TIME=0):
     pts_obj,M = persp.objectpoints(NPTS,input_obj)
     __,pts_obj,size = persp.format_points(pts_obj,MARGIN)
     img_flat,M = persp.geometric_transformationN(self.img,pts_obj,self.ref_img,size)
     self.ref_obj = pts_obj
     self.M = M
     if save:
         # images
         img_summary = persp.create_summary(img_flat,pts_obj)
         imgs = {'summary_'+str(self.n)+'_'+TIME:img_summary}
         persp.visualization(imgs,self.n,0,1)
         persp.save_open_images(out_dir)
         plt.close('all')
示例#6
0
 def get_refobject(self,input_obj,NPTS,MARGIN,save=0,out_dir='',TIME=0):
     pts_obj,M = persp.objectpoints(NPTS,input_obj)
     __,pts_obj,size = persp.format_points(pts_obj,MARGIN)
     img_flat,M = persp.geometric_transformationN(self.img,pts_obj,self.ref_img,size)
     self.ref_obj = pts_obj
     self.M = M
     if save:
         # images
         img_summary = persp.create_summary(img_flat,pts_obj)
         imgs = {'summary_'+str(self.n)+'_'+TIME:img_summary}
         persp.visualization(imgs,self.n,0,1)
         persp.save_open_images(out_dir)
         plt.close('all')
示例#7
0
    def get_checkerboard(self,in_dir,fisheye,w,h,MARGIN,
                         R,THRESH,MIN,MAX,save,out_dir='',TIME=0,loop=''):
        cam = Camera(self.n)
        cam.read(in_dir,fisheye)
        ipts,opts,img_out=cam.get_checkpoints_file(out_dir,w,h,fisheye,self.img)
        plt.close('all')
        if len(ipts) == 0:
            return 0

        img_org,circ_org,pts_img,__ = persp.imagepoints(self.img,R,3,THRESH,MIN,MAX)
        A = pts_img[0]
        B = pts_img[1]
        C = pts_img[2]
        a = np.array([10000,10000])
        b = np.array([10000,10000])
        c = np.array([10000,10000])
        min_a=10000
        min_b=10000
        min_c=10000
        a_ind = b_ind = c_ind = 0
        for i,pt in enumerate(ipts[0]):
            if np.linalg.norm(pt-A)<min_a:
                min_a = np.linalg.norm(pt-A)
                a=pt
                a_ind = i
            if np.linalg.norm(pt-B)<min_b:
                min_b = np.linalg.norm(pt-B)
                b=pt
                b_ind = i
            if np.linalg.norm(pt-C)<min_c:
                min_c = np.linalg.norm(pt-C)
                c=pt
                c_ind = i
        ''' reorder points from a to b and a to c '''
        ipts_new=np.zeros(ipts[0].shape,dtype=np.float32)
        j = np.zeros((ipts[0].shape[0],1))
        index = np.zeros((ipts[0].shape[0],1))
        for i in range(ipts[0].shape[0]):
            j[i] = i + 1 - np.mod(i,w)
            index[i]=a_ind+(c_ind-a_ind)/(w*(h-1))*(j[i]-1)+(b_ind-a_ind)/(w-1)*(i+1-j[i])
            ipts_new[i,:] = ipts[0][int(index[i]),:]

        ''' choose 4 corner points for homography'''
        ipts_selec = np.array([ipts_new[0],ipts_new[w-1],
                                ipts_new[w*(h-1)],ipts_new[w*h-1]])
        opts_selec = np.array([opts[0][0],opts[0][w-1],
                                 opts[0][w*(h-1)],opts[0][w*h-1]])

        pts_obj = opts_selec.copy()
        pts_obj[:,0]+=MARGIN[0]
        pts_obj[:,1]+=MARGIN[1]
        size = np.amax(pts_obj[:,:2],axis=0)+MARGIN
        size = (int(size[0]),int(size[1]))
        img_flat,M = persp.geometric_transformationN(self.img,pts_obj[:,:2],
                                                     ipts_selec,size)

        ref_obj=opts[0].copy()
        ref_obj[:,0]+=MARGIN[0]
        ref_obj[:,1]+=MARGIN[1]
        self.ref_img = ipts_new
        self.ref_obj = ref_obj
        self.M = M

        if save:
            img_summary = persp.create_summary(img_flat,pts_obj)
            imgs={'summary_'+str(self.n)+'_'+TIME:img_summary}
            persp.visualization(imgs,self.n,0,1)
            imgs={'img_org_'+str(self.n)+'_'+TIME:img_org,
                'circ_org_'+str(self.n)+'_'+TIME:circ_org,
                  'img_out_'+str(self.n)+'_'+TIME:img_out}
            persp.visualization(imgs,self.n)
            persp.save_open_images(out_dir)

        return 1
示例#8
0
    def get_checkerboard(self,in_dir,fisheye,w,h,MARGIN,
                         R,THRESH,MIN,MAX,save,out_dir='',TIME=0,loop=''):
        cam = Camera(self.n)
        cam.read(in_dir,fisheye)
        ipts,opts,img_out=cam.get_checkpoints_file(out_dir,w,h,fisheye,self.img)
        plt.close('all')
        if len(ipts) == 0:
            return 0

        img_org,circ_org,pts_img,__ = persp.imagepoints(self.img,R,3,THRESH,MIN,MAX)
        A = pts_img[0]
        B = pts_img[1]
        C = pts_img[2]
        a = np.array([10000,10000])
        b = np.array([10000,10000])
        c = np.array([10000,10000])
        min_a=10000
        min_b=10000
        min_c=10000
        a_ind = b_ind = c_ind = 0
        for i,pt in enumerate(ipts[0]):
            if np.linalg.norm(pt-A)<min_a:
                min_a = np.linalg.norm(pt-A)
                a=pt
                a_ind = i
            if np.linalg.norm(pt-B)<min_b:
                min_b = np.linalg.norm(pt-B)
                b=pt
                b_ind = i
            if np.linalg.norm(pt-C)<min_c:
                min_c = np.linalg.norm(pt-C)
                c=pt
                c_ind = i
        ''' reorder points from a to b and a to c '''
        ipts_new=np.zeros(ipts[0].shape,dtype=np.float32)
        j = np.zeros((ipts[0].shape[0],1))
        index = np.zeros((ipts[0].shape[0],1))
        for i in range(ipts[0].shape[0]):
            j[i] = i + 1 - np.mod(i,w)
            index[i]=a_ind+(c_ind-a_ind)/(w*(h-1))*(j[i]-1)+(b_ind-a_ind)/(w-1)*(i+1-j[i])
            ipts_new[i,:] = ipts[0][int(index[i]),:]

        ''' choose 4 corner points for homography'''
        ipts_selec = np.array([ipts_new[0],ipts_new[w-1],
                                ipts_new[w*(h-1)],ipts_new[w*h-1]])
        opts_selec = np.array([opts[0][0],opts[0][w-1],
                                 opts[0][w*(h-1)],opts[0][w*h-1]])

        pts_obj = opts_selec.copy()
        pts_obj[:,0]+=MARGIN[0]
        pts_obj[:,1]+=MARGIN[1]
        size = np.amax(pts_obj[:,:2],axis=0)+MARGIN
        size = (int(size[0]),int(size[1]))
        img_flat,M = persp.geometric_transformationN(self.img,pts_obj[:,:2],
                                                     ipts_selec,size)

        ref_obj=opts[0].copy()
        ref_obj[:,0]+=MARGIN[0]
        ref_obj[:,1]+=MARGIN[1]
        self.ref_img = ipts_new
        self.ref_obj = ref_obj
        self.M = M

        if save:
            img_summary = persp.create_summary(img_flat,pts_obj)
            imgs={'summary_'+str(self.n)+'_'+TIME:img_summary}
            persp.visualization(imgs,self.n,0,1)
            imgs={'img_org_'+str(self.n)+'_'+TIME:img_org,
                'circ_org_'+str(self.n)+'_'+TIME:circ_org,
                  'img_out_'+str(self.n)+'_'+TIME:img_out}
            persp.visualization(imgs,self.n)
            persp.save_open_images(out_dir)

        return 1