예제 #1
0
파일: Area.py 프로젝트: sgfernandes/PyTrx
    def calcManualAreas(self):
        '''Manually define areas of interest in a sequence of images. User 
        input is facilitated through an interactive plot to click around the 
        area of interest
        
        Returns
        area (list):                XYZ and UV area information
        '''                
        '\n\nCOMMENCING MANUAL AREA DETECTION'
            
        #Set up output dataset
        area=[]

        #Get DEM from camera environment
        dem = self._camEnv.getDEM() 

        #Get inverse projection variables through camera info               
        invprojvars = setProjection(dem, self._camEnv._camloc, 
                                    self._camEnv._camDirection, 
                                    self._camEnv._radCorr, 
                                    self._camEnv._tanCorr, 
                                    self._camEnv._focLen, 
                                    self._camEnv._camCen, 
                                    self._camEnv._refImage)
                
        #Cycle through images        
        for i in (range(self.getLength())):
            
            #Call corrected/uncorrected image
            if self._calibFlag is True:
                img=self._imageSet[i].getImageCorr(self._camEnv.getCamMatrixCV2(), 
                                                   self._camEnv.getDistortCoeffsCV2())      
            else:
                img=self._imageSet[i].getImageArray()          

            #Get image name
            imn=self._imageSet[i].getImageName()
            
            #Manually define extent and append
            if self._hmatrix is not None:
                polys = calcManualArea(img, imn, self._hmatrix[i], 
                                       self._pxplot, invprojvars) 
            else:
                polys = calcManualArea(img, imn, None, self._pxplot, 
                                       invprojvars)                 
            area.append(polys)
            
            #Clear memory
            self._imageSet[i].clearImage()
            self._imageSet[i].clearImageArray()
    
        #Return all extents, all cropped images and corresponding image names       
        return area
예제 #2
0
파일: Line.py 프로젝트: shahinmg/PyTrx
    def calcManualLines(self):
        """Method to manually define pixel lines from an image sequence. The 
        lines are manually defined by the user on an image plot. Returns the 
        line pixel coordinates and pixel length.
        
        :returns: XYZ and UV line lengths and coordinates
        :rtype: list
        """
        print('\n\nCOMMENCING LINE DETECTION')

        #Set up output dataset
        lines = []

        #Get DEM from camera environment
        dem = self._camEnv.getDEM()

        #Get inverse projection variables through camera info
        invprojvars = setProjection(dem, self._camEnv._camloc,
                                    self._camEnv._camDirection,
                                    self._camEnv._radCorr,
                                    self._camEnv._tanCorr,
                                    self._camEnv._focLen, self._camEnv._camCen,
                                    self._camEnv._refImage)

        #Cycle through image pairs (numbered from 0)
        for i in range(self.getLength()):

            #Get corrected/distorted image
            if self._calibFlag is True:
                cameraMatrix = self._camEnv.getCamMatrixCV2()
                distortP = self._camEnv.getDistortCoeffsCV2()
                img1 = self._imageSet[i].getImageCorr(cameraMatrix, distortP)
            else:
                img1 = self._imageSet[i].getImageArray()

            #Get image name
            imn = self._imageSet[i].getImageName()

            #Define line data
            if self._hmatrix is not None:
                out = calcManualLine(img1, imn, self._hmatrix[i], invprojvars)
            else:
                out = calcManualLine(img1, imn, None, invprojvars)

            #Append to list
            lines.append(out)

        #Return pixel point coordinates and lines
        return lines
예제 #3
0
파일: Area.py 프로젝트: sgfernandes/PyTrx
    def calcAutoAreas(self, colour=False, verify=False):
        '''Detects areas of interest from a sequence of images, and returns 
        pixel and xyz areas. 
        
        Args
        colour (boolean):           Flag to denote whether colour range for 
                                    detection should be defined for each image
                                    or only once.
        verify (boolean):           Flag to denote whether detected polygons
                                    should be manually verified by user.
    
        Returns
        area (list):                XYZ and UV area information
        '''               
        print('\n\nCOMMENCING AUTOMATED AREA DETECTION')

        #Get DEM from camera environment
        dem = self._camEnv.getDEM() 

        #Get inverse projection variables through camera info               
        invprojvars = setProjection(dem, self._camEnv._camloc, 
                                    self._camEnv._camDirection, 
                                    self._camEnv._radCorr, 
                                    self._camEnv._tanCorr, 
                                    self._camEnv._focLen, 
                                    self._camEnv._camCen, 
                                    self._camEnv._refImage)
            
        #If user is only defining the color range once
        if colour is False: 
            
            #Define colour range if none is given
            if self._colourrange is None:

                #Get image (either corrected or distorted)
                if self._calibFlag is True:
                    cameraMatrix=self._camEnv.getCamMatrixCV2()
                    distortP=self._camEnv.getDistortCoeffsCV2()
                    setting=self._imageSet[self._maximg].getImageCorr(cameraMatrix, 
                                                               distortP)
                else:
                    setting = self._imageSet[self._maximg].getImageArray() 
    
                #Get image name
                setimn=self._imageSet[self._maximg].getImageName()
                  
                #Get mask and mask image if present
                if self._mask is not None:                       
                    booleanMask = np.array(self._mask, dtype=bool)
                    booleanMask = np.invert(booleanMask)
                    
                    #Mask extent image with boolean array
                    np.where(booleanMask, 0, setting) #Fit arrays to each other
                    setting[booleanMask] = 0 #Mask image with boolean mask object       
                       
                #Enhance image if enhancement parameters given
                if self._enhance is not None:
                    setting = enhanceImage(setting, self._enhance[0], 
                                           self._enhance[1], self._enhance[2])
                
                #Define colour range
                defineColourrange(setting, setimn, pxplot=self._pxplot)    
            
        #Set up output datasets
        area=[]
                       
        #Cycle through image sequence (numbered from 0)
        for i in range(self.getLength()):
            
            #Get corrected/distorted image
            if self._calibFlag is True:
                cameraMatrix=self._camEnv.getCamMatrixCV2()
                distortP=self._camEnv.getDistortCoeffsCV2()
                img1 = self._imageSet[i].getImageCorr(cameraMatrix, 
                                                      distortP)
            else:
                img1=self._imageSet[i].getImageArray()

            #Get image name
            imn=self._imageSet[i].getImageName()
               
            #Make a copy of the image array
            img2 = np.copy(img1)
            
            #Mask image if mask is present
            if self._mask is not None:
                booleanMask = np.array(self._mask, dtype=bool)
                booleanMask = np.invert(booleanMask)
                
                #Mask extent image with boolean array
                np.where(booleanMask, 0, img2) #Fit arrays to each other
                img2[booleanMask] = 0 #Mask image with boolean mask object
            
            #Enhance image if enhancement parameters are present
            if self._enhance is not None:
                img2 = enhanceImage(img2, self._enhance[0], self._enhance[1],
                                    self._enhance[2])
            
            #Define colour range if required
            if colour is True:
                defineColourrange(img2, imn, pxplot=self._pxplot)
            
            #Calculate extent
            if self._hmatrix is not None:
                out = calcAutoArea(img2, imn, self._colourrange, 
                                   self._hmatrix[i], self._threshold, 
                                   invprojvars)  
            else:
                out = calcAutoArea(img2, imn, self._colourrange, None, 
                                   self._threshold, invprojvars)  
            
            area.append(out)

            #Clear memory
            self._imageSet[i].clearImage()
            self._imageSet[i].clearImageArray()
        
        #Verify areas if flag is true
        if verify is True:
            area = self.verifyAreas(area, invprojvars)

        #Return all xy coordinates and pixel extents                 
        return area
예제 #4
0
tu1_xy=[] 
for a,b in zip(loc_x,loc_y):
    tu1_xy.append([a,b])
print '\n\n' + str(len(tu1_xy)) + ' locations for calving events detected'
tu1_xy=np.array(tu1_xy)


#Define camera environment
tu1cam = CamEnv(tu1camenv)

#Get DEM from camera environment
dem = tu1cam.getDEM() 

#Get inverse projection variables through camera info               
invprojvars = setProjection(dem, tu1cam._camloc, tu1cam._camDirection, 
                            tu1cam._radCorr, tu1cam._tanCorr, tu1cam._focLen, 
                            tu1cam._camCen, tu1cam._refImage)
        
#Show GCPs                           
tu1cam.showGCPs()                        

#Inverse project image coordinates using function from CamEnv object                       
tu1_xyz = projectUV(tu1_xy, invprojvars)
print '\n\n' + str(len(tu1_xyz)) + ' locations for calving events georectified'


#-----------------------   Plot xyz location on DEM   -------------------------

print '\n\nPLOTTING XYZ CALVING LOCATIONS'

예제 #5
0
print '\nLOADING GCPs'
GCPxyz, GCPuv = FileHandler.readGCPs(GCPpath)

print '\nCALIBRATING CAMERA'
calibimgs = sorted(glob.glob(calibPath))  #Get imagefiles
calib, err = calibrateImages(calibimgs, chessboard,
                             cv2.CALIB_FIX_PRINCIPAL_POINT)

print '\nDEFINING CAMERA PROJECTION'
matrix = np.transpose(calib[0])  #Get matrix
tancorr = calib[1]  #Get tangential
radcorr = calib[2]  #Get radial
focal = [matrix[0, 0], matrix[1, 1]]  #Focal length
camcen = [matrix[0, 2], matrix[1, 2]]  #Principal point

invprojvars = setProjection(dem, camloc, campose, radcorr, tancorr, focal,
                            camcen, refimagePath)

#--------------------   Plot camera environment info   ------------------------

print '\nPLOTTING CAMERA ENVIRONMENT INFO'

#Load reference image
refimg = FileHandler.readImg(refimagePath)
imn = Path(refimagePath).name

#Show GCPs
Utilities.plotGCPs([GCPxyz, GCPuv], refimg, imn, dem, camloc, extent=None)

#Show Prinicpal Point in image
Utilities.plotPrincipalPoint(camcen, refimg, imn)
예제 #6
0
                              GCPuv,
                              optmethod=optmethod,
                              show=True)

print('\nCOMPILING TRANSFORMATION PARAMETERS')
camloc1, campose1, radcorr1, tancorr1, focal1, camcen1, refimagePath = new_projvars

matrix1 = np.array([focal1[0], 0, camcen[0], 0, focal1[1], camcen[1], 0, 0,
                    1]).reshape(3, 3)

distort = np.hstack([
    radcorr1[0][0], radcorr1[0][1], tancorr1[0][0], tancorr1[0][1],
    radcorr1[0][2]
])

new_invprojvars = setProjection(dem, camloc1, campose1, radcorr1, tancorr1,
                                focal1, camcen1, refimagePath)

campars = [dem, new_projvars, new_invprojvars]

residuals = computeResidualsXYZ(new_invprojvars, GCPxyz, GCPuv, dem)

print('\nLOADING MASKS')
print('Defining velocity mask')
vmask1 = FileHandler.readMask(None, vmaskPath_s)
vmask2 = Velocity.readDEMmask(dem, im1, new_invprojvars, vmaskPath_d)

print('Defining homography mask')
hmask = FileHandler.readMask(None, hmaskPath)

#--------------------   Plot camera environment info   ------------------------