idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
27,600 | public void setLensDistortion ( Point2Transform2_F64 pixelToNorm , Point2Transform2_F64 undistToDist ) { if ( pixelToNorm == null ) { this . pixelToNorm = new DoNothing2Transform2_F64 ( ) ; this . undistToDist = new DoNothing2Transform2_F64 ( ) ; } else { this . pixelToNorm = pixelToNorm ; this . undistToDist = undistToDist ; } } | Specifies transform from pixel to normalize image coordinates |
27,601 | public boolean refine ( Point2D_F64 a , Point2D_F64 b , LineGeneral2D_F64 found ) { center . x = ( a . x + b . x ) / 2.0 ; center . y = ( a . y + b . y ) / 2.0 ; localScale = a . distance ( center ) ; double slopeX = ( b . x - a . x ) ; double slopeY = ( b . y - a . y ) ; double r = Math . sqrt ( slopeX * slopeX + slopeY * slopeY ) ; double tanX = slopeY / r ; double tanY = - slopeX / r ; computePointsAndWeights ( slopeX , slopeY , a . x , a . y , tanX , tanY ) ; if ( samplePts . size ( ) >= 4 ) { if ( null == FitLine_F64 . polar ( samplePts . toList ( ) , weights . data , polar ) ) { throw new RuntimeException ( "All weights were zero, bug some place" ) ; } UtilLine2D_F64 . convert ( polar , found ) ; localToGlobal ( found ) ; return true ; } else { return false ; } } | Fits a line defined by the two points . When fitting the line the weight of the edge is used to determine . how influential the point is . Multiple calls might be required to get a perfect fit . |
27,602 | protected void localToGlobal ( LineGeneral2D_F64 line ) { line . C = localScale * line . C - center . x * line . A - center . y * line . B ; } | Converts the line from local to global image coordinates |
27,603 | public void process ( T image , GrayS32 pixelToRegion , GrowQueue_I32 regionMemberCount , FastQueue < float [ ] > regionColor ) { this . image = image ; regionSums . resize ( regionColor . size ) ; for ( int i = 0 ; i < regionSums . size ; i ++ ) { float v [ ] = regionSums . get ( i ) ; for ( int j = 0 ; j < v . length ; j ++ ) { v [ j ] = 0 ; } } for ( int y = 0 ; y < image . height ; y ++ ) { int indexImg = image . startIndex + y * image . stride ; int indexRgn = pixelToRegion . startIndex + y * pixelToRegion . stride ; for ( int x = 0 ; x < image . width ; x ++ , indexRgn ++ , indexImg ++ ) { int region = pixelToRegion . data [ indexRgn ] ; float [ ] sum = regionSums . get ( region ) ; addPixelValue ( indexImg , sum ) ; } } for ( int i = 0 ; i < regionSums . size ; i ++ ) { float N = regionMemberCount . get ( i ) ; float [ ] sum = regionSums . get ( i ) ; float [ ] average = regionColor . get ( i ) ; for ( int j = 0 ; j < numBands ; j ++ ) { average [ j ] = sum [ j ] / N ; } } } | Compute the average color for each region |
27,604 | public boolean process ( PairwiseImageGraph pairwiseGraph ) { this . graph = new MetricSceneGraph ( pairwiseGraph ) ; for ( int i = 0 ; i < graph . edges . size ( ) ; i ++ ) { decomposeEssential ( graph . edges . get ( i ) ) ; } declareModelFitting ( ) ; for ( int i = 0 ; i < graph . edges . size ( ) ; i ++ ) { Motion e = graph . edges . get ( i ) ; e . triangulationAngle = medianTriangulationAngle ( e ) ; } if ( verbose != null ) verbose . println ( "Selecting root" ) ; View origin = selectOriginNode ( ) ; Motion baseMotion = selectCoordinateBase ( origin ) ; this . graph . sanityCheck ( ) ; if ( verbose != null ) verbose . println ( "Stereo triangulation" ) ; for ( int i = 0 ; i < graph . edges . size ( ) && ! stopRequested ; i ++ ) { Motion e = graph . edges . get ( i ) ; if ( e . triangulationAngle > Math . PI / 10 || e == baseMotion ) { triangulateStereoEdges ( e ) ; if ( verbose != null ) { int a = e . viewSrc . index ; int b = e . viewDst . index ; verbose . println ( " Edge[" + i + "] " + a + "->" + b + " feat3D=" + e . stereoTriangulations . size ( ) ) ; } } } if ( stopRequested ) return false ; if ( verbose != null ) verbose . println ( "Defining the coordinate system" ) ; defineCoordinateSystem ( origin , baseMotion ) ; if ( stopRequested ) return false ; if ( verbose != null ) verbose . println ( "Estimate all features" ) ; estimateAllFeatures ( origin , baseMotion . destination ( origin ) ) ; if ( stopRequested ) return false ; convertToOutput ( origin ) ; return viewsAdded . size ( ) >= 2 ; } | Processes the paired up scene features and computes an initial estimate for the scene s structure . |
27,605 | void decomposeEssential ( Motion motion ) { List < Se3_F64 > candidates = MultiViewOps . decomposeEssential ( motion . F ) ; int bestScore = 0 ; Se3_F64 best = null ; PositiveDepthConstraintCheck check = new PositiveDepthConstraintCheck ( ) ; for ( int i = 0 ; i < candidates . size ( ) ; i ++ ) { Se3_F64 a_to_b = candidates . get ( i ) ; int count = 0 ; for ( int j = 0 ; j < motion . associated . size ( ) ; j ++ ) { AssociatedIndex a = motion . associated . get ( j ) ; Point2D_F64 p0 = motion . viewSrc . observationNorm . get ( a . src ) ; Point2D_F64 p1 = motion . viewDst . observationNorm . get ( a . dst ) ; if ( check . checkConstraint ( p0 , p1 , a_to_b ) ) { count ++ ; } } if ( count > bestScore ) { bestScore = count ; best = a_to_b ; } } if ( best == null ) throw new RuntimeException ( "Problem!" ) ; motion . a_to_b . set ( best ) ; } | Sets the a_to_b transform for the motion given . |
27,606 | double medianTriangulationAngle ( Motion edge ) { GrowQueue_F64 angles = new GrowQueue_F64 ( edge . associated . size ( ) ) ; angles . size = edge . associated . size ( ) ; for ( int i = 0 ; i < edge . associated . size ( ) ; i ++ ) { AssociatedIndex a = edge . associated . get ( i ) ; Point2D_F64 normA = edge . viewSrc . observationNorm . get ( a . src ) ; Point2D_F64 normB = edge . viewDst . observationNorm . get ( a . dst ) ; double acute = triangulationAngle ( normA , normB , edge . a_to_b ) ; angles . data [ i ] = acute ; } angles . sort ( ) ; return angles . getFraction ( 0.5 ) ; } | Compares the angle that different observations form when their lines intersect . Returns the median angle . Used to determine if this edge is good for triangulation |
27,607 | private void convertToOutput ( View origin ) { structure = new SceneStructureMetric ( false ) ; observations = new SceneObservations ( viewsAdded . size ( ) ) ; int idx = 0 ; for ( String key : graph . cameras . keySet ( ) ) { cameraToIndex . put ( key , idx ++ ) ; } structure . initialize ( cameraToIndex . size ( ) , viewsAdded . size ( ) , graph . features3D . size ( ) ) ; for ( String key : graph . cameras . keySet ( ) ) { int i = cameraToIndex . get ( key ) ; structure . setCamera ( i , true , graph . cameras . get ( key ) . pinhole ) ; } int viewOldToView [ ] = new int [ graph . nodes . size ( ) ] ; Arrays . fill ( viewOldToView , - 1 ) ; for ( int i = 0 ; i < viewsAdded . size ( ) ; i ++ ) { viewOldToView [ graph . nodes . indexOf ( viewsAdded . get ( i ) ) ] = i ; } for ( int i = 0 ; i < viewsAdded . size ( ) ; i ++ ) { View v = viewsAdded . get ( i ) ; int cameraIndex = cameraToIndex . get ( v . camera . camera ) ; structure . setView ( i , v == origin , v . viewToWorld . invert ( null ) ) ; structure . connectViewToCamera ( i , cameraIndex ) ; } for ( int indexPoint = 0 ; indexPoint < graph . features3D . size ( ) ; indexPoint ++ ) { Feature3D f = graph . features3D . get ( indexPoint ) ; structure . setPoint ( indexPoint , f . worldPt . x , f . worldPt . y , f . worldPt . z ) ; if ( f . views . size ( ) != f . obsIdx . size ) throw new RuntimeException ( "BUG!" ) ; for ( int j = 0 ; j < f . views . size ( ) ; j ++ ) { View view = f . views . get ( j ) ; int viewIndex = viewOldToView [ view . index ] ; structure . connectPointToView ( indexPoint , viewIndex ) ; Point2D_F64 pixel = viewsAdded . get ( viewIndex ) . observationPixels . get ( f . obsIdx . get ( j ) ) ; observations . getView ( viewIndex ) . add ( indexPoint , ( float ) ( pixel . x ) , ( float ) ( pixel . y ) ) ; } } } | Converts the internal data structures into the output format for bundle adjustment . Camera models are omitted since they are not available |
27,608 | void addTriangulatedStereoFeatures ( View base , Motion edge , double scale ) { View viewA = edge . viewSrc ; View viewB = edge . viewDst ; boolean baseIsA = base == viewA ; View other = baseIsA ? viewB : viewA ; edge . a_to_b . T . scale ( scale ) ; Se3_F64 otherToBase = baseIsA ? edge . a_to_b . invert ( null ) : edge . a_to_b . copy ( ) ; otherToBase . concat ( base . viewToWorld , other . viewToWorld ) ; for ( int i = 0 ; i < edge . stereoTriangulations . size ( ) ; i ++ ) { Feature3D edge3D = edge . stereoTriangulations . get ( i ) ; int indexSrc = edge3D . obsIdx . get ( 0 ) ; int indexDst = edge3D . obsIdx . get ( 1 ) ; Feature3D world3D = baseIsA ? viewA . features3D [ indexSrc ] : viewB . features3D [ indexDst ] ; edge3D . worldPt . scale ( scale ) ; if ( baseIsA ) { viewA . viewToWorld . transform ( edge3D . worldPt , edge3D . worldPt ) ; } else { edge . a_to_b . transform ( edge3D . worldPt , edge3D . worldPt ) ; viewB . viewToWorld . transform ( edge3D . worldPt , edge3D . worldPt ) ; } if ( world3D != null ) { if ( ! world3D . views . contains ( other ) ) { world3D . views . add ( other ) ; world3D . obsIdx . add ( baseIsA ? indexDst : indexSrc ) ; } if ( world3D . triangulationAngle >= edge3D . triangulationAngle ) { continue ; } world3D . worldPt . set ( edge3D . worldPt ) ; world3D . triangulationAngle = edge3D . triangulationAngle ; other . features3D [ baseIsA ? indexDst : indexSrc ] = edge3D ; } else { graph . features3D . add ( edge3D ) ; viewA . features3D [ indexSrc ] = edge3D ; viewB . features3D [ indexDst ] = edge3D ; } } edge . stereoTriangulations = new ArrayList < > ( ) ; } | Adds features which were triangulated using the stereo pair after the scale factor has been determined . Don t mark the other view as being processed . It s 3D pose will be estimated later on using PNP with the new features and features determined later on |
27,609 | static double determineScale ( View base , Motion edge ) throws Exception { View viewA = edge . viewSrc ; View viewB = edge . viewDst ; boolean baseIsA = base == viewA ; Point3D_F64 worldInBase3D = new Point3D_F64 ( ) ; Point3D_F64 localInBase3D = new Point3D_F64 ( ) ; GrowQueue_F64 scales = new GrowQueue_F64 ( ) ; for ( int i = 0 ; i < edge . stereoTriangulations . size ( ) ; i ++ ) { Feature3D edge3D = edge . stereoTriangulations . get ( i ) ; int indexSrc = edge3D . obsIdx . get ( 0 ) ; int indexDst = edge3D . obsIdx . get ( 1 ) ; Feature3D world3D = baseIsA ? viewA . features3D [ indexSrc ] : viewB . features3D [ indexDst ] ; if ( world3D == null ) continue ; SePointOps_F64 . transformReverse ( base . viewToWorld , world3D . worldPt , worldInBase3D ) ; if ( ! baseIsA ) { SePointOps_F64 . transform ( edge . a_to_b , edge3D . worldPt , localInBase3D ) ; } else { localInBase3D . set ( edge3D . worldPt ) ; } scales . add ( worldInBase3D . z / localInBase3D . z ) ; } if ( scales . size < 20 ) { throw new Exception ( "Not enough matches with known points" ) ; } scales . sort ( ) ; return scales . getFraction ( 0.5 ) ; } | Determine scale factor difference between edge triangulation and world |
27,610 | private void estimateAllFeatures ( View seedA , View seedB ) { List < View > open = new ArrayList < > ( ) ; addUnvistedToStack ( seedA , open ) ; addUnvistedToStack ( seedB , open ) ; while ( ! open . isEmpty ( ) ) { if ( stopRequested ) return ; if ( verbose != null ) verbose . println ( "### open.size=" + open . size ( ) ) ; int bestCount = countFeaturesWith3D ( open . get ( 0 ) ) ; int bestIndex = 0 ; for ( int i = 1 ; i < open . size ( ) ; i ++ ) { int count = countFeaturesWith3D ( open . get ( i ) ) ; if ( count > bestCount ) { bestCount = count ; bestIndex = i ; } } View v = open . remove ( bestIndex ) ; if ( verbose != null ) verbose . println ( " processing view=" + v . index + " | 3D Features=" + bestCount ) ; if ( ! determinePose ( v ) ) { throw new RuntimeException ( "Crap handle this" ) ; } else { addTriangulatedFeaturesForAllEdges ( v ) ; triangulateNoLocation ( v ) ; viewsAdded . add ( v ) ; addUnvistedToStack ( v , open ) ; } } } | Perform a breath first search to find the structure of all the remaining camrea views |
27,611 | int countFeaturesWith3D ( View v ) { int count = 0 ; for ( int i = 0 ; i < v . connections . size ( ) ; i ++ ) { Motion m = v . connections . get ( i ) ; boolean isSrc = m . viewSrc == v ; for ( int j = 0 ; j < m . associated . size ( ) ; j ++ ) { AssociatedIndex a = m . associated . get ( j ) ; if ( isSrc ) { count += m . viewDst . features3D [ a . dst ] != null ? 1 : 0 ; } else { count += m . viewSrc . features3D [ a . src ] != null ? 1 : 0 ; } } } return count ; } | Count how many 3D features are in view . |
27,612 | boolean determinePose ( View target ) { List < Point2D3D > list = new ArrayList < > ( ) ; List < Feature3D > features = new ArrayList < > ( ) ; GrowQueue_I32 featureIndexes = new GrowQueue_I32 ( ) ; for ( Motion c : target . connections ) { boolean isSrc = c . viewSrc == target ; View other = c . destination ( target ) ; if ( other . state != ViewState . PROCESSED ) continue ; for ( int i = 0 ; i < c . associated . size ( ) ; i ++ ) { AssociatedIndex a = c . associated . get ( i ) ; Feature3D f = other . features3D [ isSrc ? a . dst : a . src ] ; if ( f == null || f . mark == target . index ) continue ; f . mark = target . index ; features . add ( f ) ; featureIndexes . add ( isSrc ? a . src : a . dst ) ; Point2D_F64 norm = target . observationNorm . get ( isSrc ? a . src : a . dst ) ; Point2D3D p = new Point2D3D ( ) ; p . location . set ( f . worldPt ) ; p . observation . set ( norm ) ; list . add ( p ) ; } } ransacPnP . setIntrinsic ( 0 , target . camera . pinhole ) ; if ( list . size ( ) < 20 || ! ransacPnP . process ( list ) ) { if ( verbose != null ) verbose . println ( " View=" + target . index + " RANSAC failed. list.size=" + list . size ( ) ) ; return false ; } target . state = ViewState . PROCESSED ; int N = ransacPnP . getMatchSet ( ) . size ( ) ; if ( verbose != null ) verbose . println ( " View=" + target . index + " PNP RANSAC " + N + "/" + list . size ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) { int which = ransacPnP . getInputIndex ( i ) ; Feature3D f = features . get ( which ) ; if ( f . views . contains ( target ) ) continue ; f . views . add ( target ) ; f . obsIdx . add ( featureIndexes . get ( which ) ) ; target . features3D [ featureIndexes . get ( which ) ] = f ; if ( f . views . size ( ) != f . obsIdx . size ) throw new RuntimeException ( "BUG!" ) ; } Se3_F64 worldToView = ransacPnP . getModelParameters ( ) ; target . viewToWorld . set ( worldToView . invert ( null ) ) ; return true ; } | Uses the previously found motion between the two cameras to estimate the scale and 3D point of common features . If a feature already has a known 3D point that is not modified . Scale is found by computing the 3D coordinate of all points with a 3D point again then dividing the two distances . New features are also triangulated and have their location s update using this scale . |
27,613 | private void triangulateNoLocation ( View target ) { Se3_F64 otherToTarget = new Se3_F64 ( ) ; Se3_F64 worldToTarget = target . viewToWorld . invert ( null ) ; for ( Motion c : target . connections ) { boolean isSrc = c . viewSrc == target ; View other = c . destination ( target ) ; if ( other . state != ViewState . PROCESSED ) continue ; other . viewToWorld . concat ( worldToTarget , otherToTarget ) ; triangulationError . configure ( target . camera . pinhole , other . camera . pinhole ) ; for ( int i = 0 ; i < c . associated . size ( ) ; i ++ ) { AssociatedIndex a = c . associated . get ( i ) ; int indexTarget = isSrc ? a . src : a . dst ; int indexOther = isSrc ? a . dst : a . src ; if ( target . features3D [ indexTarget ] != null || other . features3D [ indexOther ] != null ) continue ; Point2D_F64 normOther = other . observationNorm . get ( indexOther ) ; Point2D_F64 normTarget = target . observationNorm . get ( indexTarget ) ; double angle = triangulationAngle ( normOther , normTarget , otherToTarget ) ; if ( angle < TRIANGULATE_MIN_ANGLE ) continue ; Feature3D f = new Feature3D ( ) ; if ( ! triangulate . triangulate ( normOther , normTarget , otherToTarget , f . worldPt ) ) continue ; if ( f . worldPt . z <= 0 ) continue ; double error = triangulationError . process ( normOther , normTarget , otherToTarget , f . worldPt ) ; if ( error > maxPixelError * maxPixelError ) continue ; other . viewToWorld . transform ( f . worldPt , f . worldPt ) ; f . views . add ( target ) ; f . views . add ( other ) ; f . obsIdx . add ( indexTarget ) ; f . obsIdx . add ( indexOther ) ; graph . features3D . add ( f ) ; target . features3D [ indexTarget ] = f ; other . features3D [ indexOther ] = f ; } } } | Go through all connections to the view and triangulate all features which have not been triangulated already |
27,614 | double triangulationAngle ( Point2D_F64 normA , Point2D_F64 normB , Se3_F64 a_to_b ) { arrowA . set ( normA . x , normA . y , 1 ) ; arrowB . set ( normB . x , normB . y , 1 ) ; GeometryMath_F64 . mult ( a_to_b . R , arrowA , arrowA ) ; return UtilVector3D_F64 . acute ( arrowA , arrowB ) ; } | Computes the acture angle between two vectors . Larger this angle is the better the triangulation of the features 3D location is in general |
27,615 | void addUnvistedToStack ( View viewed , List < View > open ) { for ( int i = 0 ; i < viewed . connections . size ( ) ; i ++ ) { View other = viewed . connections . get ( i ) . destination ( viewed ) ; if ( other . state == ViewState . UNPROCESSED ) { other . state = ViewState . PENDING ; open . add ( other ) ; if ( verbose != null ) verbose . println ( " adding to open " + viewed . index + "->" + other . index ) ; } } } | Looks to see which connections have yet to be visited and adds them to the open list |
27,616 | void defineCoordinateSystem ( View viewA , Motion motion ) { View viewB = motion . destination ( viewA ) ; viewA . viewToWorld . reset ( ) ; viewB . viewToWorld . set ( motion . motionSrcToDst ( viewB ) ) ; double scale = viewB . viewToWorld . T . norm ( ) ; viewB . viewToWorld . T . scale ( 1.0 / scale ) ; viewsAdded . add ( viewA ) ; viewsAdded . add ( viewB ) ; viewA . state = ViewState . PROCESSED ; viewB . state = ViewState . PROCESSED ; boolean originIsDst = viewA == motion . viewDst ; for ( int i = 0 ; i < motion . stereoTriangulations . size ( ) ; i ++ ) { Feature3D f = motion . stereoTriangulations . get ( i ) ; if ( f . obsIdx . size != 2 ) throw new RuntimeException ( "BUG" ) ; int indexSrc = f . obsIdx . get ( 0 ) ; int indexDst = f . obsIdx . get ( 1 ) ; motion . viewSrc . features3D [ indexSrc ] = f ; motion . viewDst . features3D [ indexDst ] = f ; if ( originIsDst ) { SePointOps_F64 . transform ( motion . a_to_b , f . worldPt , f . worldPt ) ; } f . worldPt . scale ( 1.0 / scale ) ; graph . features3D . add ( f ) ; } motion . stereoTriangulations = new ArrayList < > ( ) ; addTriangulatedFeaturesForAllEdges ( viewA ) ; addTriangulatedFeaturesForAllEdges ( viewB ) ; if ( verbose != null ) { verbose . println ( "root = " + viewA . index ) ; verbose . println ( "other = " + viewB . index ) ; verbose . println ( "-------------" ) ; } } | Sets the origin and scale of the coordinate system |
27,617 | View selectOriginNode ( ) { double bestScore = 0 ; View best = null ; if ( verbose != null ) verbose . println ( "selectOriginNode" ) ; for ( int i = 0 ; i < graph . nodes . size ( ) ; i ++ ) { double score = scoreNodeAsOrigin ( graph . nodes . get ( i ) ) ; if ( score > bestScore ) { bestScore = score ; best = graph . nodes . get ( i ) ; } if ( verbose != null ) verbose . printf ( " [%2d] score = %s\n" , i , score ) ; } if ( verbose != null && best != null ) verbose . println ( " selected = " + best . index ) ; return best ; } | Select the view which will be coordinate system s origin . This should be a well connected node which have favorable geometry to the other views it s connected to . |
27,618 | Motion selectCoordinateBase ( View view ) { double bestScore = 0 ; Motion best = null ; if ( verbose != null ) verbose . println ( "selectCoordinateBase" ) ; for ( int i = 0 ; i < view . connections . size ( ) ; i ++ ) { Motion e = view . connections . get ( i ) ; double s = e . scoreTriangulation ( ) ; if ( verbose != null ) verbose . printf ( " [%2d] score = %s\n" , i , s ) ; if ( s > bestScore ) { bestScore = s ; best = e ; } } return best ; } | Select motion which will define the coordinate system . |
27,619 | void triangulateStereoEdges ( Motion edge ) { View viewA = edge . viewSrc ; View viewB = edge . viewDst ; triangulationError . configure ( viewA . camera . pinhole , viewB . camera . pinhole ) ; for ( int i = 0 ; i < edge . associated . size ( ) ; i ++ ) { AssociatedIndex f = edge . associated . get ( i ) ; Point2D_F64 normA = viewA . observationNorm . get ( f . src ) ; Point2D_F64 normB = viewB . observationNorm . get ( f . dst ) ; double angle = triangulationAngle ( normA , normB , edge . a_to_b ) ; if ( angle < TRIANGULATE_MIN_ANGLE ) continue ; Feature3D feature3D = new Feature3D ( ) ; if ( ! triangulate . triangulate ( normA , normB , edge . a_to_b , feature3D . worldPt ) ) { continue ; } if ( feature3D . worldPt . z <= 0 ) continue ; double error = triangulationError . process ( normA , normB , edge . a_to_b , feature3D . worldPt ) ; if ( error > maxPixelError * maxPixelError ) continue ; feature3D . views . add ( viewA ) ; feature3D . views . add ( viewB ) ; feature3D . obsIdx . add ( f . src ) ; feature3D . obsIdx . add ( f . dst ) ; feature3D . triangulationAngle = angle ; edge . stereoTriangulations . add ( feature3D ) ; } } | An edge has been declared as defining a good stereo pair . All associated feature will now be triangulated . It is assumed that there is no global coordinate system at this point . |
27,620 | public static CameraPinhole approximatePinhole ( Point2Transform2_F64 p2n , int width , int height ) { Point2D_F64 na = new Point2D_F64 ( ) ; Point2D_F64 nb = new Point2D_F64 ( ) ; p2n . compute ( 0 , height / 2 , na ) ; p2n . compute ( width - 1 , height / 2 , nb ) ; double abdot = na . x * nb . x + na . y * nb . y + 1 ; double normA = Math . sqrt ( na . x * na . x + na . y * na . y + 1 ) ; double normB = Math . sqrt ( nb . x * nb . x + nb . y * nb . y + 1 ) ; double hfov = Math . acos ( abdot / ( normA * normB ) ) ; p2n . compute ( width / 2 , 0 , na ) ; p2n . compute ( width / 2 , height - 1 , nb ) ; abdot = na . x * nb . x + na . y * nb . y + 1 ; normA = Math . sqrt ( na . x * na . x + na . y * na . y + 1 ) ; normB = Math . sqrt ( nb . x * nb . x + nb . y * nb . y + 1 ) ; double vfov = Math . acos ( abdot / ( normA * normB ) ) ; return createIntrinsic ( width , height , UtilAngle . degree ( hfov ) , UtilAngle . degree ( vfov ) ) ; } | Approximates a pinhole camera using the distoriton model |
27,621 | public static CameraPinhole createIntrinsic ( int width , int height , double hfov , double vfov ) { CameraPinhole intrinsic = new CameraPinhole ( ) ; intrinsic . width = width ; intrinsic . height = height ; intrinsic . cx = width / 2 ; intrinsic . cy = height / 2 ; intrinsic . fx = intrinsic . cx / Math . tan ( UtilAngle . degreeToRadian ( hfov / 2.0 ) ) ; intrinsic . fy = intrinsic . cy / Math . tan ( UtilAngle . degreeToRadian ( vfov / 2.0 ) ) ; return intrinsic ; } | Creates a set of intrinsic parameters without distortion for a camera with the specified characteristics |
27,622 | public static CameraPinholeBrown createIntrinsic ( int width , int height , double hfov ) { CameraPinholeBrown intrinsic = new CameraPinholeBrown ( ) ; intrinsic . width = width ; intrinsic . height = height ; intrinsic . cx = width / 2 ; intrinsic . cy = height / 2 ; intrinsic . fx = intrinsic . cx / Math . tan ( UtilAngle . degreeToRadian ( hfov / 2.0 ) ) ; intrinsic . fy = intrinsic . fx ; return intrinsic ; } | Creates a set of intrinsic parameters without distortion for a camera with the specified characteristics . The focal length is assumed to be the same for x and y . |
27,623 | public static void scaleIntrinsic ( CameraPinhole param , double scale ) { param . width = ( int ) ( param . width * scale ) ; param . height = ( int ) ( param . height * scale ) ; param . cx *= scale ; param . cy *= scale ; param . fx *= scale ; param . fy *= scale ; param . skew *= scale ; } | Multiplies each element of the intrinsic parameters by the provided scale factor . Useful if the image has been rescaled . |
27,624 | public static void invertPinhole ( DMatrix3x3 K , DMatrix3x3 Kinv ) { double fx = K . a11 ; double skew = K . a12 ; double cx = K . a13 ; double fy = K . a22 ; double cy = K . a23 ; Kinv . a11 = 1.0 / fx ; Kinv . a12 = - skew / ( fx * fy ) ; Kinv . a13 = ( skew * cy - cx * fy ) / ( fx * fy ) ; Kinv . a22 = 1.0 / fy ; Kinv . a23 = - cy / fy ; Kinv . a33 = 1 ; } | Analytic matrix inversion to 3x3 camera calibration matrix . Input and output can be the same matrix . Zeros are not set . |
27,625 | public static Point2D_F64 renderPixel ( Se3_F64 worldToCamera , DMatrixRMaj K , Point3D_F64 X ) { return ImplPerspectiveOps_F64 . renderPixel ( worldToCamera , K , X ) ; } | Renders a point in world coordinates into the image plane in pixels or normalized image coordinates . |
27,626 | public static Point2D_F64 renderPixel ( CameraPinhole intrinsic , Point3D_F64 X ) { Point2D_F64 norm = new Point2D_F64 ( X . x / X . z , X . y / X . z ) ; return convertNormToPixel ( intrinsic , norm , norm ) ; } | Renders a point in camera coordinates into the image plane in pixels . |
27,627 | public static Point2D_F64 renderPixel ( DMatrixRMaj worldToCamera , Point3D_F64 X ) { return renderPixel ( worldToCamera , X , ( Point2D_F64 ) null ) ; } | Computes the image coordinate of a point given its 3D location and the camera matrix . |
27,628 | public static double crossRatios ( Point3D_F64 a0 , Point3D_F64 a1 , Point3D_F64 a2 , Point3D_F64 a3 ) { double d01 = a0 . distance ( a1 ) ; double d23 = a2 . distance ( a3 ) ; double d02 = a0 . distance ( a2 ) ; double d13 = a1 . distance ( a3 ) ; return ( d01 * d23 ) / ( d02 * d13 ) ; } | Computes the cross - ratio between 4 points . This is an invariant under projective geometry . |
27,629 | public static void extractColumn ( DMatrixRMaj P , int col , GeoTuple3D_F64 a ) { a . x = P . unsafe_get ( 0 , col ) ; a . y = P . unsafe_get ( 1 , col ) ; a . z = P . unsafe_get ( 2 , col ) ; } | Extracts a column from the camera matrix and puts it into the geometric 3 - tuple . |
27,630 | public static void insertColumn ( DMatrixRMaj P , int col , GeoTuple3D_F64 a ) { P . unsafe_set ( 0 , col , a . x ) ; P . unsafe_set ( 1 , col , a . y ) ; P . unsafe_set ( 2 , col , a . z ) ; } | Inserts 3 - tuple into the camera matrix s columns |
27,631 | public void decompose ( DMatrixRMaj E ) { if ( svd . inputModified ( ) ) { E_copy . set ( E ) ; E = E_copy ; } if ( ! svd . decompose ( E ) ) throw new RuntimeException ( "Svd some how failed" ) ; U = svd . getU ( U , false ) ; V = svd . getV ( V , false ) ; S = svd . getW ( S ) ; SingularOps_DDRM . descendingOrder ( U , false , S , V , false ) ; decompose ( U , S , V ) ; } | Computes the decomposition from an essential matrix . |
27,632 | private void extractTransform ( DMatrixRMaj U , DMatrixRMaj V , DMatrixRMaj S , Se3_F64 se , boolean optionA , boolean optionB ) { DMatrixRMaj R = se . getR ( ) ; Vector3D_F64 T = se . getT ( ) ; if ( optionA ) CommonOps_DDRM . mult ( U , Rz , temp ) ; else CommonOps_DDRM . multTransB ( U , Rz , temp ) ; CommonOps_DDRM . multTransB ( temp , V , R ) ; if ( optionB ) CommonOps_DDRM . multTransB ( U , Rz , temp ) ; else CommonOps_DDRM . mult ( U , Rz , temp ) ; CommonOps_DDRM . mult ( temp , S , temp2 ) ; CommonOps_DDRM . multTransB ( temp2 , U , temp ) ; T . x = temp . get ( 2 , 1 ) ; T . y = temp . get ( 0 , 2 ) ; T . z = temp . get ( 1 , 0 ) ; } | There are four possible reconstructions from an essential matrix . This function will compute different permutations depending on optionA and optionB being true or false . |
27,633 | public boolean process ( List < AssociatedPair > points ) { if ( points . size ( ) < estimateHomography . getMinimumPoints ( ) ) throw new IllegalArgumentException ( "At least " + estimateHomography . getMinimumPoints ( ) + " must be provided" ) ; zeroMeanWorldPoints ( points ) ; points = pointsAdj . toList ( ) ; if ( ! estimateHomography . process ( points , H ) ) return false ; CommonOps_DDRM . divide ( H , H . get ( 2 , 2 ) ) ; J . a11 = H . unsafe_get ( 0 , 0 ) - H . unsafe_get ( 2 , 0 ) * H . unsafe_get ( 0 , 2 ) ; J . a12 = H . unsafe_get ( 0 , 1 ) - H . unsafe_get ( 2 , 1 ) * H . unsafe_get ( 0 , 2 ) ; J . a21 = H . unsafe_get ( 1 , 0 ) - H . unsafe_get ( 2 , 0 ) * H . unsafe_get ( 1 , 2 ) ; J . a22 = H . unsafe_get ( 1 , 1 ) - H . unsafe_get ( 2 , 1 ) * H . unsafe_get ( 1 , 2 ) ; v1 = H . unsafe_get ( 0 , 2 ) ; v2 = H . unsafe_get ( 1 , 2 ) ; IPPE ( pose0 . R , pose1 . R ) ; estimateTranslation ( pose0 . R , points , pose0 . T ) ; estimateTranslation ( pose1 . R , points , pose1 . T ) ; error0 = computeError ( points , pose0 ) ; error1 = computeError ( points , pose1 ) ; if ( error0 > error1 ) { double e = error0 ; error0 = error1 ; error1 = e ; Se3_F64 s = pose0 ; pose0 = pose1 ; pose1 = s ; } center3 . set ( - center . x , - center . y , 0 ) ; GeometryMath_F64 . addMult ( pose0 . T , pose0 . R , center3 , pose0 . T ) ; GeometryMath_F64 . addMult ( pose1 . T , pose1 . R , center3 , pose1 . T ) ; return true ; } | Estimates the transform from world coordinate system to camera given known points and observations . For each observation p1 = World 3D location . z = 0 is implicit . p2 = Observed location of points in image in normalized image coordinates |
27,634 | double computeError ( List < AssociatedPair > points , Se3_F64 worldToCamera ) { double error = 0 ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { AssociatedPair pair = points . get ( i ) ; tmpP . set ( pair . p1 . x , pair . p1 . y , 0 ) ; SePointOps_F64 . transform ( worldToCamera , tmpP , tmpP ) ; error += pair . p2 . distance2 ( tmpP . x / tmpP . z , tmpP . y / tmpP . z ) ; } return Math . sqrt ( error / points . size ( ) ) ; } | Computes reprojection error to select best model |
27,635 | private void zeroMeanWorldPoints ( List < AssociatedPair > points ) { center . set ( 0 , 0 ) ; pointsAdj . reset ( ) ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { AssociatedPair pair = points . get ( i ) ; Point2D_F64 p = pair . p1 ; pointsAdj . grow ( ) . p2 . set ( pair . p2 ) ; center . x += p . x ; center . y += p . y ; } center . x /= points . size ( ) ; center . y /= points . size ( ) ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { Point2D_F64 p = points . get ( i ) . p1 ; pointsAdj . get ( i ) . p1 . set ( p . x - center . x , p . y - center . y ) ; } } | Ensure zero mean for world location . Creates a local copy of the input |
27,636 | void estimateTranslation ( DMatrixRMaj R , List < AssociatedPair > points , Vector3D_F64 T ) { final int N = points . size ( ) ; W . reshape ( N * 2 , 3 ) ; y . reshape ( N * 2 , 1 ) ; Wty . reshape ( 3 , 1 ) ; DMatrix3x3 Rtmp = new DMatrix3x3 ( ) ; ConvertDMatrixStruct . convert ( R , Rtmp ) ; int indexY = 0 , indexW = 0 ; for ( int i = 0 ; i < N ; i ++ ) { AssociatedPair p = points . get ( i ) ; double u1 = Rtmp . a11 * p . p1 . x + Rtmp . a12 * p . p1 . y ; double u2 = Rtmp . a21 * p . p1 . x + Rtmp . a22 * p . p1 . y ; double u3 = Rtmp . a31 * p . p1 . x + Rtmp . a32 * p . p1 . y ; W . data [ indexW ++ ] = 1 ; W . data [ indexW ++ ] = 0 ; W . data [ indexW ++ ] = - p . p2 . x ; W . data [ indexW ++ ] = 0 ; W . data [ indexW ++ ] = 1 ; W . data [ indexW ++ ] = - p . p2 . y ; y . data [ indexY ++ ] = p . p2 . x * u3 - u1 ; y . data [ indexY ++ ] = p . p2 . y * u3 - u2 ; } CommonOps_DDRM . multTransA ( W , W , WW ) ; CommonOps_DDRM . invert ( WW ) ; CommonOps_DDRM . multTransA ( W , y , Wty ) ; W . reshape ( 3 , 1 ) ; CommonOps_DDRM . mult ( WW , Wty , W ) ; T . x = W . data [ 0 ] ; T . y = W . data [ 1 ] ; T . z = W . data [ 2 ] ; } | Estimate s the translation given the previously found rotation |
27,637 | protected void IPPE ( DMatrixRMaj R1 , DMatrixRMaj R2 ) { double norm_v = Math . sqrt ( v1 * v1 + v2 * v2 ) ; if ( norm_v <= UtilEjml . EPS ) { CommonOps_DDRM . setIdentity ( R_v ) ; } else { compute_Rv ( ) ; } compute_B ( B , R_v , v1 , v2 ) ; CommonOps_DDF2 . invert ( B , B ) ; CommonOps_DDF2 . mult ( B , J , A ) ; double gamma = largestSingularValue2x2 ( A ) ; CommonOps_DDF2 . scale ( 1.0 / gamma , A , R22 ) ; CommonOps_DDF2 . setIdentity ( B ) ; CommonOps_DDF2 . multAddTransA ( - 1 , R22 , R22 , B ) ; double b1 = Math . sqrt ( B . a11 ) ; double b2 = Math . signum ( B . a12 ) * Math . sqrt ( B . a22 ) ; l0 . set ( R22 . a11 , R22 . a21 , b1 ) ; l1 . set ( R22 . a12 , R22 . a22 , b2 ) ; ca . cross ( l0 , l1 ) ; constructR ( R1 , R_v , R22 , b1 , b2 , ca , 1 , tmp ) ; constructR ( R2 , R_v , R22 , b1 , b2 , ca , - 1 , tmp ) ; } | Solves the IPPE problem |
27,638 | public void learnAndSave ( ) { System . out . println ( "======== Learning Classifier" ) ; AssignCluster < double [ ] > assignment ; if ( new File ( CLUSTER_FILE_NAME ) . exists ( ) ) { assignment = UtilIO . load ( CLUSTER_FILE_NAME ) ; } else { System . out . println ( " Computing clusters" ) ; assignment = computeClusters ( ) ; } FeatureToWordHistogram_F64 featuresToHistogram = new FeatureToWordHistogram_F64 ( assignment , HISTOGRAM_HARD ) ; List < HistogramScene > memory ; if ( ! new File ( HISTOGRAM_FILE_NAME ) . exists ( ) ) { System . out . println ( " computing histograms" ) ; memory = computeHistograms ( featuresToHistogram ) ; UtilIO . save ( memory , HISTOGRAM_FILE_NAME ) ; } } | Process all the data in the training data set to learn the classifications . See code for details . |
27,639 | private AssignCluster < double [ ] > computeClusters ( ) { System . out . println ( "Image Features" ) ; List < TupleDesc_F64 > features = new ArrayList < > ( ) ; for ( String scene : train . keySet ( ) ) { List < String > imagePaths = train . get ( scene ) ; System . out . println ( " " + scene ) ; for ( String path : imagePaths ) { GrayU8 image = UtilImageIO . loadImage ( path , GrayU8 . class ) ; describeImage . process ( image ) ; for ( TupleDesc_F64 d : describeImage . getDescriptions ( ) ) { features . add ( d . copy ( ) ) ; } } } for ( int i = 0 ; i < features . size ( ) ; i ++ ) { cluster . addReference ( features . get ( i ) ) ; } System . out . println ( "Clustering" ) ; cluster . process ( NUMBER_OF_WORDS ) ; UtilIO . save ( cluster . getAssignment ( ) , CLUSTER_FILE_NAME ) ; return cluster . getAssignment ( ) ; } | Extract dense features across the training set . Then clusters are found within those features . |
27,640 | public void grow ( ) { if ( tailBlockSize >= blockLength ) { tailBlockSize = 0 ; blocks . grow ( ) ; } BlockIndexLength s = sets . grow ( ) ; s . block = blocks . size - 1 ; s . start = tailBlockSize ; s . length = 0 ; tail = s ; } | Adds a new point set to the end . |
27,641 | public void removeTail ( ) { while ( blocks . size - 1 != tail . block ) blocks . removeTail ( ) ; tailBlockSize = tail . start ; sets . removeTail ( ) ; tail = sets . size > 0 ? sets . get ( sets . size - 1 ) : null ; } | Removes the current point set from the end |
27,642 | public void addPointToTail ( int x , int y ) { int index = tail . start + tail . length * 2 ; int block [ ] ; int blockIndex = tail . block + index / blockLength ; if ( blockIndex == blocks . size ) { tailBlockSize = 0 ; block = blocks . grow ( ) ; } else { block = blocks . get ( blockIndex ) ; } tailBlockSize += 2 ; index %= blockLength ; block [ index ] = x ; block [ index + 1 ] = y ; tail . length += 1 ; } | Adds a point to the tail point set |
27,643 | public void getSet ( int which , FastQueue < Point2D_I32 > list ) { list . reset ( ) ; BlockIndexLength set = sets . get ( which ) ; for ( int i = 0 ; i < set . length ; i ++ ) { int index = set . start + i * 2 ; int blockIndex = set . block + index / blockLength ; index %= blockLength ; int block [ ] = blocks . get ( blockIndex ) ; list . grow ( ) . set ( block [ index ] , block [ index + 1 ] ) ; } } | Copies all the points in the set into the specified list |
27,644 | public void writeOverSet ( int which , List < Point2D_I32 > points ) { BlockIndexLength set = sets . get ( which ) ; if ( set . length != points . size ( ) ) throw new IllegalArgumentException ( "points and set don't have the same length" ) ; for ( int i = 0 ; i < set . length ; i ++ ) { int index = set . start + i * 2 ; int blockIndex = set . block + index / blockLength ; index %= blockLength ; Point2D_I32 p = points . get ( i ) ; int block [ ] = blocks . get ( blockIndex ) ; block [ index ] = p . x ; block [ index + 1 ] = p . y ; } } | Overwrites the points in the set with the list of points . |
27,645 | public void viewUpdated ( ) { BufferedImage active = null ; if ( controls . selectedView == 0 ) { active = original ; } else if ( controls . selectedView == 1 ) { synchronized ( lockProcessing ) { VisualizeBinaryData . renderBinary ( detector . getBinary ( ) , false , work ) ; } active = work ; work . setRGB ( 0 , 0 , work . getRGB ( 0 , 0 ) ) ; } else { Graphics2D g2 = work . createGraphics ( ) ; g2 . setColor ( Color . BLACK ) ; g2 . fillRect ( 0 , 0 , work . getWidth ( ) , work . getHeight ( ) ) ; active = work ; } guiImage . setBufferedImage ( active ) ; guiImage . setScale ( controls . zoom ) ; guiImage . repaint ( ) ; } | Called when how the data is visualized has changed |
27,646 | void disconnectSingleConnections ( ) { List < SquareNode > open = new ArrayList < > ( ) ; List < SquareNode > open2 = new ArrayList < > ( ) ; for ( int i = 0 ; i < nodes . size ( ) ; i ++ ) { SquareNode n = nodes . get ( i ) ; checkDisconnectSingleEdge ( open , n ) ; } while ( ! open . isEmpty ( ) ) { for ( int i = 0 ; i < open . size ( ) ; i ++ ) { SquareNode n = open . get ( i ) ; checkDisconnectSingleEdge ( open2 , n ) ; open . clear ( ) ; List < SquareNode > tmp = open ; open = open2 ; open2 = tmp ; } } } | Nodes that have only a single connection to one other node are disconnected since they are likely to be noise . This is done recursively |
27,647 | boolean areMiddlePointsClose ( Point2D_F64 p0 , Point2D_F64 p1 , Point2D_F64 p2 , Point2D_F64 p3 ) { UtilLine2D_F64 . convert ( p0 , p3 , line ) ; double tol1 = p0 . distance ( p1 ) * distanceTol ; if ( Distance2D_F64 . distance ( line , p1 ) > tol1 ) return false ; double tol2 = p2 . distance ( p3 ) * distanceTol ; if ( Distance2D_F64 . distance ( lineB , p2 ) > tol2 ) return false ; UtilLine2D_F64 . convert ( p0 , p1 , line ) ; if ( Distance2D_F64 . distance ( line , p2 ) > tol2 ) return false ; UtilLine2D_F64 . convert ( p3 , p2 , line ) ; if ( Distance2D_F64 . distance ( line , p1 ) > tol1 ) return false ; return true ; } | Returns true if point p1 and p2 are close to the line defined by points p0 and p3 . |
27,648 | public boolean process ( T left , T right ) { this . inputLeft = left ; this . inputRight = right ; tick ++ ; trackerLeft . process ( left ) ; trackerRight . process ( right ) ; if ( first ) { addNewTracks ( ) ; first = false ; } else { mutualTrackDrop ( ) ; selectCandidateTracks ( ) ; boolean failed = ! estimateMotion ( ) ; dropUnusedTracks ( ) ; if ( failed ) return false ; int N = matcher . getMatchSet ( ) . size ( ) ; if ( modelRefiner != null ) refineMotionEstimate ( ) ; if ( thresholdAdd <= 0 || N < thresholdAdd ) { changePoseToReference ( ) ; addNewTracks ( ) ; } } return true ; } | Updates motion estimate using the stereo pair . |
27,649 | private void refineMotionEstimate ( ) { List < Stereo2D3D > data = new ArrayList < > ( ) ; int N = matcher . getMatchSet ( ) . size ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int index = matcher . getInputIndex ( i ) ; PointTrack l = candidates . get ( index ) ; LeftTrackInfo info = l . getCookie ( ) ; PointTrack r = info . right ; Stereo2D3D stereo = info . location ; leftImageToNorm . compute ( l . x , l . y , info . location . leftObs ) ; rightImageToNorm . compute ( r . x , r . y , info . location . rightObs ) ; data . add ( stereo ) ; } Se3_F64 keyToCurr = currToKey . invert ( null ) ; Se3_F64 found = new Se3_F64 ( ) ; if ( modelRefiner . fitModel ( data , keyToCurr , found ) ) { found . invert ( currToKey ) ; } } | Non - linear refinement of motion estimate |
27,650 | private boolean estimateMotion ( ) { List < Stereo2D3D > data = new ArrayList < > ( ) ; for ( PointTrack l : candidates ) { LeftTrackInfo info = l . getCookie ( ) ; PointTrack r = info . right ; Stereo2D3D stereo = info . location ; leftImageToNorm . compute ( l . x , l . y , info . location . leftObs ) ; rightImageToNorm . compute ( r . x , r . y , info . location . rightObs ) ; data . add ( stereo ) ; } if ( ! matcher . process ( data ) ) return false ; Se3_F64 keyToCurr = matcher . getModelParameters ( ) ; keyToCurr . invert ( currToKey ) ; int N = matcher . getMatchSet ( ) . size ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int index = matcher . getInputIndex ( i ) ; LeftTrackInfo info = candidates . get ( index ) . getCookie ( ) ; info . lastInlier = tick ; } return true ; } | Given the set of active tracks estimate the cameras motion robustly |
27,651 | private void mutualTrackDrop ( ) { for ( PointTrack t : trackerLeft . getDroppedTracks ( null ) ) { LeftTrackInfo info = t . getCookie ( ) ; trackerRight . dropTrack ( info . right ) ; } for ( PointTrack t : trackerRight . getDroppedTracks ( null ) ) { RightTrackInfo info = t . getCookie ( ) ; trackerLeft . dropTrack ( info . left ) ; } } | If a track was dropped in one image make sure it was dropped in the other image |
27,652 | private void selectCandidateTracks ( ) { List < PointTrack > activeRight = trackerRight . getActiveTracks ( null ) ; for ( PointTrack t : activeRight ) { RightTrackInfo info = t . getCookie ( ) ; info . lastActiveList = tick ; } int mutualActive = 0 ; List < PointTrack > activeLeft = trackerLeft . getActiveTracks ( null ) ; candidates . clear ( ) ; for ( PointTrack left : activeLeft ) { LeftTrackInfo info = left . getCookie ( ) ; RightTrackInfo infoRight = info . right . getCookie ( ) ; if ( infoRight . lastActiveList != tick ) { continue ; } if ( stereoCheck . checkPixel ( left , info . right ) ) { info . lastConsistent = tick ; candidates . add ( left ) ; } mutualActive ++ ; } } | Searches for tracks which are active and meet the epipolar constraints |
27,653 | private void addNewTracks ( ) { trackerLeft . spawnTracks ( ) ; trackerRight . spawnTracks ( ) ; List < PointTrack > newLeft = trackerLeft . getNewTracks ( null ) ; List < PointTrack > newRight = trackerRight . getNewTracks ( null ) ; addNewToList ( inputLeft , newLeft , pointsLeft , descLeft ) ; addNewToList ( inputRight , newRight , pointsRight , descRight ) ; assocL2R . setSource ( pointsLeft , descLeft ) ; assocL2R . setDestination ( pointsRight , descRight ) ; assocL2R . associate ( ) ; FastQueue < AssociatedIndex > matches = assocL2R . getMatches ( ) ; Point3D_F64 cameraP3 = new Point3D_F64 ( ) ; for ( int i = 0 ; i < matches . size ; i ++ ) { AssociatedIndex m = matches . get ( i ) ; PointTrack trackL = newLeft . get ( m . src ) ; PointTrack trackR = newRight . get ( m . dst ) ; LeftTrackInfo infoLeft = trackL . getCookie ( ) ; if ( infoLeft == null ) trackL . cookie = infoLeft = new LeftTrackInfo ( ) ; RightTrackInfo infoRight = trackR . getCookie ( ) ; if ( infoRight == null ) trackR . cookie = infoRight = new RightTrackInfo ( ) ; Stereo2D3D p2d3d = infoLeft . location ; leftImageToNorm . compute ( trackL . x , trackL . y , p2d3d . leftObs ) ; rightImageToNorm . compute ( trackR . x , trackR . y , p2d3d . rightObs ) ; if ( triangulate . triangulate ( p2d3d . leftObs , p2d3d . rightObs , leftToRight , cameraP3 ) ) { SePointOps_F64 . transform ( currToKey , cameraP3 , p2d3d . location ) ; infoLeft . right = trackR ; infoLeft . lastConsistent = infoLeft . lastInlier = tick ; infoRight . left = trackL ; } else { trackerLeft . dropTrack ( trackL ) ; throw new RuntimeException ( "This special case needs to be handled!" ) ; } } GrowQueue_I32 unassignedRight = assocL2R . getUnassociatedDestination ( ) ; for ( int i = 0 ; i < unassignedRight . size ; i ++ ) { int index = unassignedRight . get ( i ) ; trackerRight . dropTrack ( newRight . get ( index ) ) ; } GrowQueue_I32 unassignedLeft = assocL2R . getUnassociatedSource ( ) ; for ( int i = 0 ; i < unassignedLeft . size ; i ++ ) { int index = unassignedLeft . get ( i ) ; trackerLeft . dropTrack ( newLeft . get ( index ) ) ; } } | Spawns tracks in each image and associates features together . |
27,654 | public void createImages ( ) { image = UtilImageIO . loadImage ( UtilIO . pathExample ( "standard/barbara.jpg" ) ) ; gray = ConvertBufferedImage . convertFromSingle ( image , null , GrayU8 . class ) ; derivX = GeneralizedImageOps . createSingleBand ( GrayS16 . class , gray . getWidth ( ) , gray . getHeight ( ) ) ; derivY = GeneralizedImageOps . createSingleBand ( GrayS16 . class , gray . getWidth ( ) , gray . getHeight ( ) ) ; GImageDerivativeOps . gradient ( DerivativeType . SOBEL , gray , derivX , derivY , BorderType . EXTENDED ) ; } | Load and generate images |
27,655 | public static void fillRectangle ( InterleavedS32 img , int value , int x0 , int y0 , int width , int height ) { int x1 = x0 + width ; int y1 = y0 + height ; if ( x0 < 0 ) x0 = 0 ; if ( x1 > img . width ) x1 = img . width ; if ( y0 < 0 ) y0 = 0 ; if ( y1 > img . height ) y1 = img . height ; int length = ( x1 - x0 ) * img . numBands ; for ( int y = y0 ; y < y1 ; y ++ ) { int index = img . startIndex + y * img . stride + x0 * img . numBands ; int indexEnd = index + length ; while ( index < indexEnd ) { img . data [ index ++ ] = value ; } } } | Draws a filled rectangle that is aligned along the image axis inside the image . All bands are filled with the same value . |
27,656 | public static void flipVertical ( GrayS32 input ) { int h2 = input . height / 2 ; for ( int y = 0 ; y < h2 ; y ++ ) { int index1 = input . getStartIndex ( ) + y * input . getStride ( ) ; int index2 = input . getStartIndex ( ) + ( input . height - y - 1 ) * input . getStride ( ) ; int end = index1 + input . width ; while ( index1 < end ) { int tmp = input . data [ index1 ] ; input . data [ index1 ++ ] = input . data [ index2 ] ; input . data [ index2 ++ ] = ( int ) tmp ; } } } | Flips the image from top to bottom |
27,657 | public static void flipHorizontal ( GrayS32 input ) { int w2 = input . width / 2 ; for ( int y = 0 ; y < input . height ; y ++ ) { int index1 = input . getStartIndex ( ) + y * input . getStride ( ) ; int index2 = index1 + input . width - 1 ; int end = index1 + w2 ; while ( index1 < end ) { int tmp = input . data [ index1 ] ; input . data [ index1 ++ ] = input . data [ index2 ] ; input . data [ index2 -- ] = ( int ) tmp ; } } } | Flips the image from left to right |
27,658 | public static void rotateCCW ( GrayS64 image ) { if ( image . width != image . height ) throw new IllegalArgumentException ( "Image must be square" ) ; int w = image . height / 2 + image . height % 2 ; int h = image . height / 2 ; for ( int y0 = 0 ; y0 < h ; y0 ++ ) { int y1 = image . height - y0 - 1 ; for ( int x0 = 0 ; x0 < w ; x0 ++ ) { int x1 = image . width - x0 - 1 ; int index0 = image . startIndex + y0 * image . stride + x0 ; int index1 = image . startIndex + x0 * image . stride + y1 ; int index2 = image . startIndex + y1 * image . stride + x1 ; int index3 = image . startIndex + x1 * image . stride + y0 ; long tmp0 = image . data [ index0 ] ; image . data [ index0 ] = image . data [ index1 ] ; image . data [ index1 ] = image . data [ index2 ] ; image . data [ index2 ] = image . data [ index3 ] ; image . data [ index3 ] = ( long ) tmp0 ; } } } | In - place 90 degree image rotation in the counter - clockwise direction . Only works on square images . |
27,659 | public static void rotateCCW ( GrayS64 input , GrayS64 output ) { if ( input . width != output . height || input . height != output . width ) throw new IllegalArgumentException ( "Incompatible shapes" ) ; int w = input . width - 1 ; for ( int y = 0 ; y < input . height ; y ++ ) { int indexIn = input . startIndex + y * input . stride ; for ( int x = 0 ; x < input . width ; x ++ ) { output . unsafe_set ( y , w - x , input . data [ indexIn ++ ] ) ; } } } | Rotates the image 90 degrees in the counter - clockwise direction . |
27,660 | public static void fillBand ( InterleavedF64 input , int band , double value ) { final int numBands = input . numBands ; for ( int y = 0 ; y < input . height ; y ++ ) { int index = input . getStartIndex ( ) + y * input . getStride ( ) + band ; int end = index + input . width * numBands - band ; for ( ; index < end ; index += numBands ) { input . data [ index ] = value ; } } } | Fills one band in the image with the specified value |
27,661 | public static void fillBorder ( GrayF64 input , double value , int radius ) { for ( int y = 0 ; y < radius ; y ++ ) { int indexTop = input . startIndex + y * input . stride ; int indexBottom = input . startIndex + ( input . height - y - 1 ) * input . stride ; for ( int x = 0 ; x < input . width ; x ++ ) { input . data [ indexTop ++ ] = value ; input . data [ indexBottom ++ ] = value ; } } int h = input . height - radius ; int indexStart = input . startIndex + radius * input . stride ; for ( int x = 0 ; x < radius ; x ++ ) { int indexLeft = indexStart + x ; int indexRight = indexStart + input . width - 1 - x ; for ( int y = radius ; y < h ; y ++ ) { input . data [ indexLeft ] = value ; input . data [ indexRight ] = value ; indexLeft += input . stride ; indexRight += input . stride ; } } } | Fills the outside border with the specified value |
27,662 | public static void fillRectangle ( GrayF64 img , double value , int x0 , int y0 , int width , int height ) { int x1 = x0 + width ; int y1 = y0 + height ; if ( x0 < 0 ) x0 = 0 ; if ( x1 > img . width ) x1 = img . width ; if ( y0 < 0 ) y0 = 0 ; if ( y1 > img . height ) y1 = img . height ; for ( int y = y0 ; y < y1 ; y ++ ) { for ( int x = x0 ; x < x1 ; x ++ ) { img . set ( x , y , value ) ; } } } | Draws a filled rectangle that is aligned along the image axis inside the image . |
27,663 | public static RectangleLength2D_F32 boundBoxInside ( int srcWidth , int srcHeight , PixelTransform < Point2D_F32 > transform , Point2D_F32 work ) { List < Point2D_F32 > points = computeBoundingPoints ( srcWidth , srcHeight , transform , work ) ; Point2D_F32 center = new Point2D_F32 ( ) ; UtilPoint2D_F32 . mean ( points , center ) ; float x0 , x1 , y0 , y1 ; x0 = y0 = Float . MAX_VALUE ; x1 = y1 = - Float . MAX_VALUE ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { Point2D_F32 p = points . get ( i ) ; if ( p . x < x0 ) x0 = p . x ; if ( p . x > x1 ) x1 = p . x ; if ( p . y < y0 ) y0 = p . y ; if ( p . y > y1 ) y1 = p . y ; } x0 -= center . x ; x1 -= center . x ; y0 -= center . y ; y1 -= center . y ; float ox0 = x0 ; float oy0 = y0 ; float ox1 = x1 ; float oy1 = y1 ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { Point2D_F32 p = points . get ( i ) ; float dx = p . x - center . x ; float dy = p . y - center . y ; if ( dx > x0 && dy > y0 && dx < x1 && dy < y1 ) { float d0 = ( float ) ( float ) Math . abs ( dx - x0 ) + x0 - ox0 ; float d1 = ( float ) ( float ) Math . abs ( dx - x1 ) + ox1 - x1 ; float d2 = ( float ) ( float ) Math . abs ( dy - y0 ) + y0 - oy0 ; float d3 = ( float ) ( float ) Math . abs ( dy - y1 ) + oy1 - y1 ; if ( d0 <= d1 && d0 <= d2 && d0 <= d3 ) { x0 = dx ; } else if ( d1 <= d2 && d1 <= d3 ) { x1 = dx ; } else if ( d2 <= d3 ) { y0 = dy ; } else { y1 = dy ; } } } return new RectangleLength2D_F32 ( x0 + center . x , y0 + center . y , x1 - x0 , y1 - y0 ) ; } | Ensures that the entire box will be inside |
27,664 | public void initialize ( T image , RectangleRotate_F32 initial ) { this . region . set ( initial ) ; calcHistogram . computeHistogram ( image , initial ) ; System . arraycopy ( calcHistogram . getHistogram ( ) , 0 , keyHistogram , 0 , keyHistogram . length ) ; this . minimumWidth = initial . width * minimumSizeRatio ; } | Specifies the initial image to learn the target description |
27,665 | public void track ( T image ) { region0 . set ( region ) ; region1 . set ( region ) ; region2 . set ( region ) ; region0 . width *= 1 - scaleChange ; region0 . height *= 1 - scaleChange ; region2 . width *= 1 + scaleChange ; region2 . height *= 1 + scaleChange ; double distance0 = 1 , distance1 , distance2 = 1 ; if ( ! constantScale ) { if ( region0 . width >= minimumWidth ) { updateLocation ( image , region0 ) ; distance0 = distanceHistogram ( keyHistogram , calcHistogram . getHistogram ( ) ) ; if ( updateHistogram ) System . arraycopy ( calcHistogram . getHistogram ( ) , 0 , histogram0 , 0 , histogram0 . length ) ; } updateLocation ( image , region2 ) ; distance2 = distanceHistogram ( keyHistogram , calcHistogram . getHistogram ( ) ) ; if ( updateHistogram ) System . arraycopy ( calcHistogram . getHistogram ( ) , 0 , histogram2 , 0 , histogram2 . length ) ; } updateLocation ( image , region1 ) ; if ( ! constantScale ) { distance1 = distanceHistogram ( keyHistogram , calcHistogram . getHistogram ( ) ) ; } else { distance1 = 0 ; } if ( updateHistogram ) System . arraycopy ( calcHistogram . getHistogram ( ) , 0 , histogram1 , 0 , histogram1 . length ) ; RectangleRotate_F32 selected = null ; float selectedHist [ ] = null ; switch ( selectBest ( distance0 , distance1 , distance2 ) ) { case 0 : selected = region0 ; selectedHist = histogram0 ; break ; case 1 : selected = region1 ; selectedHist = histogram1 ; break ; case 2 : selected = region2 ; selectedHist = histogram2 ; break ; default : throw new RuntimeException ( "Bug in selectBest" ) ; } float w = selected . width * ( 1 - gamma ) + gamma * region . width ; float h = selected . height * ( 1 - gamma ) + gamma * region . height ; region . set ( selected ) ; region . width = w ; region . height = h ; if ( updateHistogram ) { System . arraycopy ( selectedHist , 0 , keyHistogram , 0 , keyHistogram . length ) ; } } | Searches for the target in the most recent image . |
27,666 | private int selectBest ( double a , double b , double c ) { if ( a < b ) { if ( a < c ) return 0 ; else return 2 ; } else if ( b <= c ) { return 1 ; } else { return 2 ; } } | Given the 3 scores return the index of the best |
27,667 | protected void updateLocation ( T image , RectangleRotate_F32 region ) { double bestHistScore = Double . MAX_VALUE ; float bestX = - 1 , bestY = - 1 ; for ( int i = 0 ; i < maxIterations ; i ++ ) { calcHistogram . computeHistogram ( image , region ) ; float histogram [ ] = calcHistogram . getHistogram ( ) ; updateWeights ( histogram ) ; double histScore = distanceHistogram ( keyHistogram , histogram ) ; if ( histScore < bestHistScore ) { bestHistScore = histScore ; bestX = region . cx ; bestY = region . cy ; } List < Point2D_F32 > samples = calcHistogram . getSamplePts ( ) ; int sampleHistIndex [ ] = calcHistogram . getSampleHistIndex ( ) ; float meanX = 0 ; float meanY = 0 ; float totalWeight = 0 ; for ( int j = 0 ; j < samples . size ( ) ; j ++ ) { Point2D_F32 samplePt = samples . get ( j ) ; int histIndex = sampleHistIndex [ j ] ; if ( histIndex < 0 ) continue ; float w = weightHistogram [ histIndex ] ; meanX += w * samplePt . x ; meanY += w * samplePt . y ; totalWeight += w ; } meanX /= totalWeight ; meanY /= totalWeight ; calcHistogram . squareToImageSample ( meanX , meanY , region ) ; meanX = calcHistogram . imageX ; meanY = calcHistogram . imageY ; boolean done = Math . abs ( meanX - region . cx ) <= minimumChange && Math . abs ( meanY - region . cy ) <= minimumChange ; region . cx = meanX ; region . cy = meanY ; if ( done ) { break ; } } region . cx = bestX ; region . cy = bestY ; } | Updates the region s location using the standard mean - shift algorithm |
27,668 | private void updateWeights ( float [ ] histogram ) { for ( int j = 0 ; j < weightHistogram . length ; j ++ ) { float h = histogram [ j ] ; if ( h != 0 ) { weightHistogram [ j ] = ( float ) Math . sqrt ( keyHistogram [ j ] / h ) ; } } } | Update the weights for each element in the histogram . Weights are used to favor colors which are less than expected . |
27,669 | protected double distanceHistogram ( float histogramA [ ] , float histogramB [ ] ) { double sumP = 0 ; for ( int i = 0 ; i < histogramA . length ; i ++ ) { float q = histogramA [ i ] ; float p = histogramB [ i ] ; sumP += Math . abs ( q - p ) ; } return sumP ; } | Computes the difference between two histograms using SAD . |
27,670 | public void setImageGradient ( Deriv derivX , Deriv derivY ) { this . imageDerivX . wrap ( derivX ) ; this . imageDerivY . wrap ( derivY ) ; } | Sets the image spacial derivatives . These should be computed from an image at the appropriate scale in scale - space . |
27,671 | public void process ( double c_x , double c_y , double sigma , double orientation , TupleDesc_F64 descriptor ) { descriptor . fill ( 0 ) ; computeRawDescriptor ( c_x , c_y , sigma , orientation , descriptor ) ; normalizeDescriptor ( descriptor , maxDescriptorElementValue ) ; } | Computes the SIFT descriptor for the specified key point |
27,672 | void computeRawDescriptor ( double c_x , double c_y , double sigma , double orientation , TupleDesc_F64 descriptor ) { double c = Math . cos ( orientation ) ; double s = Math . sin ( orientation ) ; float fwidthSubregion = widthSubregion ; int sampleWidth = widthGrid * widthSubregion ; double sampleRadius = sampleWidth / 2 ; double sampleToPixels = sigma * sigmaToPixels ; Deriv image = ( Deriv ) imageDerivX . getImage ( ) ; for ( int sampleY = 0 ; sampleY < sampleWidth ; sampleY ++ ) { float subY = sampleY / fwidthSubregion ; double y = sampleToPixels * ( sampleY - sampleRadius ) ; for ( int sampleX = 0 ; sampleX < sampleWidth ; sampleX ++ ) { float subX = sampleX / fwidthSubregion ; double x = sampleToPixels * ( sampleX - sampleRadius ) ; int pixelX = ( int ) ( x * c - y * s + c_x + 0.5 ) ; int pixelY = ( int ) ( x * s + y * c + c_y + 0.5 ) ; if ( image . isInBounds ( pixelX , pixelY ) ) { float spacialDX = imageDerivX . unsafe_getF ( pixelX , pixelY ) ; float spacialDY = imageDerivY . unsafe_getF ( pixelX , pixelY ) ; double adjDX = c * spacialDX + s * spacialDY ; double adjDY = - s * spacialDX + c * spacialDY ; double angle = UtilAngle . domain2PI ( Math . atan2 ( adjDY , adjDX ) ) ; float weightGaussian = gaussianWeight [ sampleY * sampleWidth + sampleX ] ; float weightGradient = ( float ) Math . sqrt ( spacialDX * spacialDX + spacialDY * spacialDY ) ; trilinearInterpolation ( weightGaussian * weightGradient , subX , subY , angle , descriptor ) ; } } } } | Computes the descriptor by sampling the input image . This is raw because the descriptor hasn t been massaged yet . |
27,673 | public static void normalizeDescriptor ( TupleDesc_F64 descriptor , double maxDescriptorElementValue ) { UtilFeature . normalizeL2 ( descriptor ) ; for ( int i = 0 ; i < descriptor . size ( ) ; i ++ ) { double value = descriptor . value [ i ] ; if ( value > maxDescriptorElementValue ) { descriptor . value [ i ] = maxDescriptorElementValue ; } } UtilFeature . normalizeL2 ( descriptor ) ; } | Adjusts the descriptor . This adds lighting invariance and reduces the affects of none - affine changes in lighting . |
27,674 | protected static float [ ] createGaussianWeightKernel ( double sigma , int radius ) { Kernel2D_F32 ker = FactoryKernelGaussian . gaussian2D_F32 ( sigma , radius , false , false ) ; float maxValue = KernelMath . maxAbs ( ker . data , 4 * radius * radius ) ; KernelMath . divide ( ker , maxValue ) ; return ker . data ; } | Creates a gaussian weighting kernel with an even number of elements along its width |
27,675 | protected void trilinearInterpolation ( float weight , float sampleX , float sampleY , double angle , TupleDesc_F64 descriptor ) { for ( int i = 0 ; i < widthGrid ; i ++ ) { double weightGridY = 1.0 - Math . abs ( sampleY - i ) ; if ( weightGridY <= 0 ) continue ; for ( int j = 0 ; j < widthGrid ; j ++ ) { double weightGridX = 1.0 - Math . abs ( sampleX - j ) ; if ( weightGridX <= 0 ) continue ; for ( int k = 0 ; k < numHistogramBins ; k ++ ) { double angleBin = k * histogramBinWidth ; double weightHistogram = 1.0 - UtilAngle . dist ( angle , angleBin ) / histogramBinWidth ; if ( weightHistogram <= 0 ) continue ; int descriptorIndex = ( i * widthGrid + j ) * numHistogramBins + k ; descriptor . value [ descriptorIndex ] += weight * weightGridX * weightGridY * weightHistogram ; } } } } | Applies trilinear interpolation across the descriptor |
27,676 | private void computeFeatureMask ( int numModules , int [ ] alignment , boolean hasVersion ) { markSquare ( 0 , 0 , 9 ) ; markRectangle ( numModules - 8 , 0 , 9 , 8 ) ; markRectangle ( 0 , numModules - 8 , 8 , 9 ) ; markRectangle ( 8 , 6 , 1 , numModules - 8 - 8 ) ; markRectangle ( 6 , 8 , numModules - 8 - 8 , 1 ) ; if ( hasVersion ) { markRectangle ( numModules - 11 , 0 , 6 , 3 ) ; markRectangle ( 0 , numModules - 11 , 3 , 6 ) ; } for ( int i = 0 ; i < alignment . length ; i ++ ) { int row = alignment [ i ] ; for ( int j = 0 ; j < alignment . length ; j ++ ) { if ( i == 0 & j == 0 ) continue ; if ( i == alignment . length - 1 & j == 0 ) continue ; if ( i == 0 & j == alignment . length - 1 ) continue ; int col = alignment [ j ] ; markSquare ( row - 2 , col - 2 , 5 ) ; } } } | Blocks out the location of features in the image . Needed for codeworld location extraction |
27,677 | private void computeBitLocations ( ) { int N = numRows ; int row = N - 1 ; int col = N - 1 ; int direction = - 1 ; while ( col > 0 ) { if ( col == 6 ) col -= 1 ; if ( ! get ( row , col ) ) { bits . add ( new Point2D_I32 ( col , row ) ) ; } if ( ! get ( row , col - 1 ) ) { bits . add ( new Point2D_I32 ( col - 1 , row ) ) ; } row += direction ; if ( row < 0 || row >= N ) { direction = - direction ; col -= 2 ; row += direction ; } } } | Snakes through and specifies the location of each bit for all the code words in the grid . |
27,678 | public static void drawRectangle ( Rectangle2D_I32 rect , Graphics2D g2 ) { g2 . drawLine ( rect . x0 , rect . y0 , rect . x1 , rect . y0 ) ; g2 . drawLine ( rect . x1 , rect . y0 , rect . x1 , rect . y1 ) ; g2 . drawLine ( rect . x0 , rect . y1 , rect . x1 , rect . y1 ) ; g2 . drawLine ( rect . x0 , rect . y1 , rect . x0 , rect . y0 ) ; } | Draws an axis aligned rectangle |
27,679 | public static SteerableCoefficients polynomial ( int order ) { if ( order == 1 ) return new PolyOrder1 ( ) ; else if ( order == 2 ) return new PolyOrder2 ( ) ; else if ( order == 3 ) return new PolyOrder3 ( ) ; else if ( order == 4 ) return new PolyOrder4 ( ) ; else throw new IllegalArgumentException ( "Only supports orders 1 to 4" ) ; } | Coefficients for even or odd parity polynomials . |
27,680 | private void pruneMatches ( ) { int index = 0 ; while ( index < matches . size ) { AssociatedTripleIndex a = matches . get ( index ) ; if ( a . c == - 1 ) { a . set ( matches . get ( matches . size - 1 ) ) ; matches . size -- ; } else { index ++ ; } } } | Removes by swapping all elements with a c index of - 1 |
27,681 | public void setNumberControl ( int numControl ) { this . numControl = numControl ; if ( numControl == 4 ) { x0 . reshape ( 10 , 1 , false ) ; AA . reshape ( 10 , 9 , false ) ; yy . reshape ( 10 , 1 , false ) ; xx . reshape ( 9 , 1 , false ) ; numNull = 3 ; } else { x0 . reshape ( 6 , 1 , false ) ; AA . reshape ( 4 , 2 , false ) ; yy . reshape ( 4 , 1 , false ) ; xx . reshape ( 2 , 1 , false ) ; numNull = 1 ; } int index = 0 ; for ( int i = 0 ; i < numControl ; i ++ ) { for ( int j = i ; j < numControl ; j ++ ) { table [ i * numControl + j ] = table [ j * numControl + i ] = index ++ ; } } } | Specified the number of control points . |
27,682 | public void process ( DMatrixRMaj L_full , DMatrixRMaj y , double betas [ ] ) { svd . decompose ( L_full ) ; V = svd . getV ( null , true ) ; pseudo . setA ( L_full ) ; pseudo . solve ( y , x0 ) ; DMatrixRMaj alphas = solveConstraintMatrix ( ) ; for ( int i = 0 ; i < x0 . numRows ; i ++ ) { for ( int j = 0 ; j < numNull ; j ++ ) { x0 . data [ i ] += alphas . data [ j ] * valueNull ( j , i ) ; } } if ( numControl == 4 ) { betas [ 0 ] = Math . sqrt ( Math . abs ( x0 . data [ 0 ] ) ) ; betas [ 1 ] = Math . sqrt ( Math . abs ( x0 . data [ 4 ] ) ) * Math . signum ( x0 . data [ 1 ] ) ; betas [ 2 ] = Math . sqrt ( Math . abs ( x0 . data [ 7 ] ) ) * Math . signum ( x0 . data [ 2 ] ) ; betas [ 3 ] = Math . sqrt ( Math . abs ( x0 . data [ 9 ] ) ) * Math . signum ( x0 . data [ 3 ] ) ; } else { betas [ 0 ] = Math . sqrt ( Math . abs ( x0 . data [ 0 ] ) ) ; betas [ 1 ] = Math . sqrt ( Math . abs ( x0 . data [ 3 ] ) ) * Math . signum ( x0 . data [ 1 ] ) ; betas [ 2 ] = Math . sqrt ( Math . abs ( x0 . data [ 5 ] ) ) * Math . signum ( x0 . data [ 2 ] ) ; } } | Estimates betas using relinearization . |
27,683 | protected DMatrixRMaj solveConstraintMatrix ( ) { int rowAA = 0 ; for ( int i = 0 ; i < numControl ; i ++ ) { for ( int j = i + 1 ; j < numControl ; j ++ ) { for ( int k = j ; k < numControl ; k ++ , rowAA ++ ) { extractXaXb ( getIndex ( i , i ) , getIndex ( j , k ) , XiiXjk ) ; extractXaXb ( getIndex ( i , k ) , getIndex ( j , i ) , XikXji ) ; for ( int l = 1 ; l <= AA . numCols ; l ++ ) { AA . set ( rowAA , l - 1 , XikXji [ l ] - XiiXjk [ l ] ) ; } yy . set ( rowAA , XiiXjk [ 0 ] - XikXji [ 0 ] ) ; } } } CommonOps_DDRM . solve ( AA , yy , xx ) ; return xx ; } | Apply additional constraints to reduce the number of possible solutions |
27,684 | public static < T extends ImageGray < T > > void orderBandsIntoRGB ( Planar < T > image , BufferedImage input ) { boolean swap = swapBandOrder ( input ) ; if ( swap ) { if ( image . getNumBands ( ) == 3 ) { int bufferedImageType = input . getType ( ) ; if ( bufferedImageType == BufferedImage . TYPE_3BYTE_BGR || bufferedImageType == BufferedImage . TYPE_INT_BGR ) { T tmp = image . getBand ( 0 ) ; image . bands [ 0 ] = image . getBand ( 2 ) ; image . bands [ 2 ] = tmp ; } } else if ( image . getNumBands ( ) == 4 ) { T [ ] temp = ( T [ ] ) Array . newInstance ( image . getBandType ( ) , 4 ) ; int bufferedImageType = input . getType ( ) ; if ( bufferedImageType == BufferedImage . TYPE_INT_ARGB ) { temp [ 0 ] = image . getBand ( 1 ) ; temp [ 1 ] = image . getBand ( 2 ) ; temp [ 2 ] = image . getBand ( 3 ) ; temp [ 3 ] = image . getBand ( 0 ) ; } else if ( bufferedImageType == BufferedImage . TYPE_4BYTE_ABGR ) { temp [ 0 ] = image . getBand ( 3 ) ; temp [ 1 ] = image . getBand ( 2 ) ; temp [ 2 ] = image . getBand ( 1 ) ; temp [ 3 ] = image . getBand ( 0 ) ; } image . bands [ 0 ] = temp [ 0 ] ; image . bands [ 1 ] = temp [ 1 ] ; image . bands [ 2 ] = temp [ 2 ] ; image . bands [ 3 ] = temp [ 3 ] ; } } } | If a Planar was created from a BufferedImage its colors might not be in the expected order . Invoking this function ensures that the image will have the expected ordering . For images with 3 bands it will be RGB and for 4 bands it will be ARGB . |
27,685 | public static boolean isKnownByteFormat ( BufferedImage image ) { int type = image . getType ( ) ; return type != BufferedImage . TYPE_BYTE_INDEXED && type != BufferedImage . TYPE_BYTE_BINARY && type != BufferedImage . TYPE_CUSTOM ; } | Checks to see if it is a known byte format |
27,686 | public static List < BufferedImage > loadImages ( String directory , final String regex ) { List < String > paths = UtilIO . listByRegex ( directory , regex ) ; List < BufferedImage > ret = new ArrayList < > ( ) ; if ( paths . size ( ) == 0 ) return ret ; Collections . sort ( paths ) ; for ( String path : paths ) { BufferedImage img = loadImage ( path ) ; if ( img != null ) ret . add ( img ) ; } return ret ; } | Loads all the image in the specified directory which match the provided regex |
27,687 | public static BufferedImage loadImage ( URL url ) { if ( url == null ) return null ; try { BufferedImage buffered = ImageIO . read ( url ) ; if ( buffered != null ) return buffered ; if ( url . getProtocol ( ) . equals ( "file" ) ) { String path = URLDecoder . decode ( url . getPath ( ) , "UTF-8" ) ; if ( ! new File ( path ) . exists ( ) ) { System . err . println ( "File does not exist: " + path ) ; return null ; } } } catch ( IOException ignore ) { } try { InputStream stream = url . openStream ( ) ; String path = url . toString ( ) ; if ( path . toLowerCase ( ) . endsWith ( "ppm" ) ) { return loadPPM ( stream , null ) ; } else if ( path . toLowerCase ( ) . endsWith ( "pgm" ) ) { return loadPGM ( stream , null ) ; } stream . close ( ) ; } catch ( IOException ignore ) { } return null ; } | A function that load the specified image . If anything goes wrong it returns a null . |
27,688 | public static < T extends ImageGray < T > > T loadImage ( String fileName , Class < T > imageType ) { BufferedImage img = loadImage ( fileName ) ; if ( img == null ) return null ; return ConvertBufferedImage . convertFromSingle ( img , ( T ) null , imageType ) ; } | Loads the image and converts into the specified image type . |
27,689 | public static BufferedImage loadPPM ( String fileName , BufferedImage storage ) throws IOException { return loadPPM ( new FileInputStream ( fileName ) , storage ) ; } | Loads a PPM image from a file . |
27,690 | public static BufferedImage loadPGM ( String fileName , BufferedImage storage ) throws IOException { return loadPGM ( new FileInputStream ( fileName ) , storage ) ; } | Loads a PGM image from a file . |
27,691 | public static void savePPM ( Planar < GrayU8 > rgb , String fileName , GrowQueue_I8 temp ) throws IOException { File out = new File ( fileName ) ; DataOutputStream os = new DataOutputStream ( new FileOutputStream ( out ) ) ; String header = String . format ( "P6\n%d %d\n255\n" , rgb . width , rgb . height ) ; os . write ( header . getBytes ( ) ) ; if ( temp == null ) temp = new GrowQueue_I8 ( ) ; temp . resize ( rgb . width * rgb . height * 3 ) ; byte data [ ] = temp . data ; GrayU8 band0 = rgb . getBand ( 0 ) ; GrayU8 band1 = rgb . getBand ( 1 ) ; GrayU8 band2 = rgb . getBand ( 2 ) ; int indexOut = 0 ; for ( int y = 0 ; y < rgb . height ; y ++ ) { int index = rgb . startIndex + y * rgb . stride ; for ( int x = 0 ; x < rgb . width ; x ++ , index ++ ) { data [ indexOut ++ ] = band0 . data [ index ] ; data [ indexOut ++ ] = band1 . data [ index ] ; data [ indexOut ++ ] = band2 . data [ index ] ; } } os . write ( data , 0 , temp . size ) ; os . close ( ) ; } | Saves an image in PPM format . |
27,692 | public static void savePGM ( GrayU8 gray , String fileName ) throws IOException { File out = new File ( fileName ) ; DataOutputStream os = new DataOutputStream ( new FileOutputStream ( out ) ) ; String header = String . format ( "P5\n%d %d\n255\n" , gray . width , gray . height ) ; os . write ( header . getBytes ( ) ) ; os . write ( gray . data , 0 , gray . width * gray . height ) ; os . close ( ) ; } | Saves an image in PGM format . |
27,693 | public static < T extends KernelBase > T gaussian ( Class < T > kernelType , double sigma , int radius ) { if ( Kernel1D_F32 . class == kernelType ) { return gaussian ( 1 , true , 32 , sigma , radius ) ; } else if ( Kernel1D_F64 . class == kernelType ) { return gaussian ( 1 , true , 64 , sigma , radius ) ; } else if ( Kernel1D_S32 . class == kernelType ) { return gaussian ( 1 , false , 32 , sigma , radius ) ; } else if ( Kernel2D_S32 . class == kernelType ) { return gaussian ( 2 , false , 32 , sigma , radius ) ; } else if ( Kernel2D_F32 . class == kernelType ) { return gaussian ( 2 , true , 32 , sigma , radius ) ; } else if ( Kernel2D_F64 . class == kernelType ) { return gaussian ( 2 , true , 64 , sigma , radius ) ; } else { throw new RuntimeException ( "Unknown kernel type. " + kernelType . getSimpleName ( ) ) ; } } | Creates a Gaussian kernel of the specified type . |
27,694 | public static < T extends ImageGray < T > , K extends Kernel1D > K gaussian1D ( Class < T > imageType , double sigma , int radius ) { boolean isFloat = GeneralizedImageOps . isFloatingPoint ( imageType ) ; int numBits = GeneralizedImageOps . getNumBits ( imageType ) ; if ( numBits < 32 ) numBits = 32 ; return gaussian ( 1 , isFloat , numBits , sigma , radius ) ; } | Creates a 1D Gaussian kernel of the specified type . |
27,695 | public static < T extends ImageGray < T > , K extends Kernel2D > K gaussian2D ( Class < T > imageType , double sigma , int radius ) { boolean isFloat = GeneralizedImageOps . isFloatingPoint ( imageType ) ; int numBits = Math . max ( 32 , GeneralizedImageOps . getNumBits ( imageType ) ) ; return gaussian ( 2 , isFloat , numBits , sigma , radius ) ; } | Creates a 2D Gaussian kernel of the specified type . |
27,696 | public static < T extends KernelBase > T gaussian ( int DOF , boolean isFloat , int numBits , double sigma , int radius ) { if ( radius <= 0 ) radius = FactoryKernelGaussian . radiusForSigma ( sigma , 0 ) ; else if ( sigma <= 0 ) sigma = FactoryKernelGaussian . sigmaForRadius ( radius , 0 ) ; if ( DOF == 2 ) { if ( numBits == 32 ) { Kernel2D_F32 k = gaussian2D_F32 ( sigma , radius , true , isFloat ) ; if ( isFloat ) return ( T ) k ; return ( T ) KernelMath . convert ( k , MIN_FRAC ) ; } else if ( numBits == 64 ) { Kernel2D_F64 k = gaussian2D_F64 ( sigma , radius , true , isFloat ) ; if ( isFloat ) return ( T ) k ; else throw new IllegalArgumentException ( "64bit int kernels supported" ) ; } else { throw new IllegalArgumentException ( "Bits must be 32 or 64" ) ; } } else if ( DOF == 1 ) { if ( numBits == 32 ) { Kernel1D_F32 k = gaussian1D_F32 ( sigma , radius , true , isFloat ) ; if ( isFloat ) return ( T ) k ; return ( T ) KernelMath . convert ( k , MIN_FRAC ) ; } else if ( numBits == 64 ) { Kernel1D_F64 k = gaussian1D_F64 ( sigma , radius , true , isFloat ) ; if ( isFloat ) return ( T ) k ; return ( T ) KernelMath . convert ( k , MIN_FRACD ) ; } else { throw new IllegalArgumentException ( "Bits must be 32 or 64 not " + numBits ) ; } } else { throw new IllegalArgumentException ( "DOF not supported" ) ; } } | Creates a Gaussian kernel with the specified properties . |
27,697 | public static < T extends Kernel1D > T derivative ( int order , boolean isFloat , double sigma , int radius ) { if ( order == 0 ) { return gaussian ( 1 , isFloat , 32 , sigma , radius ) ; } if ( radius <= 0 ) radius = FactoryKernelGaussian . radiusForSigma ( sigma , order ) ; else if ( sigma <= 0 ) { sigma = FactoryKernelGaussian . sigmaForRadius ( radius , order ) ; } Kernel1D_F32 k = derivative1D_F32 ( order , sigma , radius , true ) ; if ( isFloat ) return ( T ) k ; return ( T ) KernelMath . convert ( k , MIN_FRAC ) ; } | Creates a 1D Gaussian kernel with the specified properties . |
27,698 | public static Kernel2D_F32 gaussian2D_F32 ( double sigma , int radius , boolean odd , boolean normalize ) { Kernel1D_F32 kernel1D = gaussian1D_F32 ( sigma , radius , odd , false ) ; Kernel2D_F32 ret = KernelMath . convolve2D ( kernel1D , kernel1D ) ; if ( normalize ) { KernelMath . normalizeSumToOne ( ret ) ; } return ret ; } | Creates a kernel for a 2D convolution . This should only be used for validation purposes . |
27,699 | protected static Kernel1D_F32 derivative1D_F32 ( int order , double sigma , int radius , boolean normalize ) { Kernel1D_F32 ret = new Kernel1D_F32 ( radius * 2 + 1 ) ; float [ ] gaussian = ret . data ; int index = 0 ; switch ( order ) { case 1 : for ( int i = radius ; i >= - radius ; i -- ) { gaussian [ index ++ ] = ( float ) UtilGaussian . derivative1 ( 0 , sigma , i ) ; } break ; case 2 : for ( int i = radius ; i >= - radius ; i -- ) { gaussian [ index ++ ] = ( float ) UtilGaussian . derivative2 ( 0 , sigma , i ) ; } break ; case 3 : for ( int i = radius ; i >= - radius ; i -- ) { gaussian [ index ++ ] = ( float ) UtilGaussian . derivative3 ( 0 , sigma , i ) ; } break ; case 4 : for ( int i = radius ; i >= - radius ; i -- ) { gaussian [ index ++ ] = ( float ) UtilGaussian . derivative4 ( 0 , sigma , i ) ; } break ; default : throw new IllegalArgumentException ( "Only derivatives of order 1 to 4 are supported" ) ; } if ( normalize ) { double sum = 0 ; for ( int i = radius ; i >= - radius ; i -- ) { sum += UtilGaussian . computePDF ( 0 , sigma , i ) ; } for ( int i = 0 ; i < gaussian . length ; i ++ ) { gaussian [ i ] /= sum ; } } return ret ; } | Computes the derivative of a Gaussian kernel . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.