idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
27,300 | public void init ( ) { N = getParameterLength ( ) ; jacR = new DMatrixRMaj [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { jacR [ i ] = new DMatrixRMaj ( 3 , 3 ) ; } jacobian = new DMatrixRMaj ( N , 9 ) ; paramInternal = new double [ N ] ; numericalJac = createNumericalAlgorithm ( function ) ; } | Initializes data structures . Separate function to make it easier to extend the class |
27,301 | public void checkOneObservationPerView ( ) { for ( int viewIdx = 0 ; viewIdx < views . length ; viewIdx ++ ) { SceneObservations . View v = views [ viewIdx ] ; for ( int obsIdx = 0 ; obsIdx < v . size ( ) ; obsIdx ++ ) { int a = v . point . get ( obsIdx ) ; for ( int i = obsIdx + 1 ; i < v . size ( ) ; i ++ ) { if ( a == v . point . get ( i ) ) { new RuntimeException ( "Same point is viewed more than once in the same view" ) ; } } } } } | Makes sure that each feature is only observed in each view |
27,302 | public static void profile ( Performer performer , int num ) { long deltaTime = measureTime ( performer , num ) ; System . out . printf ( "%30s time = %8d ms per frame = %8.3f\n" , performer . getName ( ) , deltaTime , ( deltaTime / ( double ) num ) ) ; } | See how long it takes to run the process num times and print the results to standard out |
27,303 | protected void initialize ( T input , GrayS32 output ) { this . graph = output ; final int N = input . width * input . height ; regionSize . resize ( N ) ; threshold . resize ( N ) ; for ( int i = 0 ; i < N ; i ++ ) { regionSize . data [ i ] = 1 ; threshold . data [ i ] = K ; graph . data [ i ] = i ; } edges . reset ( ) ; edgesNotMatched . reset ( ) ; } | Predeclares all memory required and sets data structures to their initial values |
27,304 | protected void mergeSmallRegions ( ) { for ( int i = 0 ; i < edgesNotMatched . size ( ) ; i ++ ) { Edge e = edgesNotMatched . get ( i ) ; int rootA = find ( e . indexA ) ; int rootB = find ( e . indexB ) ; if ( rootA == rootB ) continue ; int sizeA = regionSize . get ( rootA ) ; int sizeB = regionSize . get ( rootB ) ; if ( sizeA < minimumSize || sizeB < minimumSize ) { graph . data [ e . indexB ] = rootA ; graph . data [ rootB ] = rootA ; regionSize . data [ rootA ] = sizeA + sizeB ; } } } | Look at the remaining regions and if there are any small ones marge them into a larger region |
27,305 | protected int find ( int child ) { int root = graph . data [ child ] ; if ( root == graph . data [ root ] ) return root ; int inputChild = child ; while ( root != child ) { child = root ; root = graph . data [ child ] ; } graph . data [ inputChild ] = root ; return root ; } | Finds the root given child . If the child does not point directly to the parent find the parent and make the child point directly towards it . |
27,306 | protected void computeOutput ( ) { outputRegionId . reset ( ) ; outputRegionSizes . reset ( ) ; for ( int y = 0 ; y < graph . height ; y ++ ) { int indexGraph = graph . startIndex + y * graph . stride ; for ( int x = 0 ; x < graph . width ; x ++ , indexGraph ++ ) { int parent = graph . data [ indexGraph ] ; if ( parent == indexGraph ) { outputRegionId . add ( indexGraph ) ; outputRegionSizes . add ( regionSize . get ( indexGraph ) ) ; } else { int child = indexGraph ; while ( parent != child ) { child = parent ; parent = graph . data [ child ] ; } graph . data [ indexGraph ] = parent ; } } } } | Searches for root nodes in the graph and adds their size to the list of region sizes . Makes sure all other nodes in the graph point directly at their root . |
27,307 | public void apply ( DMatrixRMaj H , DMatrixRMaj output ) { output . reshape ( 3 , H . numCols ) ; int stride = H . numCols ; for ( int col = 0 ; col < H . numCols ; col ++ ) { double h1 = H . data [ col ] , h2 = H . data [ col + stride ] , h3 = H . data [ col + 2 * stride ] ; output . data [ col ] = h1 / stdX - meanX * h3 / stdX ; output . data [ col + stride ] = h2 / stdY - meanY * h3 / stdY ; output . data [ col + 2 * stride ] = h3 ; } } | Applies normalization to a H = 3xN matrix |
27,308 | public void apply ( DMatrix3x3 C , DMatrix3x3 output ) { DMatrix3x3 Hinv = matrixInv3 ( work ) ; PerspectiveOps . multTranA ( Hinv , C , Hinv , output ) ; } | Apply transform to conic in 3x3 matrix format . |
27,309 | private static WlCoef_I32 generateInv_I32 ( ) { WlCoef_I32 ret = new WlCoef_I32 ( ) ; ret . scaling = new int [ ] { 1 , 1 } ; ret . wavelet = new int [ ] { ret . scaling [ 0 ] , - ret . scaling [ 0 ] } ; ret . denominatorScaling = 2 ; ret . denominatorWavelet = 2 ; return ret ; } | Create a description for the inverse transform . Note that this will NOT produce an exact copy of the original due to rounding error . |
27,310 | public void updateTracks ( I input , PyramidDiscrete < I > pyramid , D [ ] derivX , D [ ] derivY ) { tracksSpawned . clear ( ) ; this . input = input ; trackerKlt . setInputs ( pyramid , derivX , derivY ) ; trackUsingKlt ( tracksPureKlt ) ; trackUsingKlt ( tracksReactivated ) ; } | Updates the location and description of tracks using KLT . Saves a reference to the input image for future processing . |
27,311 | private void trackUsingKlt ( List < CombinedTrack < TD > > tracks ) { for ( int i = 0 ; i < tracks . size ( ) ; ) { CombinedTrack < TD > track = tracks . get ( i ) ; if ( ! trackerKlt . performTracking ( track . track ) ) { tracks . remove ( i ) ; tracksDormant . add ( track ) ; } else { track . set ( track . track . x , track . track . y ) ; i ++ ; } } } | Tracks features in the list using KLT and update their state |
27,312 | public void spawnTracksFromDetected ( ) { FastQueue < AssociatedIndex > matches = associate . getMatches ( ) ; int N = detector . getNumberOfFeatures ( ) ; for ( int i = 0 ; i < N ; i ++ ) associated [ i ] = false ; for ( AssociatedIndex i : matches . toList ( ) ) { associated [ i . dst ] = true ; } for ( int i = 0 ; i < N ; i ++ ) { if ( associated [ i ] ) continue ; Point2D_F64 p = detector . getLocation ( i ) ; TD d = detectedDesc . get ( i ) ; CombinedTrack < TD > track ; if ( tracksUnused . size ( ) > 0 ) { track = tracksUnused . pop ( ) ; } else { track = new CombinedTrack < > ( ) ; track . desc = detector . createDescription ( ) ; track . track = trackerKlt . createNewTrack ( ) ; } trackerKlt . setDescription ( ( float ) p . x , ( float ) p . y , track . track ) ; track . featureId = totalTracks ++ ; track . desc . setTo ( d ) ; track . set ( p ) ; tracksPureKlt . add ( track ) ; tracksSpawned . add ( track ) ; } } | From the found interest points create new tracks . Tracks are only created at points where there are no existing tracks . |
27,313 | private void associateToDetected ( List < CombinedTrack < TD > > known ) { detectedDesc . reset ( ) ; knownDesc . reset ( ) ; int N = detector . getNumberOfFeatures ( ) ; for ( int i = 0 ; i < N ; i ++ ) { detectedDesc . add ( detector . getDescription ( i ) ) ; } for ( CombinedTrack < TD > t : known ) { knownDesc . add ( t . desc ) ; } associate . setSource ( knownDesc ) ; associate . setDestination ( detectedDesc ) ; associate . associate ( ) ; N = Math . max ( known . size ( ) , detector . getNumberOfFeatures ( ) ) ; if ( associated . length < N ) associated = new boolean [ N ] ; } | Associates pre - existing tracks to newly detected features |
27,314 | public void associateAllToDetected ( ) { List < CombinedTrack < TD > > all = new ArrayList < > ( ) ; all . addAll ( tracksReactivated ) ; all . addAll ( tracksDormant ) ; all . addAll ( tracksPureKlt ) ; int numTainted = tracksReactivated . size ( ) + tracksDormant . size ( ) ; tracksReactivated . clear ( ) ; tracksDormant . clear ( ) ; detector . detect ( input ) ; associateToDetected ( all ) ; FastQueue < AssociatedIndex > matches = associate . getMatches ( ) ; for ( int i = 0 ; i < numTainted ; i ++ ) { associated [ i ] = false ; } for ( AssociatedIndex a : matches . toList ( ) ) { if ( a . src >= numTainted ) continue ; CombinedTrack < TD > t = all . get ( a . src ) ; t . set ( detector . getLocation ( a . dst ) ) ; trackerKlt . setDescription ( ( float ) t . x , ( float ) t . y , t . track ) ; tracksReactivated . add ( t ) ; associated [ a . src ] = true ; } for ( int i = 0 ; i < numTainted ; i ++ ) { if ( ! associated [ i ] ) { tracksDormant . add ( all . get ( i ) ) ; } } } | Associate all tracks in any state to the latest observations . If a dormant track is associated it will be reactivated . If a reactivated track is associated it s state will be updated . PureKLT tracks are left unmodified . |
27,315 | public boolean dropTrack ( CombinedTrack < TD > track ) { if ( ! tracksPureKlt . remove ( track ) ) if ( ! tracksReactivated . remove ( track ) ) if ( ! tracksDormant . remove ( track ) ) return false ; tracksUnused . add ( track ) ; return true ; } | Stops tracking the specified track and recycles its data . |
27,316 | public void dropAllTracks ( ) { tracksUnused . addAll ( tracksDormant ) ; tracksUnused . addAll ( tracksPureKlt ) ; tracksUnused . addAll ( tracksReactivated ) ; tracksSpawned . clear ( ) ; tracksPureKlt . clear ( ) ; tracksReactivated . clear ( ) ; tracksSpawned . clear ( ) ; tracksDormant . clear ( ) ; } | Drops all tracks and recycles the data |
27,317 | private void processImage ( ) { final List < Point2D_F64 > leftPts = new ArrayList < > ( ) ; final List < Point2D_F64 > rightPts = new ArrayList < > ( ) ; final List < TupleDesc > leftDesc = new ArrayList < > ( ) ; final List < TupleDesc > rightDesc = new ArrayList < > ( ) ; final ProgressMonitor progressMonitor = new ProgressMonitor ( this , "Compute Feature Information" , "" , 0 , 4 ) ; extractImageFeatures ( progressMonitor , 0 , imageLeft , leftDesc , leftPts ) ; extractImageFeatures ( progressMonitor , 2 , imageRight , rightDesc , rightPts ) ; SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { progressMonitor . close ( ) ; scorePanel . setScorer ( controlPanel . getSelected ( ) ) ; scorePanel . setLocation ( leftPts , rightPts , leftDesc , rightDesc ) ; repaint ( ) ; } } ) ; } | Extracts image information and then passes that info onto scorePanel for display . Data is not recycled to avoid threading issues . |
27,318 | private void extractImageFeatures ( final ProgressMonitor progressMonitor , final int progress , T image , List < TupleDesc > descs , List < Point2D_F64 > locs ) { SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { progressMonitor . setNote ( "Detecting" ) ; } } ) ; detector . detect ( image ) ; SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { progressMonitor . setProgress ( progress + 1 ) ; progressMonitor . setNote ( "Describing" ) ; } } ) ; describe . setImage ( image ) ; orientation . setImage ( image ) ; if ( detector . hasScale ( ) ) { for ( int i = 0 ; i < detector . getNumberOfFeatures ( ) ; i ++ ) { double yaw = 0 ; Point2D_F64 pt = detector . getLocation ( i ) ; double radius = detector . getRadius ( i ) ; if ( describe . requiresOrientation ( ) ) { orientation . setObjectRadius ( radius ) ; yaw = orientation . compute ( pt . x , pt . y ) ; } TupleDesc d = describe . createDescription ( ) ; if ( describe . process ( pt . x , pt . y , yaw , radius , d ) ) { descs . add ( d ) ; locs . add ( pt . copy ( ) ) ; } } } else { orientation . setObjectRadius ( 1 ) ; for ( int i = 0 ; i < detector . getNumberOfFeatures ( ) ; i ++ ) { double yaw = 0 ; Point2D_F64 pt = detector . getLocation ( i ) ; if ( describe . requiresOrientation ( ) ) { yaw = orientation . compute ( pt . x , pt . y ) ; } TupleDesc d = describe . createDescription ( ) ; if ( describe . process ( pt . x , pt . y , yaw , 1 , d ) ) { descs . add ( d ) ; locs . add ( pt . copy ( ) ) ; } } } SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { progressMonitor . setProgress ( progress + 2 ) ; } } ) ; } | Detects the locations of the features in the image and extracts descriptions of each of the features . |
27,319 | protected void resizeForLayer ( int width , int height ) { deriv1X . reshape ( width , height ) ; deriv1Y . reshape ( width , height ) ; deriv2X . reshape ( width , height ) ; deriv2Y . reshape ( width , height ) ; deriv2XX . reshape ( width , height ) ; deriv2YY . reshape ( width , height ) ; deriv2XY . reshape ( width , height ) ; warpImage2 . reshape ( width , height ) ; warpDeriv2X . reshape ( width , height ) ; warpDeriv2Y . reshape ( width , height ) ; warpDeriv2XX . reshape ( width , height ) ; warpDeriv2YY . reshape ( width , height ) ; warpDeriv2XY . reshape ( width , height ) ; derivFlowUX . reshape ( width , height ) ; derivFlowUY . reshape ( width , height ) ; derivFlowVX . reshape ( width , height ) ; derivFlowVY . reshape ( width , height ) ; psiData . reshape ( width , height ) ; psiGradient . reshape ( width , height ) ; psiSmooth . reshape ( width , height ) ; divU . reshape ( width , height ) ; divV . reshape ( width , height ) ; divD . reshape ( width , height ) ; du . reshape ( width , height ) ; dv . reshape ( width , height ) ; } | Resize images for the current layer being processed |
27,320 | private void computePsiSmooth ( GrayF32 ux , GrayF32 uy , GrayF32 vx , GrayF32 vy , GrayF32 psiSmooth ) { int N = derivFlowUX . width * derivFlowUX . height ; for ( int i = 0 ; i < N ; i ++ ) { float vux = ux . data [ i ] ; float vuy = uy . data [ i ] ; float vvx = vx . data [ i ] ; float vvy = vy . data [ i ] ; float mu = vux * vux + vuy * vuy ; float mv = vvx * vvx + vvy * vvy ; psiSmooth . data [ i ] = ( float ) ( 1.0 / ( 2.0 * Math . sqrt ( mu + mv + EPSILON * EPSILON ) ) ) ; } } | Equation 5 . Psi_s |
27,321 | protected void computePsiDataPsiGradient ( GrayF32 image1 , GrayF32 image2 , GrayF32 deriv1x , GrayF32 deriv1y , GrayF32 deriv2x , GrayF32 deriv2y , GrayF32 deriv2xx , GrayF32 deriv2yy , GrayF32 deriv2xy , GrayF32 du , GrayF32 dv , GrayF32 psiData , GrayF32 psiGradient ) { int N = image1 . width * image1 . height ; for ( int i = 0 ; i < N ; i ++ ) { float du_ = du . data [ i ] ; float dv_ = dv . data [ i ] ; float taylor2 = image2 . data [ i ] + deriv2x . data [ i ] * du_ + deriv2y . data [ i ] * dv_ ; float v = taylor2 - image1 . data [ i ] ; psiData . data [ i ] = ( float ) ( 1.0 / ( 2.0 * Math . sqrt ( v * v + EPSILON * EPSILON ) ) ) ; float dIx = deriv2x . data [ i ] + deriv2xx . data [ i ] * du_ + deriv2xy . data [ i ] * dv_ - deriv1x . data [ i ] ; float dIy = deriv2y . data [ i ] + deriv2xy . data [ i ] * du_ + deriv2yy . data [ i ] * dv_ - deriv1y . data [ i ] ; float dI2 = dIx * dIx + dIy * dIy ; psiGradient . data [ i ] = ( float ) ( 1.0 / ( 2.0 * Math . sqrt ( dI2 + EPSILON * EPSILON ) ) ) ; } } | Compute Psi - data using equation 6 and approximation in equation 5 |
27,322 | private void computeDivUVD ( GrayF32 u , GrayF32 v , GrayF32 psi , GrayF32 divU , GrayF32 divV , GrayF32 divD ) { final int stride = psi . stride ; for ( int y = 1 ; y < psi . height - 1 ; y ++ ) { int index = y * stride + 1 ; for ( int x = 1 ; x < psi . width - 1 ; x ++ , index ++ ) { float psi_index = psi . data [ index ] ; float coef0 = 0.5f * ( psi . data [ index + 1 ] + psi_index ) ; float coef1 = 0.5f * ( psi . data [ index - 1 ] + psi_index ) ; float coef2 = 0.5f * ( psi . data [ index + stride ] + psi_index ) ; float coef3 = 0.5f * ( psi . data [ index - stride ] + psi_index ) ; float u_index = u . data [ index ] ; divU . data [ index ] = coef0 * ( u . data [ index + 1 ] - u_index ) + coef1 * ( u . data [ index - 1 ] - u_index ) + coef2 * ( u . data [ index + stride ] - u_index ) + coef3 * ( u . data [ index - stride ] - u_index ) ; float v_index = v . data [ index ] ; divV . data [ index ] = coef0 * ( v . data [ index + 1 ] - v_index ) + coef1 * ( v . data [ index - 1 ] - v_index ) + coef2 * ( v . data [ index + stride ] - v_index ) + coef3 * ( v . data [ index - stride ] - v_index ) ; divD . data [ index ] = coef0 + coef1 + coef2 + coef3 ; } } for ( int x = 0 ; x < psi . width ; x ++ ) { computeDivUVD_safe ( x , 0 , u , v , psi , divU , divV , divD ) ; computeDivUVD_safe ( x , psi . height - 1 , u , v , psi , divU , divV , divD ) ; } for ( int y = 1 ; y < psi . height - 1 ; y ++ ) { computeDivUVD_safe ( 0 , y , u , v , psi , divU , divV , divD ) ; computeDivUVD_safe ( psi . width - 1 , y , u , v , psi , divU , divV , divD ) ; } } | Computes the divergence for u v and d . Equation 8 and Equation 10 . |
27,323 | public void reset ( ) { unused . addAll ( templateNegative ) ; unused . addAll ( templatePositive ) ; templateNegative . clear ( ) ; templatePositive . clear ( ) ; } | Discard previous results and puts it back into its initial state |
27,324 | public void addDescriptor ( boolean positive , ImageRectangle rect ) { addDescriptor ( positive , rect . x0 , rect . y0 , rect . x1 , rect . y1 ) ; } | Creates a new descriptor for the specified region |
27,325 | private void addDescriptor ( boolean positive , NccFeature f ) { if ( positive ) if ( distance ( f , templatePositive ) < 0.05 ) { return ; } if ( ! positive ) { if ( distance ( f , templateNegative ) < 0.05 ) { return ; } if ( distance ( f , templatePositive ) < 0.05 ) { return ; } } if ( positive ) templatePositive . add ( f ) ; else templateNegative . add ( f ) ; } | Adds a descriptor to the positive or negative list . If it is very similar to an existing one it is not added . Look at code for details |
27,326 | public void computeNccDescriptor ( NccFeature f , float x0 , float y0 , float x1 , float y1 ) { double mean = 0 ; float widthStep = ( x1 - x0 ) / 15.0f ; float heightStep = ( y1 - y0 ) / 15.0f ; int index = 0 ; for ( int y = 0 ; y < 15 ; y ++ ) { float sampleY = y0 + y * heightStep ; for ( int x = 0 ; x < 15 ; x ++ ) { mean += f . value [ index ++ ] = interpolate . get_fast ( x0 + x * widthStep , sampleY ) ; } } mean /= 15 * 15 ; double variance = 0 ; index = 0 ; for ( int y = 0 ; y < 15 ; y ++ ) { for ( int x = 0 ; x < 15 ; x ++ ) { double v = f . value [ index ++ ] -= mean ; variance += v * v ; } } variance /= 15 * 15 ; f . mean = mean ; f . sigma = Math . sqrt ( variance ) ; } | Computes the NCC descriptor by sample points at evenly spaced distances inside the rectangle |
27,327 | public NccFeature createDescriptor ( ) { NccFeature f ; if ( unused . isEmpty ( ) ) f = new NccFeature ( 15 * 15 ) ; else f = unused . pop ( ) ; return f ; } | Creates a new descriptor or recycles an old one |
27,328 | public double computeConfidence ( int x0 , int y0 , int x1 , int y1 ) { computeNccDescriptor ( observed , x0 , y0 , x1 , y1 ) ; if ( templateNegative . size ( ) > 0 && templatePositive . size ( ) > 0 ) { double distancePositive = distance ( observed , templatePositive ) ; double distanceNegative = distance ( observed , templateNegative ) ; return distanceNegative / ( distanceNegative + distancePositive ) ; } else if ( templatePositive . size ( ) > 0 ) { return 1.0 - distance ( observed , templatePositive ) ; } else { return distance ( observed , templateNegative ) ; } } | Compute a value which indicates how confident the specified region is to be a member of the positive set . The confidence value is from 0 to 1 . 1 indicates 100% confidence . |
27,329 | public double computeConfidence ( ImageRectangle r ) { return computeConfidence ( r . x0 , r . y0 , r . x1 , r . y1 ) ; } | see the other function with the same name |
27,330 | public double distance ( NccFeature observed , List < NccFeature > candidates ) { double maximum = - Double . MAX_VALUE ; for ( NccFeature f : candidates ) { double score = DescriptorDistance . ncc ( observed , f ) ; if ( score > maximum ) maximum = score ; } return 1 - 0.5 * ( maximum + 1 ) ; } | Computes the best distance to observed from the candidate list . |
27,331 | public void process ( GrayF32 input ) { constructPyramid ( input ) ; corners . reset ( ) ; double scale = Math . pow ( 2.0 , pyramid . size ( ) - 1 ) ; for ( int level = pyramid . size ( ) - 1 ; level >= 0 ; level -- ) { detector . process ( pyramid . get ( level ) ) ; PyramidLevel featsLevel = featureLevels . get ( level ) ; FastQueue < ChessboardCorner > corners = detector . getCorners ( ) ; featsLevel . corners . reset ( ) ; for ( int i = 0 ; i < corners . size ; i ++ ) { ChessboardCorner cf = corners . get ( i ) ; double x = cf . x * scale ; double y = cf . y * scale ; ChessboardCorner cl = featsLevel . corners . grow ( ) ; cl . first = true ; cl . set ( x , y , cf . orientation , cf . intensity ) ; } scale /= 2.0 ; } for ( int levelIdx = 0 ; levelIdx < pyramid . size ( ) ; levelIdx ++ ) { PyramidLevel level0 = featureLevels . get ( levelIdx ) ; if ( levelIdx + 1 < pyramid . size ( ) ) { PyramidLevel level1 = featureLevels . get ( levelIdx + 1 ) ; markSeenAsFalse ( level0 . corners , level1 . corners ) ; } } for ( int levelIdx = 0 ; levelIdx < pyramid . size ( ) ; levelIdx ++ ) { PyramidLevel level = featureLevels . get ( levelIdx ) ; for ( int i = 0 ; i < level . corners . size ; i ++ ) { ChessboardCorner c = level . corners . get ( i ) ; if ( c . first ) corners . grow ( ) . set ( c ) ; } } } | Detects corner features inside the input gray scale image . |
27,332 | void markSeenAsFalse ( FastQueue < ChessboardCorner > corners0 , FastQueue < ChessboardCorner > corners1 ) { nn . setPoints ( corners1 . toList ( ) , false ) ; int radius = detector . shiRadius * 2 + 1 ; for ( int i = 0 ; i < corners0 . size ; i ++ ) { ChessboardCorner c0 = corners0 . get ( i ) ; nnSearch . findNearest ( c0 , radius , 5 , nnResults ) ; for ( int j = 0 ; j < nnResults . size ; j ++ ) { ChessboardCorner c1 = nnResults . get ( j ) . point ; if ( ! c0 . first ) { c1 . first = false ; } else if ( c1 . intensity < c0 . intensity ) { c1 . first = false ; } else { c0 . first = false ; } } } } | Finds corners in list 1 which match corners in list 0 . If the feature in list 0 has already been seen then the feature in list 1 will be marked as seen . Otherwise the feature which is the most intense is marked as first . |
27,333 | public void processImage ( int sourceID , long frameID , final BufferedImage buffered , ImageBase input ) { System . out . flush ( ) ; synchronized ( bufferedImageLock ) { original = ConvertBufferedImage . checkCopy ( buffered , original ) ; work = ConvertBufferedImage . checkDeclare ( buffered , work ) ; } if ( saveRequested ) { saveInputImage ( ) ; saveRequested = false ; } final double timeInSeconds ; synchronized ( this ) { long before = System . nanoTime ( ) ; detector . process ( ( T ) input ) ; long after = System . nanoTime ( ) ; timeInSeconds = ( after - before ) * 1e-9 ; } synchronized ( detected ) { this . detected . reset ( ) ; for ( QrCode d : detector . getDetections ( ) ) { this . detected . grow ( ) . set ( d ) ; } this . failures . reset ( ) ; for ( QrCode d : detector . getFailures ( ) ) { if ( d . failureCause . ordinal ( ) >= QrCode . Failure . READING_BITS . ordinal ( ) ) this . failures . grow ( ) . set ( d ) ; } } controlPanel . polygonPanel . thresholdPanel . updateHistogram ( ( T ) input ) ; SwingUtilities . invokeLater ( ( ) -> { controls . setProcessingTimeS ( timeInSeconds ) ; viewUpdated ( ) ; synchronized ( detected ) { controlPanel . messagePanel . updateList ( detected . toList ( ) , failures . toList ( ) ) ; } } ) ; } | Override this function so that it doesn t threshold the image twice |
27,334 | public boolean computeHomography ( CalibrationObservation observedPoints ) { if ( observedPoints . size ( ) < 4 ) throw new IllegalArgumentException ( "At least 4 points needed in each set of observations. " + " Filter these first please" ) ; List < AssociatedPair > pairs = new ArrayList < > ( ) ; for ( int i = 0 ; i < observedPoints . size ( ) ; i ++ ) { int which = observedPoints . get ( i ) . index ; Point2D_F64 obs = observedPoints . get ( i ) ; pairs . add ( new AssociatedPair ( worldPoints . get ( which ) , obs , true ) ) ; } if ( ! computeHomography . process ( pairs , found ) ) return false ; return true ; } | Computes the homography from a list of detected grid points in the image . The order of the grid points is important and must follow the expected row major starting at the top left . |
27,335 | public synchronized void recycle ( float [ ] array ) { if ( array . length != length ) { throw new IllegalArgumentException ( "Unexpected array length. Expected " + length + " found " + array . length ) ; } storage . add ( array ) ; } | Adds the array to storage . if the array length is unexpected an exception is thrown |
27,336 | private void visualizeResults ( SceneStructureMetric structure , List < BufferedImage > colorImages ) { List < Point3D_F64 > cloudXyz = new ArrayList < > ( ) ; GrowQueue_I32 cloudRgb = new GrowQueue_I32 ( ) ; Point3D_F64 world = new Point3D_F64 ( ) ; Point3D_F64 camera = new Point3D_F64 ( ) ; Point2D_F64 pixel = new Point2D_F64 ( ) ; for ( int i = 0 ; i < structure . points . length ; i ++ ) { SceneStructureMetric . Point p = structure . points [ i ] ; p . get ( world ) ; for ( int j = 0 ; j < p . views . size ; j ++ ) { int viewIdx = p . views . get ( j ) ; SePointOps_F64 . transform ( structure . views [ viewIdx ] . worldToView , world , camera ) ; int cameraIdx = structure . views [ viewIdx ] . camera ; structure . cameras [ cameraIdx ] . model . project ( camera . x , camera . y , camera . z , pixel ) ; BufferedImage image = colorImages . get ( viewIdx ) ; int x = ( int ) pixel . x ; int y = ( int ) pixel . y ; if ( x < 0 || y < 0 || x >= image . getWidth ( ) || y >= image . getHeight ( ) ) continue ; cloudXyz . add ( world . copy ( ) ) ; cloudRgb . add ( image . getRGB ( ( int ) pixel . x , ( int ) pixel . y ) ) ; break ; } } PointCloudViewer viewer = VisualizeData . createPointCloudViewer ( ) ; viewer . setTranslationStep ( 0.05 ) ; viewer . addCloud ( cloudXyz , cloudRgb . data ) ; viewer . setCameraHFov ( UtilAngle . radian ( 60 ) ) ; SwingUtilities . invokeLater ( ( ) -> { viewer . getComponent ( ) . setPreferredSize ( new Dimension ( 500 , 500 ) ) ; ShowImages . showWindow ( viewer . getComponent ( ) , "Reconstruction Points" , true ) ; } ) ; } | Opens a window showing the found point cloud . Points are colorized using the pixel value inside one of the input images |
27,337 | public static void decodeFormatMessage ( int message , QrCode qr ) { int error = message >> 3 ; qr . error = QrCode . ErrorLevel . lookup ( error ) ; qr . mask = QrCodeMaskPattern . lookupMask ( message & 0x07 ) ; } | Assumes that the format message has no errors in it and decodes its data and saves it into the qr code |
27,338 | public static int correctDCH ( int N , int messageNoMask , int generator , int totalBits , int dataBits ) { int bestHamming = 255 ; int bestMessage = - 1 ; int errorBits = totalBits - dataBits ; for ( int i = 0 ; i < N ; i ++ ) { int test = i << errorBits ; test = test ^ bitPolyModulus ( test , generator , totalBits , dataBits ) ; int distance = DescriptorDistance . hamming ( test ^ messageNoMask ) ; if ( distance < bestHamming ) { bestHamming = distance ; bestMessage = i ; } else if ( distance == bestHamming ) { bestMessage = - 1 ; } } return bestMessage ; } | Applies a brute force algorithm to find the message which has the smallest hamming distance . if two messages have the same distance - 1 is returned . |
27,339 | private static void displayResults ( BufferedImage orig , Planar < GrayF32 > distortedImg , ImageDistort allInside , ImageDistort fullView ) { Planar < GrayF32 > undistortedImg = new Planar < > ( GrayF32 . class , distortedImg . getWidth ( ) , distortedImg . getHeight ( ) , distortedImg . getNumBands ( ) ) ; allInside . apply ( distortedImg , undistortedImg ) ; BufferedImage out1 = ConvertBufferedImage . convertTo ( undistortedImg , null , true ) ; fullView . apply ( distortedImg , undistortedImg ) ; BufferedImage out2 = ConvertBufferedImage . convertTo ( undistortedImg , null , true ) ; ListDisplayPanel panel = new ListDisplayPanel ( ) ; panel . addItem ( new ImagePanel ( orig ) , "Original" ) ; panel . addItem ( new ImagePanel ( out1 ) , "Undistorted All Inside" ) ; panel . addItem ( new ImagePanel ( out2 ) , "Undistorted Full View" ) ; ShowImages . showWindow ( panel , "Removing Lens Distortion" , true ) ; } | Displays results in a window for easy comparison .. |
27,340 | public boolean process ( double sampleRadius , Quadrilateral_F64 input ) { work . set ( input ) ; samples . reset ( ) ; estimator . process ( work , false ) ; estimator . getWorldToCamera ( ) . invert ( referenceCameraToWorld ) ; samples . reset ( ) ; createSamples ( sampleRadius , work . a , input . a ) ; createSamples ( sampleRadius , work . b , input . b ) ; createSamples ( sampleRadius , work . c , input . c ) ; createSamples ( sampleRadius , work . d , input . d ) ; if ( samples . size ( ) < 10 ) return false ; maxLocation = 0 ; maxOrientation = 0 ; for ( int i = 0 ; i < samples . size ( ) ; i ++ ) { referenceCameraToWorld . concat ( samples . get ( i ) , difference ) ; ConvertRotation3D_F64 . matrixToRodrigues ( difference . getR ( ) , rodrigues ) ; double theta = Math . abs ( rodrigues . theta ) ; double d = difference . getT ( ) . norm ( ) ; if ( theta > maxOrientation ) { maxOrientation = theta ; } if ( d > maxLocation ) { maxLocation = d ; } } return true ; } | Processes the observation and generates a stability estimate |
27,341 | private void createSamples ( double sampleRadius , Point2D_F64 workPoint , Point2D_F64 originalPoint ) { workPoint . x = originalPoint . x + sampleRadius ; if ( estimator . process ( work , false ) ) { samples . grow ( ) . set ( estimator . getWorldToCamera ( ) ) ; } workPoint . x = originalPoint . x - sampleRadius ; if ( estimator . process ( work , false ) ) { samples . grow ( ) . set ( estimator . getWorldToCamera ( ) ) ; } workPoint . x = originalPoint . x ; workPoint . y = originalPoint . y + sampleRadius ; if ( estimator . process ( work , false ) ) { samples . grow ( ) . set ( estimator . getWorldToCamera ( ) ) ; } workPoint . y = originalPoint . y - sampleRadius ; if ( estimator . process ( work , false ) ) { samples . grow ( ) . set ( estimator . getWorldToCamera ( ) ) ; } workPoint . set ( originalPoint ) ; } | Samples around the provided corner + - in x and y directions |
27,342 | public void initialLearning ( Rectangle2D_F64 targetRegion , FastQueue < ImageRectangle > cascadeRegions ) { storageMetric . reset ( ) ; fernNegative . clear ( ) ; TldHelperFunctions . convertRegion ( targetRegion , targetRegion_I32 ) ; variance . selectThreshold ( targetRegion_I32 ) ; template . addDescriptor ( true , targetRegion_I32 ) ; fern . learnFernNoise ( true , targetRegion_I32 ) ; for ( int i = 0 ; i < cascadeRegions . size ; i ++ ) { ImageRectangle r = cascadeRegions . get ( i ) ; if ( ! variance . checkVariance ( r ) ) continue ; double overlap = helper . computeOverlap ( targetRegion_I32 , r ) ; if ( overlap > config . overlapLower ) continue ; fernNegative . add ( r ) ; } int N = fernNegative . size ( ) ; for ( int i = 0 ; i < N ; i ++ ) { fern . learnFern ( false , fernNegative . get ( i ) ) ; } detection . detectionCascade ( cascadeRegions ) ; learnAmbiguousNegative ( targetRegion ) ; } | Select positive and negative examples based on the region the user s initially selected region . The selected region is used as a positive example while all the other regions far away are used as negative examples . |
27,343 | public void updateLearning ( Rectangle2D_F64 targetRegion ) { storageMetric . reset ( ) ; TldHelperFunctions . convertRegion ( targetRegion , targetRegion_I32 ) ; template . addDescriptor ( true , targetRegion_I32 ) ; fern . learnFernNoise ( true , targetRegion_I32 ) ; FastQueue < TldRegionFernInfo > ferns = detection . getFernInfo ( ) ; int N = Math . min ( config . numNegativeFerns , ferns . size ) ; for ( int i = 0 ; i < N ; i ++ ) { int index = rand . nextInt ( ferns . size ) ; TldRegionFernInfo f = ferns . get ( index ) ; double overlap = helper . computeOverlap ( targetRegion_I32 , f . r ) ; if ( overlap > config . overlapLower ) continue ; fern . learnFern ( false , f . r ) ; } learnAmbiguousNegative ( targetRegion ) ; } | Updates learning using the latest tracking results . |
27,344 | protected void learnAmbiguousNegative ( Rectangle2D_F64 targetRegion ) { TldHelperFunctions . convertRegion ( targetRegion , targetRegion_I32 ) ; if ( detection . isSuccess ( ) ) { TldRegion best = detection . getBest ( ) ; double overlap = helper . computeOverlap ( best . rect , targetRegion_I32 ) ; if ( overlap <= config . overlapLower ) { template . addDescriptor ( false , best . rect ) ; } List < ImageRectangle > ambiguous = detection . getAmbiguousRegions ( ) ; for ( ImageRectangle r : ambiguous ) { overlap = helper . computeOverlap ( r , targetRegion_I32 ) ; if ( overlap <= config . overlapLower ) { fern . learnFernNoise ( false , r ) ; template . addDescriptor ( false , r ) ; } } } } | Mark regions which were local maximums and had high confidence as negative . These regions were candidates for the tracker but were not selected |
27,345 | public static < T extends ImageGray < T > > InputToBinary < T > localOtsu ( ConfigLength regionWidth , double scale , boolean down , boolean otsu2 , double tuning , Class < T > inputType ) { if ( BOverrideFactoryThresholdBinary . localOtsu != null ) return BOverrideFactoryThresholdBinary . localOtsu . handle ( otsu2 , regionWidth , tuning , scale , down , inputType ) ; ThresholdLocalOtsu otsu ; if ( BoofConcurrency . USE_CONCURRENT ) { otsu = new ThresholdLocalOtsu_MT ( otsu2 , regionWidth , tuning , scale , down ) ; } else { otsu = new ThresholdLocalOtsu ( otsu2 , regionWidth , tuning , scale , down ) ; } return new InputToBinarySwitch < > ( otsu , inputType ) ; } | Applies a local Otsu threshold |
27,346 | public static < T extends ImageGray < T > > InputToBinary < T > blockMean ( ConfigLength regionWidth , double scale , boolean down , boolean thresholdFromLocalBlocks , Class < T > inputType ) { if ( BOverrideFactoryThresholdBinary . blockMean != null ) return BOverrideFactoryThresholdBinary . blockMean . handle ( regionWidth , scale , down , thresholdFromLocalBlocks , inputType ) ; BlockProcessor processor ; if ( inputType == GrayU8 . class ) processor = new ThresholdBlockMean_U8 ( scale , down ) ; else processor = new ThresholdBlockMean_F32 ( ( float ) scale , down ) ; if ( BoofConcurrency . USE_CONCURRENT ) { return new ThresholdBlock_MT ( processor , regionWidth , thresholdFromLocalBlocks , inputType ) ; } else { return new ThresholdBlock ( processor , regionWidth , thresholdFromLocalBlocks , inputType ) ; } } | Applies a non - overlapping block mean threshold |
27,347 | public static < T extends ImageGray < T > > InputToBinary < T > blockOtsu ( ConfigLength regionWidth , double scale , boolean down , boolean thresholdFromLocalBlocks , boolean otsu2 , double tuning , Class < T > inputType ) { if ( BOverrideFactoryThresholdBinary . blockOtsu != null ) return BOverrideFactoryThresholdBinary . blockOtsu . handle ( otsu2 , regionWidth , tuning , scale , down , thresholdFromLocalBlocks , inputType ) ; BlockProcessor processor = new ThresholdBlockOtsu ( otsu2 , tuning , scale , down ) ; InputToBinary < GrayU8 > otsu ; if ( BoofConcurrency . USE_CONCURRENT ) { otsu = new ThresholdBlock_MT < > ( processor , regionWidth , thresholdFromLocalBlocks , GrayU8 . class ) ; } else { otsu = new ThresholdBlock < > ( processor , regionWidth , thresholdFromLocalBlocks , GrayU8 . class ) ; } return new InputToBinarySwitch < > ( otsu , inputType ) ; } | Applies a non - overlapping block Otsu threshold |
27,348 | public static < T extends ImageGray < T > > InputToBinary < T > threshold ( ConfigThreshold config , Class < T > inputType ) { switch ( config . type ) { case FIXED : return globalFixed ( config . fixedThreshold , config . down , inputType ) ; case GLOBAL_OTSU : return globalOtsu ( config . minPixelValue , config . maxPixelValue , config . scale , config . down , inputType ) ; case GLOBAL_ENTROPY : return globalEntropy ( config . minPixelValue , config . maxPixelValue , config . scale , config . down , inputType ) ; case GLOBAL_LI : return globalLi ( config . minPixelValue , config . maxPixelValue , config . scale , config . down , inputType ) ; case GLOBAL_HUANG : return globalHuang ( config . minPixelValue , config . maxPixelValue , config . scale , config . down , inputType ) ; case LOCAL_GAUSSIAN : return localGaussian ( config . width , config . scale , config . down , inputType ) ; case LOCAL_SAVOLA : return localSauvola ( config . width , config . down , config . savolaK , inputType ) ; case LOCAL_NICK : return localNick ( config . width , config . down , config . nickK , inputType ) ; case LOCAL_MEAN : return localMean ( config . width , config . scale , config . down , inputType ) ; case LOCAL_OTSU : { ConfigThresholdLocalOtsu c = ( ConfigThresholdLocalOtsu ) config ; return localOtsu ( config . width , config . scale , config . down , c . useOtsu2 , c . tuning , inputType ) ; } case BLOCK_MIN_MAX : { ConfigThresholdBlockMinMax c = ( ConfigThresholdBlockMinMax ) config ; return blockMinMax ( c . width , c . scale , c . down , c . thresholdFromLocalBlocks , c . minimumSpread , inputType ) ; } case BLOCK_MEAN : return blockMean ( config . width , config . scale , config . down , config . thresholdFromLocalBlocks , inputType ) ; case BLOCK_OTSU : { ConfigThresholdLocalOtsu c = ( ConfigThresholdLocalOtsu ) config ; return blockOtsu ( c . width , c . scale , c . down , c . thresholdFromLocalBlocks , c . useOtsu2 , c . tuning , inputType ) ; } } throw new IllegalArgumentException ( "Unknown type " + config . type ) ; } | Creates threshold using a config class |
27,349 | public void constraintSouth ( JComponent target , JComponent top , JComponent bottom , int padV ) { if ( bottom == null ) { layout . putConstraint ( SpringLayout . SOUTH , target , - padV , SpringLayout . SOUTH , this ) ; } else { Spring a = Spring . sum ( Spring . constant ( - padV ) , layout . getConstraint ( SpringLayout . NORTH , bottom ) ) ; Spring b ; if ( top == null ) b = Spring . sum ( Spring . height ( target ) , layout . getConstraint ( SpringLayout . NORTH , this ) ) ; else b = Spring . sum ( Spring . height ( target ) , layout . getConstraint ( SpringLayout . SOUTH , top ) ) ; layout . getConstraints ( target ) . setConstraint ( SpringLayout . SOUTH , Spring . max ( a , b ) ) ; } } | Constrain it to the top of it s bottom panel and prevent it from getting crushed below it s size |
27,350 | public void setLensDistoriton ( LensDistortionNarrowFOV distortion ) { pixelToNorm = distortion . undistort_F64 ( true , false ) ; normToPixel = distortion . distort_F64 ( false , true ) ; } | Specifies the intrinsic parameters . |
27,351 | public void setFiducial ( double x0 , double y0 , double x1 , double y1 , double x2 , double y2 , double x3 , double y3 ) { points . get ( 0 ) . location . set ( x0 , y0 , 0 ) ; points . get ( 1 ) . location . set ( x1 , y1 , 0 ) ; points . get ( 2 ) . location . set ( x2 , y2 , 0 ) ; points . get ( 3 ) . location . set ( x3 , y3 , 0 ) ; } | Specify the location of points on the 2D fiducial . These should be in world coordinates |
27,352 | public void pixelToMarker ( double pixelX , double pixelY , Point2D_F64 marker ) { pixelToNorm . compute ( pixelX , pixelY , marker ) ; cameraP3 . set ( marker . x , marker . y , 1 ) ; GeometryMath_F64 . multTran ( outputFiducialToCamera . R , cameraP3 , ray . slope ) ; GeometryMath_F64 . multTran ( outputFiducialToCamera . R , outputFiducialToCamera . T , ray . p ) ; ray . p . scale ( - 1 ) ; double t = - ray . p . z / ray . slope . z ; marker . x = ray . p . x + ray . slope . x * t ; marker . y = ray . p . y + ray . slope . y * t ; } | Given the found solution compute the the observed pixel would appear on the marker s surface . pixel - > normalized pixel - > rotated - > projected on to plane |
27,353 | protected boolean estimate ( Quadrilateral_F64 cornersPixels , Quadrilateral_F64 cornersNorm , Se3_F64 foundFiducialToCamera ) { listObs . clear ( ) ; listObs . add ( cornersPixels . a ) ; listObs . add ( cornersPixels . b ) ; listObs . add ( cornersPixels . c ) ; listObs . add ( cornersPixels . d ) ; points . get ( 0 ) . observation . set ( cornersNorm . a ) ; points . get ( 1 ) . observation . set ( cornersNorm . b ) ; points . get ( 2 ) . observation . set ( cornersNorm . c ) ; points . get ( 3 ) . observation . set ( cornersNorm . d ) ; bestError = Double . MAX_VALUE ; estimateP3P ( 0 ) ; estimateP3P ( 1 ) ; estimateP3P ( 2 ) ; estimateP3P ( 3 ) ; if ( bestError == Double . MAX_VALUE ) return false ; inputP3P . clear ( ) ; for ( int i = 0 ; i < 4 ; i ++ ) { inputP3P . add ( points . get ( i ) ) ; } if ( bestError > 2 ) { if ( epnp . process ( inputP3P , foundEPNP ) ) { if ( foundEPNP . T . z > 0 ) { double error = computeErrors ( foundEPNP ) ; if ( error < bestError ) { bestPose . set ( foundEPNP ) ; } } } } if ( ! refine . fitModel ( inputP3P , bestPose , foundFiducialToCamera ) ) { foundFiducialToCamera . set ( bestPose ) ; return true ; } return true ; } | Given the observed corners of the quad in the image in pixels estimate and store the results of its pose |
27,354 | protected void estimateP3P ( int excluded ) { inputP3P . clear ( ) ; for ( int i = 0 ; i < 4 ; i ++ ) { if ( i != excluded ) { inputP3P . add ( points . get ( i ) ) ; } } solutions . reset ( ) ; if ( ! p3p . process ( inputP3P , solutions ) ) { return ; } for ( int i = 0 ; i < solutions . size ; i ++ ) { double error = computeErrors ( solutions . get ( i ) ) ; if ( error < bestError ) { bestError = error ; bestPose . set ( solutions . get ( i ) ) ; } } } | Estimates the pose using P3P from 3 out of 4 points . Then use all 4 to pick the best solution |
27,355 | protected void enlarge ( Quadrilateral_F64 corners , double scale ) { UtilPolygons2D_F64 . center ( corners , center ) ; extend ( center , corners . a , scale ) ; extend ( center , corners . b , scale ) ; extend ( center , corners . c , scale ) ; extend ( center , corners . d , scale ) ; } | Enlarges the quadrilateral to make it more sensitive to changes in orientation |
27,356 | protected double computeErrors ( Se3_F64 fiducialToCamera ) { if ( fiducialToCamera . T . z < 0 ) { return Double . MAX_VALUE ; } double maxError = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) { maxError = Math . max ( maxError , computePixelError ( fiducialToCamera , points . get ( i ) . location , listObs . get ( i ) ) ) ; } return maxError ; } | Compute the sum of reprojection errors for all four points |
27,357 | public void encode ( DMatrixRMaj F , double [ ] param ) { selectColumns ( F ) ; double v [ ] = new double [ ] { F . get ( 0 , col0 ) , F . get ( 1 , col0 ) , F . get ( 2 , col0 ) , F . get ( 0 , col1 ) , F . get ( 1 , col1 ) , F . get ( 2 , col1 ) } ; double divisor = selectDivisor ( v , param ) ; SimpleMatrix A = new SimpleMatrix ( 3 , 2 ) ; SimpleMatrix y = new SimpleMatrix ( 3 , 1 ) ; for ( int i = 0 ; i < 3 ; i ++ ) { A . set ( i , 0 , v [ i ] ) ; A . set ( i , 1 , v [ i + 3 ] ) ; y . set ( i , 0 , F . get ( i , col2 ) / divisor ) ; } SimpleMatrix x = A . solve ( y ) ; param [ 5 ] = x . get ( 0 ) ; param [ 6 ] = x . get ( 1 ) ; } | Examines the matrix structure to determine how to parameterize F . |
27,358 | private double selectDivisor ( double v [ ] , double param [ ] ) { double maxValue = 0 ; int maxIndex = 0 ; for ( int i = 0 ; i < v . length ; i ++ ) { if ( Math . abs ( v [ i ] ) > maxValue ) { maxValue = Math . abs ( v [ i ] ) ; maxIndex = i ; } } double divisor = v [ maxIndex ] ; int index = 0 ; for ( int i = 0 ; i < v . length ; i ++ ) { v [ i ] /= divisor ; if ( i != maxIndex ) { param [ index ] = v [ i ] ; int col = i < 3 ? col0 : col1 ; indexes [ index ++ ] = 3 * ( i % 3 ) + col ; } } int col = maxIndex >= 3 ? col1 : col0 ; indexes [ 5 ] = 3 * ( maxIndex % 3 ) + col ; return divisor ; } | The divisor is the element in the first two columns that has the largest absolute value . Finds this element sets col0 to be the row which contains it and specifies which elements in that column are to be used . |
27,359 | protected void createEdge ( String src , String dst , FastQueue < AssociatedPair > pairs , FastQueue < AssociatedIndex > matches ) { int countF = 0 ; if ( ransac3D . process ( pairs . toList ( ) ) ) { countF = ransac3D . getMatchSet ( ) . size ( ) ; } int countH = 0 ; if ( ransacH . process ( pairs . toList ( ) ) ) { countH = ransacH . getMatchSet ( ) . size ( ) ; } if ( Math . max ( countF , countH ) < minimumInliers ) return ; boolean is3D = countF > countH * ratio3D ; PairwiseImageGraph2 . Motion edge = graph . edges . grow ( ) ; edge . is3D = is3D ; edge . countF = countF ; edge . countH = countH ; edge . index = graph . edges . size - 1 ; edge . src = graph . lookupNode ( src ) ; edge . dst = graph . lookupNode ( dst ) ; edge . src . connections . add ( edge ) ; edge . dst . connections . add ( edge ) ; if ( is3D ) { saveInlierMatches ( ransac3D , matches , edge ) ; edge . F . set ( ransac3D . getModelParameters ( ) ) ; } else { saveInlierMatches ( ransacH , matches , edge ) ; Homography2D_F64 H = ransacH . getModelParameters ( ) ; ConvertDMatrixStruct . convert ( H , edge . F ) ; } } | Connects two views together if they meet a minimal set of geometric requirements . Determines if there is strong evidence that there is 3D information present and not just a homography |
27,360 | private void saveInlierMatches ( ModelMatcher < ? , ? > ransac , FastQueue < AssociatedIndex > matches , PairwiseImageGraph2 . Motion edge ) { int N = ransac . getMatchSet ( ) . size ( ) ; edge . inliers . reset ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int idx = ransac . getInputIndex ( i ) ; edge . inliers . grow ( ) . set ( matches . get ( idx ) ) ; } } | Puts the inliers from RANSAC into the edge s list of associated features |
27,361 | protected void recycleData ( ) { for ( int i = 0 ; i < nodes . size ( ) ; i ++ ) { SquareNode n = nodes . get ( i ) ; for ( int j = 0 ; j < n . edges . length ; j ++ ) { if ( n . edges [ j ] != null ) { graph . detachEdge ( n . edges [ j ] ) ; } } } for ( int i = 0 ; i < nodes . size ( ) ; i ++ ) { SquareNode n = nodes . get ( i ) ; for ( int j = 0 ; j < n . edges . length ; j ++ ) { if ( n . edges [ j ] != null ) throw new RuntimeException ( "BUG!" ) ; } } nodes . reset ( ) ; for ( int i = 0 ; i < clusters . size ; i ++ ) { clusters . get ( i ) . clear ( ) ; } clusters . reset ( ) ; } | Reset and recycle data structures from the previous run |
27,362 | protected void findClusters ( ) { for ( int i = 0 ; i < nodes . size ( ) ; i ++ ) { SquareNode n = nodes . get ( i ) ; if ( n . graph < 0 ) { n . graph = clusters . size ( ) ; List < SquareNode > graph = clusters . grow ( ) ; graph . add ( n ) ; addToCluster ( n , graph ) ; } } } | Put sets of nodes into the same list if they are some how connected |
27,363 | void addToCluster ( SquareNode seed , List < SquareNode > graph ) { open . clear ( ) ; open . add ( seed ) ; while ( ! open . isEmpty ( ) ) { SquareNode n = open . remove ( open . size ( ) - 1 ) ; for ( int i = 0 ; i < n . square . size ( ) ; i ++ ) { SquareEdge edge = n . edges [ i ] ; if ( edge == null ) continue ; SquareNode other ; if ( edge . a == n ) other = edge . b ; else if ( edge . b == n ) other = edge . a ; else throw new RuntimeException ( "BUG!" ) ; if ( other . graph == SquareNode . RESET_GRAPH ) { other . graph = n . graph ; graph . add ( other ) ; open . add ( other ) ; } else if ( other . graph != n . graph ) { throw new RuntimeException ( "BUG! " + other . graph + " " + n . graph ) ; } } } } | Finds all neighbors and adds them to the graph . Repeated until there are no more nodes to add to the graph |
27,364 | public static void printClickedColor ( final BufferedImage image ) { ImagePanel gui = new ImagePanel ( image ) ; gui . addMouseListener ( new MouseAdapter ( ) { public void mouseClicked ( MouseEvent e ) { float [ ] color = new float [ 3 ] ; int rgb = image . getRGB ( e . getX ( ) , e . getY ( ) ) ; ColorHsv . rgbToHsv ( ( rgb >> 16 ) & 0xFF , ( rgb >> 8 ) & 0xFF , rgb & 0xFF , color ) ; System . out . println ( "H = " + color [ 0 ] + " S = " + color [ 1 ] + " V = " + color [ 2 ] ) ; showSelectedColor ( "Selected" , image , color [ 0 ] , color [ 1 ] ) ; } } ) ; ShowImages . showWindow ( gui , "Color Selector" ) ; } | Shows a color image and allows the user to select a pixel convert it to HSV print the HSV values and calls the function below to display similar pixels . |
27,365 | public static void showSelectedColor ( String name , BufferedImage image , float hue , float saturation ) { Planar < GrayF32 > input = ConvertBufferedImage . convertFromPlanar ( image , null , true , GrayF32 . class ) ; Planar < GrayF32 > hsv = input . createSameShape ( ) ; ColorHsv . rgbToHsv ( input , hsv ) ; float maxDist2 = 0.4f * 0.4f ; GrayF32 H = hsv . getBand ( 0 ) ; GrayF32 S = hsv . getBand ( 1 ) ; float adjustUnits = ( float ) ( Math . PI / 2.0 ) ; BufferedImage output = new BufferedImage ( input . width , input . height , BufferedImage . TYPE_INT_RGB ) ; for ( int y = 0 ; y < hsv . height ; y ++ ) { for ( int x = 0 ; x < hsv . width ; x ++ ) { float dh = UtilAngle . dist ( H . unsafe_get ( x , y ) , hue ) ; float ds = ( S . unsafe_get ( x , y ) - saturation ) * adjustUnits ; float dist2 = dh * dh + ds * ds ; if ( dist2 <= maxDist2 ) { output . setRGB ( x , y , image . getRGB ( x , y ) ) ; } } } ShowImages . showWindow ( output , "Showing " + name ) ; } | Selectively displays only pixels which have a similar hue and saturation values to what is provided . This is intended to be a simple example of color based segmentation . Color based segmentation can be done in RGB color but is more problematic due to it not being intensity invariant . More robust techniques can use Gaussian models instead of a uniform distribution as is done below . |
27,366 | public static ImageDimension transformDimension ( ImageBase orig , int level ) { return transformDimension ( orig . width , orig . height , level ) ; } | Returns dimension which is required for the transformed image in a multilevel wavelet transform . |
27,367 | public static int borderForwardLower ( WlCoef desc ) { int ret = - Math . min ( desc . offsetScaling , desc . offsetWavelet ) ; return ret + ( ret % 2 ) ; } | Returns the lower border for a forward wavelet transform . |
27,368 | public static int borderInverseLower ( WlBorderCoef < ? > desc , BorderIndex1D border ) { WlCoef inner = desc . getInnerCoefficients ( ) ; int borderSize = borderForwardLower ( inner ) ; WlCoef ll = borderSize > 0 ? inner : null ; WlCoef lu = ll ; WlCoef uu = inner ; int indexLU = 0 ; if ( desc . getLowerLength ( ) > 0 ) { ll = desc . getBorderCoefficients ( 0 ) ; indexLU = desc . getLowerLength ( ) * 2 - 2 ; lu = desc . getBorderCoefficients ( indexLU ) ; } if ( desc . getUpperLength ( ) > 0 ) { uu = desc . getBorderCoefficients ( - 2 ) ; } border . setLength ( 2000 ) ; borderSize = checkInverseLower ( ll , 0 , border , borderSize ) ; borderSize = checkInverseLower ( lu , indexLU , border , borderSize ) ; borderSize = checkInverseLower ( uu , 1998 , border , borderSize ) ; return borderSize ; } | Returns the lower border for an inverse wavelet transform . |
27,369 | public static int round ( int top , int div2 , int divisor ) { if ( top > 0 ) return ( top + div2 ) / divisor ; else return ( top - div2 ) / divisor ; } | Specialized rounding for use with integer wavelet transform . |
27,370 | public static void adjustForDisplay ( ImageGray transform , int numLevels , double valueRange ) { if ( transform instanceof GrayF32 ) adjustForDisplay ( ( GrayF32 ) transform , numLevels , ( float ) valueRange ) ; else adjustForDisplay ( ( GrayI ) transform , numLevels , ( int ) valueRange ) ; } | Adjusts the values inside a wavelet transform to make it easier to view . |
27,371 | public static void equalizeLocalNaive ( GrayU8 input , int radius , GrayU8 output , IWorkArrays workArrays ) { int width = 2 * radius + 1 ; int maxValue = workArrays . length ( ) - 1 ; int idx0 = 0 , idx1 = input . height ; int [ ] histogram = workArrays . pop ( ) ; for ( int y = idx0 ; y < idx1 ; y ++ ) { int y0 = y - radius ; int y1 = y + radius + 1 ; if ( y0 < 0 ) { y0 = 0 ; y1 = width ; if ( y1 > input . height ) y1 = input . height ; } else if ( y1 > input . height ) { y1 = input . height ; y0 = y1 - width ; if ( y0 < 0 ) y0 = 0 ; } int indexIn = input . startIndex + y * input . stride ; int indexOut = output . startIndex + y * output . stride ; for ( int x = 0 ; x < input . width ; x ++ ) { int x0 = x - radius ; int x1 = x + radius + 1 ; if ( x0 < 0 ) { x0 = 0 ; x1 = width ; if ( x1 > input . width ) x1 = input . width ; } else if ( x1 > input . width ) { x1 = input . width ; x0 = x1 - width ; if ( x0 < 0 ) x0 = 0 ; } localHistogram ( input , x0 , y0 , x1 , y1 , histogram ) ; int inputValue = input . data [ indexIn ++ ] & 0xFF ; int sum = 0 ; for ( int i = 0 ; i <= inputValue ; i ++ ) { sum += histogram [ i ] ; } int area = ( y1 - y0 ) * ( x1 - x0 ) ; output . data [ indexOut ++ ] = ( byte ) ( ( sum * maxValue ) / area ) ; } } workArrays . recycle ( histogram ) ; } | Inefficiently computes the local histogram but can handle every possible case for image size and local region size |
27,372 | public static void equalizeLocalInner ( GrayU8 input , int radius , GrayU8 output , IWorkArrays workArrays ) { int width = 2 * radius + 1 ; int area = width * width ; int maxValue = workArrays . length ( ) - 1 ; int y0 = radius , y1 = input . height - radius ; int [ ] histogram = workArrays . pop ( ) ; for ( int y = y0 ; y < y1 ; y ++ ) { localHistogram ( input , 0 , y - radius , width , y + radius + 1 , histogram ) ; int inputValue = input . unsafe_get ( radius , y ) ; int sum = 0 ; for ( int i = 0 ; i <= inputValue ; i ++ ) { sum += histogram [ i ] ; } output . set ( radius , y , ( sum * maxValue ) / area ) ; int indexOld = input . startIndex + y * input . stride ; int indexNew = indexOld + width ; int indexIn = input . startIndex + y * input . stride + radius + 1 ; int indexOut = output . startIndex + y * output . stride + radius + 1 ; for ( int x = radius + 1 ; x < input . width - radius ; x ++ ) { for ( int i = - radius ; i <= radius ; i ++ ) { histogram [ input . data [ indexOld + i * input . stride ] & 0xFF ] -- ; } for ( int i = - radius ; i <= radius ; i ++ ) { histogram [ input . data [ indexNew + i * input . stride ] & 0xFF ] ++ ; } inputValue = input . data [ indexIn ++ ] & 0xFF ; sum = 0 ; for ( int i = 0 ; i <= inputValue ; i ++ ) { sum += histogram [ i ] ; } output . data [ indexOut ++ ] = ( byte ) ( ( sum * maxValue ) / area ) ; indexOld ++ ; indexNew ++ ; } } workArrays . recycle ( histogram ) ; } | Performs local histogram equalization just on the inner portion of the image |
27,373 | public static void localHistogram ( GrayU16 input , int x0 , int y0 , int x1 , int y1 , int histogram [ ] ) { for ( int i = 0 ; i < histogram . length ; i ++ ) histogram [ i ] = 0 ; for ( int i = y0 ; i < y1 ; i ++ ) { int index = input . startIndex + i * input . stride + x0 ; int end = index + x1 - x0 ; for ( ; index < end ; index ++ ) { histogram [ input . data [ index ] & 0xFFFF ] ++ ; } } } | Computes the local histogram just for the specified inner region |
27,374 | public synchronized void setBufferedImage ( BufferedImage image ) { if ( checkEventDispatch && this . img != null ) { if ( ! SwingUtilities . isEventDispatchThread ( ) ) throw new RuntimeException ( "Changed image when not in GUI thread?" ) ; } this . img = image ; if ( image != null ) updateSize ( image . getWidth ( ) , image . getHeight ( ) ) ; } | Change the image being displayed . |
27,375 | public void initialize ( T image , RectangleLength2D_I32 initial ) { if ( ! image . isInBounds ( initial . x0 , initial . y0 ) ) throw new IllegalArgumentException ( "Initial rectangle is out of bounds!" ) ; if ( ! image . isInBounds ( initial . x0 + initial . width , initial . y0 + initial . height ) ) throw new IllegalArgumentException ( "Initial rectangle is out of bounds!" ) ; pdf . reshape ( image . width , image . height ) ; ImageMiscOps . fill ( pdf , - 1 ) ; setTrackLocation ( initial ) ; failed = false ; minimumSum = 0 ; targetModel . setImage ( image ) ; for ( int y = 0 ; y < initial . height ; y ++ ) { for ( int x = 0 ; x < initial . width ; x ++ ) { minimumSum += targetModel . compute ( x + initial . x0 , y + initial . y0 ) ; } } minimumSum *= minFractionDrop ; } | Specifies the initial target location so that it can learn its description |
27,376 | public boolean process ( T image ) { if ( failed ) return false ; targetModel . setImage ( image ) ; dirty . set ( location . x0 , location . y0 , location . x0 + location . width , location . y0 + location . height ) ; updatePdfImage ( location . x0 , location . y0 , location . x0 + location . width , location . y0 + location . height ) ; int x0 = location . x0 ; int y0 = location . y0 ; int prevX = x0 ; int prevY = y0 ; for ( int i = 0 ; i < maxIterations ; i ++ ) { float totalPdf = 0 ; float sumX = 0 ; float sumY = 0 ; for ( int y = 0 ; y < location . height ; y ++ ) { int indexPdf = pdf . startIndex + pdf . stride * ( y + y0 ) + x0 ; for ( int x = 0 ; x < location . width ; x ++ ) { float p = pdf . data [ indexPdf ++ ] ; totalPdf += p ; sumX += ( x0 + x ) * p ; sumY += ( y0 + y ) * p ; } } if ( totalPdf <= minimumSum ) { failed = true ; return false ; } x0 = ( int ) ( sumX / totalPdf - location . width / 2 + 0.5f ) ; y0 = ( int ) ( sumY / totalPdf - location . height / 2 + 0.5f ) ; if ( x0 < 0 ) x0 = 0 ; else if ( x0 >= image . width - location . width ) x0 = image . width - location . width ; if ( y0 < 0 ) y0 = 0 ; else if ( y0 >= image . height - location . height ) y0 = image . height - location . height ; if ( x0 == prevX && y0 == prevY ) break ; prevX = x0 ; prevY = y0 ; updatePdfImage ( x0 , y0 , x0 + location . width , y0 + location . height ) ; } location . x0 = x0 ; location . y0 = y0 ; ImageMiscOps . fillRectangle ( pdf , - 1 , dirty . x0 , dirty . y0 , dirty . x1 - dirty . x0 , dirty . y1 - dirty . y0 ) ; return true ; } | Updates the target s location in the image by performing a mean - shift search . Returns if it was successful at finding the target or not . If it fails once it will need to be re - initialized |
27,377 | protected void updatePdfImage ( int x0 , int y0 , int x1 , int y1 ) { for ( int y = y0 ; y < y1 ; y ++ ) { int indexOut = pdf . startIndex + pdf . stride * y + x0 ; for ( int x = x0 ; x < x1 ; x ++ , indexOut ++ ) { if ( pdf . data [ indexOut ] < 0 ) pdf . data [ indexOut ] = targetModel . compute ( x , y ) ; } } if ( dirty . x0 > x0 ) dirty . x0 = x0 ; if ( dirty . y0 > y0 ) dirty . y0 = y0 ; if ( dirty . x1 < x1 ) dirty . x1 = x1 ; if ( dirty . y1 < y1 ) dirty . y1 = y1 ; } | Computes the PDF only inside the image as needed amd update the dirty rectangle |
27,378 | public void process ( T image ) { this . image = image ; this . stopRequested = false ; modeLocation . reset ( ) ; modeColor . reset ( ) ; modeMemberCount . reset ( ) ; interpolate . setImage ( image ) ; pixelToMode . reshape ( image . width , image . height ) ; quickMode . reshape ( image . width , image . height ) ; ImageMiscOps . fill ( pixelToMode , - 1 ) ; ImageMiscOps . fill ( quickMode , - 1 ) ; int indexImg = 0 ; for ( int y = 0 ; y < image . height && ! stopRequested ; y ++ ) { for ( int x = 0 ; x < image . width ; x ++ , indexImg ++ ) { if ( pixelToMode . data [ indexImg ] != - 1 ) { int peakIndex = pixelToMode . data [ indexImg ] ; modeMemberCount . data [ peakIndex ] ++ ; continue ; } float meanColor = interpolate . get ( x , y ) ; findPeak ( x , y , meanColor ) ; int modeX = ( int ) ( this . modeX + 0.5f ) ; int modeY = ( int ) ( this . modeY + 0.5f ) ; int modePixelIndex = modeY * image . width + modeX ; int modeIndex = quickMode . data [ modePixelIndex ] ; if ( modeIndex < 0 ) { modeIndex = this . modeLocation . size ( ) ; this . modeLocation . grow ( ) . set ( modeX , modeY ) ; modeColor . grow ( ) [ 0 ] = meanGray ; quickMode . data [ modePixelIndex ] = modeIndex ; modeMemberCount . add ( 0 ) ; } modeMemberCount . data [ modeIndex ] ++ ; for ( int i = 0 ; i < history . size ; i ++ ) { Point2D_F32 p = history . get ( i ) ; int px = ( int ) ( p . x + 0.5f ) ; int py = ( int ) ( p . y + 0.5f ) ; int index = pixelToMode . getIndex ( px , py ) ; if ( pixelToMode . data [ index ] == - 1 ) { pixelToMode . data [ index ] = modeIndex ; } } } } } | Performs mean - shift clustering on the input image |
27,379 | public void set ( Point2D3D src ) { observation . set ( src . observation ) ; location . set ( src . location ) ; } | Sets this to be identical to src . |
27,380 | public void clearLensDistortion ( ) { detector . clearLensDistortion ( ) ; if ( refineGray != null ) refineGray . clearLensDistortion ( ) ; edgeIntensity . setTransform ( null ) ; } | Discard previously set lens distortion models |
27,381 | public void process ( T gray , GrayU8 binary ) { detector . process ( gray , binary ) ; if ( refineGray != null ) refineGray . setImage ( gray ) ; edgeIntensity . setImage ( gray ) ; long time0 = System . nanoTime ( ) ; FastQueue < DetectPolygonFromContour . Info > detections = detector . getFound ( ) ; if ( adjustForBias != null ) { int minSides = getMinimumSides ( ) ; for ( int i = detections . size ( ) - 1 ; i >= 0 ; i -- ) { Polygon2D_F64 p = detections . get ( i ) . polygon ; adjustForBias . process ( p , detector . isOutputClockwise ( ) ) ; if ( p . size ( ) < minSides ) detections . remove ( i ) ; } } long time1 = System . nanoTime ( ) ; double milli = ( time1 - time0 ) * 1e-6 ; milliAdjustBias . update ( milli ) ; } | Detects polygons inside the grayscale image and its thresholded version |
27,382 | public boolean refine ( DetectPolygonFromContour . Info info ) { double before , after ; if ( edgeIntensity . computeEdge ( info . polygon , ! detector . isOutputClockwise ( ) ) ) { before = edgeIntensity . getAverageOutside ( ) - edgeIntensity . getAverageInside ( ) ; } else { return false ; } boolean success = false ; if ( refineContour != null ) { List < Point2D_I32 > contour = detector . getContour ( info ) ; refineContour . process ( contour , info . splits , work ) ; if ( adjustForBias != null ) adjustForBias . process ( work , detector . isOutputClockwise ( ) ) ; if ( edgeIntensity . computeEdge ( work , ! detector . isOutputClockwise ( ) ) ) { after = edgeIntensity . getAverageOutside ( ) - edgeIntensity . getAverageInside ( ) ; if ( after > before ) { info . edgeInside = edgeIntensity . getAverageInside ( ) ; info . edgeOutside = edgeIntensity . getAverageOutside ( ) ; info . polygon . set ( work ) ; success = true ; before = after ; } } } if ( functionAdjust != null ) { functionAdjust . adjust ( info , detector . isOutputClockwise ( ) ) ; } if ( refineGray != null ) { work . vertexes . resize ( info . polygon . size ( ) ) ; if ( refineGray . refine ( info . polygon , work ) ) { if ( edgeIntensity . computeEdge ( work , ! detector . isOutputClockwise ( ) ) ) { after = edgeIntensity . getAverageOutside ( ) - edgeIntensity . getAverageInside ( ) ; if ( after * 1.5 > before ) { info . edgeInside = edgeIntensity . getAverageInside ( ) ; info . edgeOutside = edgeIntensity . getAverageOutside ( ) ; info . polygon . set ( work ) ; success = true ; } } } } return success ; } | Refines the fit to the specified polygon . Only info . polygon is modified |
27,383 | public void refineAll ( ) { List < DetectPolygonFromContour . Info > detections = detector . getFound ( ) . toList ( ) ; for ( int i = 0 ; i < detections . size ( ) ; i ++ ) { refine ( detections . get ( i ) ) ; } } | Refines all the detected polygons and places them into the provided list . Polygons which fail the refinement step are not added . |
27,384 | public static < T extends ImageGray < T > > T checkReshape ( T target , ImageGray testImage , Class < T > targetType ) { if ( target == null ) { return GeneralizedImageOps . createSingleBand ( targetType , testImage . width , testImage . height ) ; } else if ( target . width != testImage . width || target . height != testImage . height ) { target . reshape ( testImage . width , testImage . height ) ; } return target ; } | Checks to see if the target image is null or if it is a different size than the test image . If it is null then a new image is returned otherwise target is reshaped and returned . |
27,385 | protected void findLocalScaleSpaceMax ( PyramidFloat < T > ss , int layerID ) { int index0 = spaceIndex ; int index1 = ( spaceIndex + 1 ) % 3 ; int index2 = ( spaceIndex + 2 ) % 3 ; List < Point2D_I16 > candidates = maximums [ index1 ] ; ImageBorder_F32 inten0 = ( ImageBorder_F32 ) FactoryImageBorderAlgs . value ( intensities [ index0 ] , 0 ) ; GrayF32 inten1 = intensities [ index1 ] ; ImageBorder_F32 inten2 = ( ImageBorder_F32 ) FactoryImageBorderAlgs . value ( intensities [ index2 ] , 0 ) ; float scale0 = ( float ) ss . scale [ layerID - 1 ] ; float scale1 = ( float ) ss . scale [ layerID ] ; float scale2 = ( float ) ss . scale [ layerID + 1 ] ; float sigma0 = ( float ) ss . getSigma ( layerID - 1 ) ; float sigma1 = ( float ) ss . getSigma ( layerID ) ; float sigma2 = ( float ) ss . getSigma ( layerID + 1 ) ; float ss0 = ( float ) ( Math . pow ( sigma0 , scalePower ) / scale0 ) ; float ss1 = ( float ) ( Math . pow ( sigma1 , scalePower ) / scale1 ) ; float ss2 = ( float ) ( Math . pow ( sigma2 , scalePower ) / scale2 ) ; for ( Point2D_I16 c : candidates ) { float val = ss1 * inten1 . get ( c . x , c . y ) ; int x0 = ( int ) ( c . x * scale1 / scale0 ) ; int y0 = ( int ) ( c . y * scale1 / scale0 ) ; int x2 = ( int ) ( c . x * scale1 / scale2 ) ; int y2 = ( int ) ( c . y * scale1 / scale2 ) ; if ( checkMax ( inten0 , val / ss0 , x0 , y0 ) && checkMax ( inten2 , val / ss2 , x2 , y2 ) ) { foundPoints . add ( new ScalePoint ( c . x * scale1 , c . y * scale1 , sigma1 ) ) ; } } } | Searches the pyramid layers up and down to see if the found 2D features are also scale space maximums . |
27,386 | int getCornerIndex ( SquareNode node , double x , double y ) { for ( int i = 0 ; i < node . square . size ( ) ; i ++ ) { Point2D_F64 c = node . square . get ( i ) ; if ( c . x == x && c . y == y ) return i ; } throw new RuntimeException ( "BUG!" ) ; } | Returns the corner index of the specified coordinate |
27,387 | boolean candidateIsMuchCloser ( SquareNode node0 , SquareNode node1 , double distance2 ) { double length = Math . max ( node0 . largestSide , node1 . largestSide ) * tooFarFraction ; length *= length ; if ( distance2 > length ) return false ; return distance2 <= length ; } | Checks to see if the two corners which are to be connected are by far the two closest corners between the two squares |
27,388 | private void handleContextMenu ( JTree tree , int x , int y ) { TreePath path = tree . getPathForLocation ( x , y ) ; tree . setSelectionPath ( path ) ; DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) tree . getLastSelectedPathComponent ( ) ; if ( node == null ) return ; if ( ! node . isLeaf ( ) ) { tree . setSelectionPath ( null ) ; return ; } final AppInfo info = ( AppInfo ) node . getUserObject ( ) ; JMenuItem copyname = new JMenuItem ( "Copy Name" ) ; copyname . addActionListener ( e -> { Clipboard clipboard = Toolkit . getDefaultToolkit ( ) . getSystemClipboard ( ) ; clipboard . setContents ( new StringSelection ( info . app . getSimpleName ( ) ) , null ) ; } ) ; JMenuItem copypath = new JMenuItem ( "Copy Path" ) ; copypath . addActionListener ( e -> { String path1 = UtilIO . getSourcePath ( info . app . getPackage ( ) . getName ( ) , info . app . getSimpleName ( ) ) ; Clipboard clipboard = Toolkit . getDefaultToolkit ( ) . getSystemClipboard ( ) ; clipboard . setContents ( new StringSelection ( path1 ) , null ) ; } ) ; JMenuItem github = new JMenuItem ( "Go to Github" ) ; github . addActionListener ( e -> openInGitHub ( info ) ) ; JPopupMenu submenu = new JPopupMenu ( ) ; submenu . add ( copyname ) ; submenu . add ( copypath ) ; submenu . add ( github ) ; submenu . show ( tree , x , y ) ; } | Displays a context menu for a class leaf node Allows copying of the name and the path to the source |
27,389 | private void openInGitHub ( AppInfo info ) { if ( Desktop . isDesktopSupported ( ) ) { try { URI uri = new URI ( UtilIO . getGithubURL ( info . app . getPackage ( ) . getName ( ) , info . app . getSimpleName ( ) ) ) ; if ( ! uri . getPath ( ) . isEmpty ( ) ) Desktop . getDesktop ( ) . browse ( uri ) ; else System . err . println ( "Bad URL received" ) ; } catch ( Exception e1 ) { JOptionPane . showMessageDialog ( this , "Open GitHub Error" , "Error connecting: " + e1 . getMessage ( ) , JOptionPane . ERROR_MESSAGE ) ; System . err . println ( e1 . getMessage ( ) ) ; } } } | Opens github page of source code up in a browser window |
27,390 | public void killAllProcesses ( long blockTimeMS ) { SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { DefaultListModel model = ( DefaultListModel ) processList . getModel ( ) ; for ( int i = model . size ( ) - 1 ; i >= 0 ; i -- ) { ActiveProcess p = ( ActiveProcess ) model . get ( i ) ; removeProcessTab ( p , false ) ; } } } ) ; synchronized ( processes ) { for ( int i = 0 ; i < processes . size ( ) ; i ++ ) { processes . get ( i ) . requestKill ( ) ; } } if ( blockTimeMS > 0 ) { long abortTime = System . currentTimeMillis ( ) + blockTimeMS ; while ( abortTime > System . currentTimeMillis ( ) ) { int total = 0 ; synchronized ( processes ) { for ( int i = 0 ; i < processes . size ( ) ; i ++ ) { if ( ! processes . get ( i ) . isActive ( ) ) { total ++ ; } } if ( processes . size ( ) == total ) { break ; } } } } } | Requests that all active processes be killed . |
27,391 | public void intervalAdded ( ListDataEvent e ) { DefaultListModel listModel = ( DefaultListModel ) e . getSource ( ) ; ActiveProcess process = ( ActiveProcess ) listModel . get ( listModel . getSize ( ) - 1 ) ; addProcessTab ( process , outputPanel ) ; } | Called after a new process is added to the process list |
27,392 | protected void setUpEdges ( GrayS32 input , GrayS32 output ) { if ( connectRule == ConnectRule . EIGHT ) { setUpEdges8 ( input , edgesIn ) ; setUpEdges8 ( output , edgesOut ) ; edges [ 0 ] . set ( 1 , 0 ) ; edges [ 1 ] . set ( 1 , 1 ) ; edges [ 2 ] . set ( 0 , 1 ) ; edges [ 3 ] . set ( - 1 , 0 ) ; } else { setUpEdges4 ( input , edgesIn ) ; setUpEdges4 ( output , edgesOut ) ; edges [ 0 ] . set ( 1 , 0 ) ; edges [ 1 ] . set ( 0 , 1 ) ; } } | Declares lookup tables for neighbors |
27,393 | public void process ( GrayS32 input , GrayS32 output , GrowQueue_I32 regionMemberCount ) { this . regionMemberCount = regionMemberCount ; regionMemberCount . reset ( ) ; setUpEdges ( input , output ) ; ImageMiscOps . fill ( output , - 1 ) ; mergeList . reset ( ) ; connectInner ( input , output ) ; connectLeftRight ( input , output ) ; connectBottom ( input , output ) ; performMerge ( output , regionMemberCount ) ; } | Relabels the image such that all pixels with the same label are a member of the same graph . |
27,394 | protected void connectInner ( GrayS32 input , GrayS32 output ) { int startX = connectRule == ConnectRule . EIGHT ? 1 : 0 ; for ( int y = 0 ; y < input . height - 1 ; y ++ ) { int indexIn = input . startIndex + y * input . stride + startX ; int indexOut = output . startIndex + y * output . stride + startX ; for ( int x = startX ; x < input . width - 1 ; x ++ , indexIn ++ , indexOut ++ ) { int inputLabel = input . data [ indexIn ] ; int outputLabel = output . data [ indexOut ] ; if ( outputLabel == - 1 ) { output . data [ indexOut ] = outputLabel = regionMemberCount . size ; regionMemberCount . add ( 1 ) ; mergeList . add ( outputLabel ) ; } for ( int i = 0 ; i < edgesIn . length ; i ++ ) { if ( inputLabel == input . data [ indexIn + edgesIn [ i ] ] ) { int outputAdj = output . data [ indexOut + edgesOut [ i ] ] ; if ( outputAdj == - 1 ) { regionMemberCount . data [ outputLabel ] ++ ; output . data [ indexOut + edgesOut [ i ] ] = outputLabel ; } else if ( outputLabel != outputAdj ) { markMerge ( outputLabel , outputAdj ) ; } } } } } } | Examines pixels inside the image without the need for bounds checking |
27,395 | protected void connectLeftRight ( GrayS32 input , GrayS32 output ) { for ( int y = 0 ; y < input . height ; y ++ ) { int x = input . width - 1 ; int inputLabel = input . unsafe_get ( x , y ) ; int outputLabel = output . unsafe_get ( x , y ) ; if ( outputLabel == - 1 ) { outputLabel = regionMemberCount . size ; output . unsafe_set ( x , y , outputLabel ) ; regionMemberCount . add ( 1 ) ; mergeList . add ( outputLabel ) ; } for ( int i = 0 ; i < edges . length ; i ++ ) { Point2D_I32 offset = edges [ i ] ; if ( ! input . isInBounds ( x + offset . x , y + offset . y ) ) continue ; if ( inputLabel == input . unsafe_get ( x + offset . x , y + offset . y ) ) { int outputAdj = output . unsafe_get ( x + offset . x , y + offset . y ) ; if ( outputAdj == - 1 ) { regionMemberCount . data [ outputLabel ] ++ ; output . unsafe_set ( x + offset . x , y + offset . y , outputLabel ) ; } else if ( outputLabel != outputAdj ) { markMerge ( outputLabel , outputAdj ) ; } } } if ( connectRule != ConnectRule . EIGHT ) continue ; x = 0 ; inputLabel = input . unsafe_get ( x , y ) ; outputLabel = output . unsafe_get ( x , y ) ; if ( outputLabel == - 1 ) { outputLabel = regionMemberCount . size ; output . unsafe_set ( x , y , outputLabel ) ; regionMemberCount . add ( 1 ) ; mergeList . add ( outputLabel ) ; } for ( int i = 0 ; i < edges . length ; i ++ ) { Point2D_I32 offset = edges [ i ] ; if ( ! input . isInBounds ( x + offset . x , y + offset . y ) ) continue ; if ( inputLabel == input . unsafe_get ( x + offset . x , y + offset . y ) ) { int outputAdj = output . unsafe_get ( x + offset . x , y + offset . y ) ; if ( outputAdj == - 1 ) { regionMemberCount . data [ outputLabel ] ++ ; output . unsafe_set ( x + offset . x , y + offset . y , outputLabel ) ; } else if ( outputLabel != outputAdj ) { markMerge ( outputLabel , outputAdj ) ; } } } } } | Examines pixels along the left and right border |
27,396 | protected void connectBottom ( GrayS32 input , GrayS32 output ) { for ( int x = 0 ; x < input . width - 1 ; x ++ ) { int y = input . height - 1 ; int inputLabel = input . unsafe_get ( x , y ) ; int outputLabel = output . unsafe_get ( x , y ) ; if ( outputLabel == - 1 ) { outputLabel = regionMemberCount . size ; output . unsafe_set ( x , y , outputLabel ) ; regionMemberCount . add ( 1 ) ; mergeList . add ( outputLabel ) ; } if ( inputLabel == input . unsafe_get ( x + 1 , y ) ) { int outputAdj = output . unsafe_get ( x + 1 , y ) ; if ( outputAdj == - 1 ) { regionMemberCount . data [ outputLabel ] ++ ; output . unsafe_set ( x + 1 , y , outputLabel ) ; } else if ( outputLabel != outputAdj ) { markMerge ( outputLabel , outputAdj ) ; } } } } | Examines pixels along the bottom border |
27,397 | public void setImage ( I image , D derivX , D derivY ) { InputSanityCheck . checkSameShape ( image , derivX , derivY ) ; this . image = image ; this . interpInput . setImage ( image ) ; this . derivX = derivX ; this . derivY = derivY ; } | Sets the current image it should be tracking with . |
27,398 | @ SuppressWarnings ( { "SuspiciousNameCombination" } ) public boolean setDescription ( KltFeature feature ) { setAllowedBounds ( feature ) ; if ( ! isFullyInside ( feature . x , feature . y ) ) { if ( isFullyOutside ( feature . x , feature . y ) ) return false ; else return internalSetDescriptionBorder ( feature ) ; } return internalSetDescription ( feature ) ; } | Sets the features description using the current image and the location of the feature stored in the feature . If the feature is an illegal location and cannot be set then false is returned . |
27,399 | protected boolean internalSetDescriptionBorder ( KltFeature feature ) { computeSubImageBounds ( feature , feature . x , feature . y ) ; ImageMiscOps . fill ( feature . desc , Float . NaN ) ; feature . desc . subimage ( dstX0 , dstY0 , dstX1 , dstY1 , subimage ) ; interpInput . setImage ( image ) ; interpInput . region ( srcX0 , srcY0 , subimage ) ; feature . derivX . subimage ( dstX0 , dstY0 , dstX1 , dstY1 , subimage ) ; interpDeriv . setImage ( derivX ) ; interpDeriv . region ( srcX0 , srcY0 , subimage ) ; feature . derivY . subimage ( dstX0 , dstY0 , dstX1 , dstY1 , subimage ) ; interpDeriv . setImage ( derivY ) ; interpDeriv . region ( srcX0 , srcY0 , subimage ) ; int total = 0 ; Gxx = Gyy = Gxy = 0 ; for ( int i = 0 ; i < lengthFeature ; i ++ ) { if ( Float . isNaN ( feature . desc . data [ i ] ) ) continue ; total ++ ; float dX = feature . derivX . data [ i ] ; float dY = feature . derivY . data [ i ] ; Gxx += dX * dX ; Gyy += dY * dY ; Gxy += dX * dY ; } feature . Gxx = Gxx ; feature . Gyy = Gyy ; feature . Gxy = Gxy ; float det = Gxx * Gyy - Gxy * Gxy ; return ( det >= config . minDeterminant * total ) ; } | Computes the descriptor for border features . All it needs to do is save the pixel value but derivative information is also computed so that it can reject bad features immediately . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.