idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
26,800 | public void reset ( ) { square = null ; touch = null ; center . set ( - 1 , - 1 ) ; largestSide = 0 ; smallestSide = Double . MAX_VALUE ; graph = RESET_GRAPH ; for ( int i = 0 ; i < edges . length ; i ++ ) { if ( edges [ i ] != null ) throw new RuntimeException ( "BUG!" ) ; sideLengths [ i ] = 0 ; } } | Discards previous information | 94 | 4 |
26,801 | public void updateArrayLength ( ) { if ( edges . length != square . size ( ) ) { edges = new SquareEdge [ square . size ( ) ] ; sideLengths = new double [ square . size ( ) ] ; } } | touch the border? | 50 | 4 |
26,802 | public int getNumberOfConnections ( ) { int ret = 0 ; for ( int i = 0 ; i < square . size ( ) ; i ++ ) { if ( edges [ i ] != null ) ret ++ ; } return ret ; } | Computes the number of edges attached to this node | 51 | 10 |
26,803 | public static < T extends ImageGray < T > > InterpolatePixelS < T > createPixelS ( double min , double max , InterpolationType type , BorderType borderType , Class < T > imageType ) { InterpolatePixelS < T > alg ; switch ( type ) { case NEAREST_NEIGHBOR : alg = nearestNeighborPixelS ( imageType ) ; break ; case BILINEAR : return bilinearPixelS ( imageType , borderType ) ; case BICUBIC : alg = bicubicS ( - 0.5f , ( float ) min , ( float ) max , imageType ) ; break ; case POLYNOMIAL4 : alg = polynomialS ( 4 , min , max , imageType ) ; break ; default : throw new IllegalArgumentException ( "Add type: " + type ) ; } if ( borderType != null ) alg . setBorder ( FactoryImageBorder . single ( imageType , borderType ) ) ; return alg ; } | Creates an interpolation class of the specified type for the specified image type . | 224 | 16 |
26,804 | public static < T extends ImageBase < T > > InterpolatePixelMB < T > createPixelMB ( double min , double max , InterpolationType type , BorderType borderType , ImageType < T > imageType ) { switch ( imageType . getFamily ( ) ) { case PLANAR : return ( InterpolatePixelMB < T > ) createPixelPL ( ( InterpolatePixelS ) createPixelS ( min , max , type , borderType , imageType . getDataType ( ) ) ) ; case GRAY : { InterpolatePixelS interpS = createPixelS ( min , max , type , borderType , imageType . getImageClass ( ) ) ; return new InterpolatePixel_S_to_MB ( interpS ) ; } case INTERLEAVED : switch ( type ) { case NEAREST_NEIGHBOR : return nearestNeighborPixelMB ( ( ImageType ) imageType , borderType ) ; case BILINEAR : return bilinearPixelMB ( ( ImageType ) imageType , borderType ) ; default : throw new IllegalArgumentException ( "Interpolate type not yet support for ImageInterleaved" ) ; } default : throw new IllegalArgumentException ( "Add type: " + type ) ; } } | Pixel based interpolation on multi - band image | 275 | 9 |
26,805 | public static void yu12ToBoof ( byte [ ] data , int width , int height , ImageBase output ) { if ( output instanceof Planar ) { Planar ms = ( Planar ) output ; ms . reshape ( width , height , 3 ) ; if ( BoofConcurrency . USE_CONCURRENT ) { if ( ms . getBandType ( ) == GrayU8 . class ) { ImplConvertYV12_MT . yv12ToPlanarRgb_U8 ( data , ms ) ; } else if ( ms . getBandType ( ) == GrayF32 . class ) { ImplConvertYV12_MT . yv12ToPlanarRgb_F32 ( data , ms ) ; } else { throw new IllegalArgumentException ( "Unsupported output band format" ) ; } } else { if ( ms . getBandType ( ) == GrayU8 . class ) { ImplConvertYV12 . yv12ToPlanarRgb_U8 ( data , ms ) ; } else if ( ms . getBandType ( ) == GrayF32 . class ) { ImplConvertYV12 . yv12ToPlanarRgb_F32 ( data , ms ) ; } else { throw new IllegalArgumentException ( "Unsupported output band format" ) ; } } } else if ( output instanceof ImageGray ) { if ( output . getClass ( ) == GrayU8 . class ) { yu12ToGray ( data , width , height , ( GrayU8 ) output ) ; } else if ( output . getClass ( ) == GrayF32 . class ) { yu12ToGray ( data , width , height , ( GrayF32 ) output ) ; } else { throw new IllegalArgumentException ( "Unsupported output type" ) ; } } else if ( output instanceof ImageInterleaved ) { ( ( ImageMultiBand ) output ) . reshape ( width , height , 3 ) ; if ( BoofConcurrency . USE_CONCURRENT ) { if ( output . getClass ( ) == InterleavedU8 . class ) { ImplConvertYV12_MT . yv12ToInterleaved ( data , ( InterleavedU8 ) output ) ; } else if ( output . getClass ( ) == InterleavedF32 . class ) { ImplConvertYV12_MT . yv12ToInterleaved ( data , ( InterleavedF32 ) output ) ; } else { throw new IllegalArgumentException ( "Unsupported output type" ) ; } } else { if ( output . getClass ( ) == InterleavedU8 . class ) { ImplConvertYV12 . yv12ToInterleaved ( data , ( InterleavedU8 ) output ) ; } else if ( output . getClass ( ) == InterleavedF32 . class ) { ImplConvertYV12 . yv12ToInterleaved ( data , ( InterleavedF32 ) output ) ; } else { throw new IllegalArgumentException ( "Unsupported output type" ) ; } } } else { throw new IllegalArgumentException ( "Boofcv image type not yet supported" ) ; } } | Converts a YU12 encoded byte array into a BoofCV formatted image . | 691 | 17 |
26,806 | public static GrayU8 yu12ToGray ( byte [ ] data , int width , int height , GrayU8 output ) { if ( output != null ) { if ( output . width != width || output . height != height ) throw new IllegalArgumentException ( "output width and height must be " + width + " " + height ) ; } else { output = new GrayU8 ( width , height ) ; } if ( BoofConcurrency . USE_CONCURRENT ) { ImplConvertNV21_MT . nv21ToGray ( data , output ) ; } else { ImplConvertNV21 . nv21ToGray ( data , output ) ; } return output ; } | Converts an YV12 image into a gray scale U8 image . | 147 | 15 |
26,807 | public static < D > ScoreAssociation < D > scoreEuclidean ( Class < D > tupleType , boolean squared ) { if ( TupleDesc_F64 . class . isAssignableFrom ( tupleType ) ) { if ( squared ) return ( ScoreAssociation ) new ScoreAssociateEuclideanSq_F64 ( ) ; else return ( ScoreAssociation ) new ScoreAssociateEuclidean_F64 ( ) ; } else if ( tupleType == TupleDesc_F32 . class ) { if ( squared ) return ( ScoreAssociation ) new ScoreAssociateEuclideanSq_F32 ( ) ; } throw new IllegalArgumentException ( "Euclidean score not yet supported for type " + tupleType . getSimpleName ( ) ) ; } | Scores features based on the Euclidean distance between them . The square is often used instead of the Euclidean distance since it is much faster to compute . | 172 | 33 |
26,808 | public static < D > ScoreAssociation < D > scoreHamming ( Class < D > tupleType ) { if ( tupleType == TupleDesc_B . class ) { return ( ScoreAssociation ) new ScoreAssociateHamming_B ( ) ; } throw new IllegalArgumentException ( "Hamming distance not yet supported for type " + tupleType . getSimpleName ( ) ) ; } | Hamming distance between two binary descriptors . | 84 | 9 |
26,809 | public void process ( GrayF32 intensity , QueueCorner corners ) { corners . reset ( ) ; float data [ ] = intensity . data ; for ( int y = 0 ; y < intensity . height ; y ++ ) { int startIndex = intensity . startIndex + y * intensity . stride ; int endIndex = startIndex + intensity . width ; for ( int index = startIndex ; index < endIndex ; index ++ ) { if ( data [ index ] > thresh ) { int x = index - startIndex ; corners . add ( x , y ) ; } } } } | Selects pixels as corners which are above the threshold . | 123 | 11 |
26,810 | public void swapLists ( ) { FastQueue < Helper > tmp = srcPositive ; srcPositive = dstPositive ; dstPositive = tmp ; tmp = srcNegative ; srcNegative = dstNegative ; dstNegative = tmp ; } | Swaps the source and dest feature list . Useful when processing a sequence of images and don t want to resort everything . | 55 | 24 |
26,811 | public void associate ( ) { // initialize data structures matches . reset ( ) ; unassociatedSrc . reset ( ) ; if ( srcPositive . size == 0 && srcNegative . size == 0 ) return ; if ( dstPositive . size == 0 && dstNegative . size == 0 ) return ; // find and add the matches assoc . setSource ( ( FastQueue ) srcPositive ) ; assoc . setDestination ( ( FastQueue ) dstPositive ) ; assoc . associate ( ) ; FastQueue < AssociatedIndex > m = assoc . getMatches ( ) ; for ( int i = 0 ; i < m . size ; i ++ ) { AssociatedIndex a = m . data [ i ] ; int globalSrcIndex = srcPositive . data [ a . src ] . index ; int globalDstIndex = dstPositive . data [ a . dst ] . index ; matches . grow ( ) . setAssociation ( globalSrcIndex , globalDstIndex , a . fitScore ) ; } GrowQueue_I32 un = assoc . getUnassociatedSource ( ) ; for ( int i = 0 ; i < un . size ; i ++ ) { unassociatedSrc . add ( srcPositive . data [ un . get ( i ) ] . index ) ; } assoc . setSource ( ( FastQueue ) srcNegative ) ; assoc . setDestination ( ( FastQueue ) dstNegative ) ; assoc . associate ( ) ; m = assoc . getMatches ( ) ; for ( int i = 0 ; i < m . size ; i ++ ) { AssociatedIndex a = m . data [ i ] ; int globalSrcIndex = srcNegative . data [ a . src ] . index ; int globalDstIndex = dstNegative . data [ a . dst ] . index ; matches . grow ( ) . setAssociation ( globalSrcIndex , globalDstIndex , a . fitScore ) ; } un = assoc . getUnassociatedSource ( ) ; for ( int i = 0 ; i < un . size ; i ++ ) { unassociatedSrc . add ( srcNegative . data [ un . get ( i ) ] . index ) ; } } | Associates the features together . | 475 | 7 |
26,812 | private void sort ( FastQueue < BrightFeature > input , FastQueue < Helper > pos , FastQueue < Helper > neg ) { pos . reset ( ) ; neg . reset ( ) ; for ( int i = 0 ; i < input . size ; i ++ ) { BrightFeature f = input . get ( i ) ; if ( f . white ) { pos . grow ( ) . wrap ( f , i ) ; } else { neg . grow ( ) . wrap ( f , i ) ; } } } | Splits the set of input features into positive and negative laplacian lists . Keep track of the feature s index in the original input list . This is the index that needs to be returned . | 108 | 40 |
26,813 | public static < I extends ImageMultiBand < I > , M extends ImageMultiBand < M > , D extends ImageGray < D > > ImageGradient < I , D > gradientReduce ( ImageGradient < I , M > gradient , DerivativeReduceType type , Class < D > outputType ) { String name ; switch ( type ) { case MAX_F : name = "maxf" ; break ; default : throw new RuntimeException ( "Unknown reduce type " + type ) ; } Class middleType ; switch ( gradient . getDerivativeType ( ) . getFamily ( ) ) { case PLANAR : middleType = Planar . class ; break ; case GRAY : throw new IllegalArgumentException ( "Can't have gradient output be single band" ) ; default : middleType = gradient . getDerivativeType ( ) . getImageClass ( ) ; } Method m = findReduce ( name , middleType , outputType ) ; GradientMultiToSingleBand_Reflection < M , D > reducer = new GradientMultiToSingleBand_Reflection <> ( m , gradient . getDerivativeType ( ) , outputType ) ; return new ImageGradientThenReduce <> ( gradient , reducer ) ; } | Computes the image gradient inside a multi - band image then reduces the output to a single band before returning the results | 267 | 23 |
26,814 | public static < I extends ImageGray < I > , D extends ImageGray < D > > ImageGradient < I , D > gradientSB ( DerivativeType type , Class < I > inputType , Class < D > derivType ) { if ( derivType == null ) derivType = GImageDerivativeOps . getDerivativeType ( inputType ) ; Class which ; switch ( type ) { case PREWITT : which = GradientPrewitt . class ; break ; case SOBEL : which = GradientSobel . class ; break ; case THREE : which = GradientThree . class ; break ; case TWO_0 : which = GradientTwo0 . class ; break ; case TWO_1 : which = GradientTwo1 . class ; break ; default : throw new IllegalArgumentException ( "Unknown type " + type ) ; } Method m = findDerivative ( which , inputType , derivType ) ; return new ImageGradient_Reflection <> ( m ) ; } | Returns the gradient for single band images of the specified type | 215 | 11 |
26,815 | public int addPattern ( GrayU8 inputBinary , double lengthSide ) { if ( inputBinary == null ) { throw new IllegalArgumentException ( "Input image is null." ) ; } else if ( lengthSide <= 0 ) { throw new IllegalArgumentException ( "Parameter lengthSide must be more than zero" ) ; } else if ( ImageStatistics . max ( inputBinary ) > 1 ) throw new IllegalArgumentException ( "A binary image is composed on 0 and 1 pixels. This isn't binary!" ) ; // see if it needs to be resized if ( inputBinary . width != squareLength || inputBinary . height != squareLength ) { // need to create a new image and rescale it to better handle the resizing GrayF32 inputGray = new GrayF32 ( inputBinary . width , inputBinary . height ) ; ConvertImage . convert ( inputBinary , inputGray ) ; PixelMath . multiply ( inputGray , 255 , inputGray ) ; GrayF32 scaled = new GrayF32 ( squareLength , squareLength ) ; // See if it can use the better algorithm for scaling down the image if ( inputBinary . width > squareLength && inputBinary . height > squareLength ) { AverageDownSampleOps . down ( inputGray , scaled ) ; } else { new FDistort ( inputGray , scaled ) . scaleExt ( ) . apply ( ) ; } GThresholdImageOps . threshold ( scaled , binary , 255 / 2.0 , false ) ; } else { binary . setTo ( inputBinary ) ; } // describe it in 4 different orientations FiducialDef def = new FiducialDef ( ) ; def . lengthSide = lengthSide ; // CCW rotation so that the index refers to how many CW rotation it takes to put it into the nominal pose binaryToDef ( binary , def . desc [ 0 ] ) ; ImageMiscOps . rotateCCW ( binary ) ; binaryToDef ( binary , def . desc [ 1 ] ) ; ImageMiscOps . rotateCCW ( binary ) ; binaryToDef ( binary , def . desc [ 2 ] ) ; ImageMiscOps . rotateCCW ( binary ) ; binaryToDef ( binary , def . desc [ 3 ] ) ; int index = targets . size ( ) ; targets . add ( def ) ; return index ; } | Adds a new image to the detector . Image must be gray - scale and is converted into a binary image using the specified threshold . All input images are rescaled to be square and of the appropriate size . Thus the original shape of the image doesn t matter . Square shapes are highly recommended since that s what the target looks like . | 501 | 66 |
26,816 | protected static void binaryToDef ( GrayU8 binary , short [ ] desc ) { for ( int i = 0 ; i < binary . data . length ; i += 16 ) { int value = 0 ; for ( int j = 0 ; j < 16 ; j ++ ) { value |= binary . data [ i + j ] << j ; } desc [ i / 16 ] = ( short ) value ; } } | Converts a binary image into the compressed bit format | 87 | 10 |
26,817 | protected int hamming ( short [ ] a , short [ ] b ) { int distance = 0 ; for ( int i = 0 ; i < a . length ; i ++ ) { distance += DescriptorDistance . hamming ( ( a [ i ] & 0xFFFF ) ^ ( b [ i ] & 0xFFFF ) ) ; } return distance ; } | Computes the hamming score between two descriptions . Larger the number better the fit | 76 | 17 |
26,818 | public static TupleDesc_F64 combine ( List < TupleDesc_F64 > inputs , TupleDesc_F64 combined ) { int N = 0 ; for ( int i = 0 ; i < inputs . size ( ) ; i ++ ) { N += inputs . get ( i ) . size ( ) ; } if ( combined == null ) { combined = new TupleDesc_F64 ( N ) ; } else { if ( N != combined . size ( ) ) throw new RuntimeException ( "The combined feature needs to be " + N + " not " + combined . size ( ) ) ; } int start = 0 ; for ( int i = 0 ; i < inputs . size ( ) ; i ++ ) { double v [ ] = inputs . get ( i ) . value ; System . arraycopy ( v , 0 , combined . value , start , v . length ) ; start += v . length ; } return combined ; } | Concats the list of tuples together into one big feature . The combined feature must be large enough to store all the inputs . | 198 | 26 |
26,819 | public void setProcessing ( VideoProcessing processing ) { if ( this . processing != null ) { // kill the old process this . processing . stopProcessing ( ) ; } if ( Looper . getMainLooper ( ) . getThread ( ) != Thread . currentThread ( ) ) { throw new RuntimeException ( "Not called from a GUI thread. Bad stuff could happen" ) ; } this . processing = processing ; // if the camera is null then it will be initialized when the camera is initialized if ( processing != null && mCamera != null ) { processing . init ( mDraw , mCamera , mCameraInfo , previewRotation ) ; } } | Changes the CV algorithm running . Should only be called from a GUI thread . | 138 | 15 |
26,820 | private void setUpAndConfigureCamera ( ) { // Open and configure the camera mCamera = openConfigureCamera ( mCameraInfo ) ; setCameraDisplayOrientation ( mCameraInfo , mCamera ) ; // Create an instance of Camera mPreview . setCamera ( mCamera ) ; if ( processing != null ) { processing . init ( mDraw , mCamera , mCameraInfo , previewRotation ) ; } } | Sets up the camera if it is not already setup . | 89 | 12 |
26,821 | protected void setProgressMessage ( final String message ) { runOnUiThread ( new Runnable ( ) { public void run ( ) { synchronized ( lockProgress ) { if ( progressDialog != null ) { // a dialog is already open, change the message progressDialog . setMessage ( message ) ; return ; } progressDialog = new ProgressDialog ( VideoDisplayActivity . this ) ; progressDialog . setMessage ( message ) ; progressDialog . setIndeterminate ( true ) ; progressDialog . setProgressStyle ( ProgressDialog . STYLE_SPINNER ) ; } // don't show the dialog until 1 second has passed long showTime = System . currentTimeMillis ( ) + 1000 ; while ( showTime > System . currentTimeMillis ( ) ) { Thread . yield ( ) ; } // if it hasn't been dismissed, show the dialog synchronized ( lockProgress ) { if ( progressDialog != null ) progressDialog . show ( ) ; } } } ) ; // block until the GUI thread has been called while ( progressDialog == null ) { Thread . yield ( ) ; } } | Displays an indeterminate progress dialog . If the dialog is already open this will change the message being displayed . Function blocks until the dialog has been declared . | 229 | 32 |
26,822 | protected void hideProgressDialog ( ) { // do nothing if the dialog is already being displayed synchronized ( lockProgress ) { if ( progressDialog == null ) return ; } if ( Looper . getMainLooper ( ) . getThread ( ) == Thread . currentThread ( ) ) { // if inside the UI thread just dismiss the dialog and avoid a potential locking condition synchronized ( lockProgress ) { progressDialog . dismiss ( ) ; progressDialog = null ; } } else { runOnUiThread ( new Runnable ( ) { public void run ( ) { synchronized ( lockProgress ) { progressDialog . dismiss ( ) ; progressDialog = null ; } } } ) ; // block until dialog has been dismissed while ( progressDialog != null ) { Thread . yield ( ) ; } } } | Dismisses the progress dialog . Can be called even if there is no progressDialog being shown . | 163 | 21 |
26,823 | public void set ( CameraUniversalOmni original ) { super . set ( original ) ; this . mirrorOffset = original . mirrorOffset ; if ( radial . length != original . radial . length ) radial = new double [ original . radial . length ] ; System . arraycopy ( original . radial , 0 , radial , 0 , radial . length ) ; this . t1 = original . t1 ; this . t2 = original . t2 ; } | Assigns this model to be identical to the passed in model | 94 | 13 |
26,824 | public void process ( T image1 , T image2 , ImageFlow output ) { InputSanityCheck . checkSameShape ( image1 , image2 ) ; derivX . reshape ( image1 . width , image1 . height ) ; derivY . reshape ( image1 . width , image1 . height ) ; derivT . reshape ( image1 . width , image1 . height ) ; averageFlow . reshape ( output . width , output . height ) ; if ( resetOutput ) output . fillZero ( ) ; computeDerivX ( image1 , image2 , derivX ) ; computeDerivY ( image1 , image2 , derivY ) ; computeDerivT ( image1 , image2 , derivT ) ; findFlow ( derivX , derivY , derivT , output ) ; } | Computes dense optical flow from the first image s gradient and the difference between the second and the first image . | 172 | 22 |
26,825 | protected static void innerAverageFlow ( ImageFlow flow , ImageFlow averageFlow ) { int endX = flow . width - 1 ; int endY = flow . height - 1 ; for ( int y = 1 ; y < endY ; y ++ ) { int index = flow . width * y + 1 ; for ( int x = 1 ; x < endX ; x ++ , index ++ ) { ImageFlow . D average = averageFlow . data [ index ] ; ImageFlow . D f0 = flow . data [ index - 1 ] ; ImageFlow . D f1 = flow . data [ index + 1 ] ; ImageFlow . D f2 = flow . data [ index - flow . width ] ; ImageFlow . D f3 = flow . data [ index + flow . width ] ; ImageFlow . D f4 = flow . data [ index - 1 - flow . width ] ; ImageFlow . D f5 = flow . data [ index + 1 - flow . width ] ; ImageFlow . D f6 = flow . data [ index - 1 + flow . width ] ; ImageFlow . D f7 = flow . data [ index + 1 + flow . width ] ; average . x = 0.1666667f * ( f0 . x + f1 . x + f2 . x + f3 . x ) + 0.08333333f * ( f4 . x + f5 . x + f6 . x + f7 . x ) ; average . y = 0.1666667f * ( f0 . y + f1 . y + f2 . y + f3 . y ) + 0.08333333f * ( f4 . y + f5 . y + f6 . y + f7 . y ) ; } } } | Computes average flow using an 8 - connect neighborhood for the inner image | 372 | 14 |
26,826 | protected static void borderAverageFlow ( ImageFlow flow , ImageFlow averageFlow ) { for ( int y = 0 ; y < flow . height ; y ++ ) { computeBorder ( flow , averageFlow , 0 , y ) ; computeBorder ( flow , averageFlow , flow . width - 1 , y ) ; } for ( int x = 1 ; x < flow . width - 1 ; x ++ ) { computeBorder ( flow , averageFlow , x , 0 ) ; computeBorder ( flow , averageFlow , x , flow . height - 1 ) ; } } | Computes average flow using an 8 - connect neighborhood for the image border | 116 | 14 |
26,827 | void computeProjectionTable ( int width , int height ) { output . reshape ( width , height ) ; depthMap . reshape ( width , height ) ; ImageMiscOps . fill ( depthMap , - 1 ) ; pointing = new float [ width * height * 3 ] ; for ( int y = 0 ; y < output . height ; y ++ ) { for ( int x = 0 ; x < output . width ; x ++ ) { // Should this add 0.5 so that the ray goes out of the pixel's center? Seems to increase reprojection // error in calibration tests if I do... pixelTo3 . compute ( x , y , p3 ) ; if ( UtilEjml . isUncountable ( p3 . x ) ) { depthMap . unsafe_set ( x , y , Float . NaN ) ; } else { pointing [ ( y * output . width + x ) * 3 ] = ( float ) p3 . x ; pointing [ ( y * output . width + x ) * 3 + 1 ] = ( float ) p3 . y ; pointing [ ( y * output . width + x ) * 3 + 2 ] = ( float ) p3 . z ; } } } } | Computes 3D pointing vector for every pixel in the simulated camera frame | 258 | 14 |
26,828 | public GrayF32 render ( ) { ImageMiscOps . fill ( output , background ) ; ImageMiscOps . fill ( depthMap , Float . MAX_VALUE ) ; for ( int i = 0 ; i < scene . size ( ) ; i ++ ) { SurfaceRect r = scene . get ( i ) ; r . rectInCamera ( ) ; } if ( BoofConcurrency . USE_CONCURRENT ) { renderMultiThread ( ) ; } else { renderSingleThread ( ) ; } return getOutput ( ) ; } | Render the scene and returns the rendered image . | 113 | 9 |
26,829 | public void computePixel ( int which , double x , double y , Point2D_F64 output ) { SurfaceRect r = scene . get ( which ) ; Point3D_F64 p3 = new Point3D_F64 ( - x , - y , 0 ) ; SePointOps_F64 . transform ( r . rectToCamera , p3 , p3 ) ; // unit sphere p3 . scale ( 1.0 / p3 . norm ( ) ) ; sphereToPixel . compute ( p3 . x , p3 . y , p3 . z , output ) ; } | Project a point which lies on the 2D planar polygon s surface onto the rendered image | 127 | 19 |
26,830 | public void configure ( LensDistortionNarrowFOV model , PixelTransform < Point2D_F32 > visualToDepth ) { this . visualToDepth = visualToDepth ; this . p2n = model . undistort_F64 ( true , false ) ; } | Configures intrinsic camera parameters | 59 | 5 |
26,831 | public boolean process ( int x , int y ) { visualToDepth . compute ( x , y , distorted ) ; int depthX = ( int ) distorted . x ; int depthY = ( int ) distorted . y ; if ( depthImage . isInBounds ( depthX , depthY ) ) { // get the depth at the specified location double value = lookupDepth ( depthX , depthY ) ; // see if its an invalid value if ( value == 0 ) return false ; // convert visual pixel into normalized image coordinate p2n . compute ( x , y , norm ) ; // project into 3D space worldPt . z = value * depthScale ; worldPt . x = worldPt . z * norm . x ; worldPt . y = worldPt . z * norm . y ; return true ; } else { return false ; } } | Given a pixel coordinate in the visual camera compute the 3D coordinate of that point . | 182 | 17 |
26,832 | private void captureFiducialPoints ( ) { Polygon2D_F64 p = regions . grow ( ) ; p . vertexes . resize ( sidesCollision . size ( ) ) ; for ( int i = 0 ; i < sidesCollision . size ( ) ; i ++ ) { p . get ( i ) . set ( sidesCollision . get ( i ) ) ; } quality . addObservations ( detector . getDetectedPoints ( ) ) ; gui . getInfoPanel ( ) . updateGeometry ( quality . getScore ( ) ) ; // once the user has sufficient geometric variation enable save geometryTrigger |= quality . getScore ( ) >= 1.0 ; if ( geometryTrigger && magnets . isEmpty ( ) ) { gui . getInfoPanel ( ) . enabledFinishedButton ( ) ; } } | Record the area covered in the image by the fiducial update the quality calculation and see if it should enable the save button . | 175 | 26 |
26,833 | private boolean checkMagnetCapturePicture ( ) { boolean captured = false ; Iterator < Magnet > iter = magnets . iterator ( ) ; while ( iter . hasNext ( ) ) { Magnet i = iter . next ( ) ; if ( i . handlePictureTaken ( ) ) { iter . remove ( ) ; captured = true ; } } return captured ; } | Checks to see if its near one of the magnets in the image broder | 75 | 16 |
26,834 | public boolean fit ( List < Point2D_I32 > contour , GrowQueue_I32 corners ) { if ( corners . size ( ) < 3 ) { return false ; } searchRadius = Math . min ( 6 , Math . max ( contour . size ( ) / 12 , 3 ) ) ; int startCorner , endCorner ; if ( looping ) { startCorner = 0 ; endCorner = corners . size ; } else { // the end point positions are fixed startCorner = 1 ; endCorner = corners . size - 1 ; } boolean change = true ; for ( int iteration = 0 ; iteration < maxIterations && change ; iteration ++ ) { change = false ; for ( int i = startCorner ; i < endCorner ; i ++ ) { int c0 = CircularIndex . minusPOffset ( i , 1 , corners . size ( ) ) ; int c2 = CircularIndex . plusPOffset ( i , 1 , corners . size ( ) ) ; int improved = optimize ( contour , corners . get ( c0 ) , corners . get ( i ) , corners . get ( c2 ) ) ; if ( improved != corners . get ( i ) ) { corners . set ( i , improved ) ; change = true ; } } } return true ; } | Fits a polygon to the contour given an initial set of candidate corners . If not looping the corners must include the end points still . Minimum of 3 points required . Otherwise there s no corner! . | 279 | 43 |
26,835 | protected int optimize ( List < Point2D_I32 > contour , int c0 , int c1 , int c2 ) { double bestDistance = computeCost ( contour , c0 , c1 , c2 , 0 ) ; int bestIndex = 0 ; for ( int i = - searchRadius ; i <= searchRadius ; i ++ ) { if ( i == 0 ) { // if it found a better point in the first half stop the search since that's probably the correct // direction. Could be improved by remember past search direction if ( bestIndex != 0 ) break ; } else { double found = computeCost ( contour , c0 , c1 , c2 , i ) ; if ( found < bestDistance ) { bestDistance = found ; bestIndex = i ; } } } return CircularIndex . addOffset ( c1 , bestIndex , contour . size ( ) ) ; } | Searches around the current c1 point for the best place to put the corner | 192 | 17 |
26,836 | protected double computeCost ( List < Point2D_I32 > contour , int c0 , int c1 , int c2 , int offset ) { c1 = CircularIndex . addOffset ( c1 , offset , contour . size ( ) ) ; createLine ( c0 , c1 , contour , line0 ) ; createLine ( c1 , c2 , contour , line1 ) ; return distanceSum ( line0 , c0 , c1 , contour ) + distanceSum ( line1 , c1 , c2 , contour ) ; } | Computes the distance between the two lines defined by corner points in the contour | 122 | 16 |
26,837 | protected double distanceSum ( LineGeneral2D_F64 line , int c0 , int c1 , List < Point2D_I32 > contour ) { double total = 0 ; if ( c0 < c1 ) { int length = c1 - c0 + 1 ; int samples = Math . min ( maxLineSamples , length ) ; for ( int i = 0 ; i < samples ; i ++ ) { int index = c0 + i * ( length - 1 ) / ( samples - 1 ) ; total += distance ( line , contour . get ( index ) ) ; } } else { int lengthFirst = contour . size ( ) - c0 ; int lengthSecond = c1 + 1 ; int length = lengthFirst + c1 + 1 ; int samples = Math . min ( maxLineSamples , length ) ; int samplesFirst = samples * lengthFirst / length ; int samplesSecond = samples * lengthSecond / length ; for ( int i = 0 ; i < samplesFirst ; i ++ ) { int index = c0 + i * lengthFirst / ( samples - 1 ) ; total += distance ( line , contour . get ( index ) ) ; } for ( int i = 0 ; i < samplesSecond ; i ++ ) { int index = i * lengthSecond / ( samples - 1 ) ; total += distance ( line , contour . get ( index ) ) ; } } return total ; } | Sum of Euclidean distance of contour points along the line | 300 | 13 |
26,838 | private void createLine ( int index0 , int index1 , List < Point2D_I32 > contour , LineGeneral2D_F64 line ) { if ( index1 < 0 ) System . out . println ( "SHIT" ) ; Point2D_I32 p0 = contour . get ( index0 ) ; Point2D_I32 p1 = contour . get ( index1 ) ; // System.out.println("createLine "+p0+" "+p1); work . a . set ( p0 . x , p0 . y ) ; work . b . set ( p1 . x , p1 . y ) ; UtilLine2D_F64 . convert ( work , line ) ; // ensure A*A + B*B = 1 line . normalize ( ) ; } | Given segment information create a line in general notation which has been normalized | 177 | 13 |
26,839 | public < B extends ImageGray < B > > B createSameShape ( Class < B > type ) { return GeneralizedImageOps . createSingleBand ( type , width , height ) ; } | Creates a single band image of the specified type that will have the same shape as this image | 40 | 19 |
26,840 | private synchronized void changeImageView ( ) { JComponent comp ; if ( control . selectedView < 3 ) { BufferedImage img ; switch ( control . selectedView ) { case 0 : img = disparityOut ; break ; case 1 : img = colorLeft ; break ; case 2 : img = colorRight ; break ; default : throw new RuntimeException ( "Unknown option" ) ; } gui . setImage ( img ) ; gui . setPreferredSize ( new Dimension ( origLeft . getWidth ( ) , origLeft . getHeight ( ) ) ) ; comp = gui ; } else { if ( ! computedCloud ) { computedCloud = true ; DisparityToColorPointCloud d2c = new DisparityToColorPointCloud ( ) ; double baseline = calib . getRightToLeft ( ) . getT ( ) . norm ( ) ; d2c . configure ( baseline , rectK , rectR , leftRectToPixel , control . minDisparity , control . maxDisparity ) ; d2c . process ( activeAlg . getDisparity ( ) , colorLeft ) ; CameraPinhole rectifiedPinhole = PerspectiveOps . matrixToPinhole ( rectK , colorLeft . getWidth ( ) , colorLeft . getHeight ( ) , null ) ; pcv . clearPoints ( ) ; pcv . setCameraHFov ( PerspectiveOps . computeHFov ( rectifiedPinhole ) ) ; pcv . setTranslationStep ( 5 ) ; pcv . addCloud ( d2c . getCloud ( ) , d2c . getCloudColor ( ) ) ; } comp = pcv . getComponent ( ) ; comp . requestFocusInWindow ( ) ; } panel . remove ( gui ) ; panel . remove ( pcv . getComponent ( ) ) ; panel . add ( comp , BorderLayout . CENTER ) ; panel . validate ( ) ; comp . repaint ( ) ; processedImage = true ; } | Changes which image is being displayed depending on GUI selection | 410 | 10 |
26,841 | private void rectifyInputImages ( ) { // get intrinsic camera calibration matrices DMatrixRMaj K1 = PerspectiveOps . pinholeToMatrix ( calib . left , ( DMatrixRMaj ) null ) ; DMatrixRMaj K2 = PerspectiveOps . pinholeToMatrix ( calib . right , ( DMatrixRMaj ) null ) ; // compute rectification matrices rectifyAlg . process ( K1 , new Se3_F64 ( ) , K2 , calib . getRightToLeft ( ) . invert ( null ) ) ; DMatrixRMaj rect1 = rectifyAlg . getRect1 ( ) ; DMatrixRMaj rect2 = rectifyAlg . getRect2 ( ) ; rectK = rectifyAlg . getCalibrationMatrix ( ) ; rectR = rectifyAlg . getRectifiedRotation ( ) ; // adjust view to maximize viewing area while not including black regions RectifyImageOps . allInsideLeft ( calib . left , rect1 , rect2 , rectK ) ; // compute transforms to apply rectify the images leftRectToPixel = transformRectToPixel ( calib . left , rect1 ) ; ImageType < T > imageType = ImageType . single ( activeAlg . getInputType ( ) ) ; FMatrixRMaj rect1_F32 = new FMatrixRMaj ( 3 , 3 ) ; // TODO simplify code some how FMatrixRMaj rect2_F32 = new FMatrixRMaj ( 3 , 3 ) ; ConvertMatrixData . convert ( rect1 , rect1_F32 ) ; ConvertMatrixData . convert ( rect2 , rect2_F32 ) ; ImageDistort < T , T > distortRect1 = RectifyImageOps . rectifyImage ( calib . left , rect1_F32 , BorderType . SKIP , imageType ) ; ImageDistort < T , T > distortRect2 = RectifyImageOps . rectifyImage ( calib . right , rect2_F32 , BorderType . SKIP , imageType ) ; // rectify and undo distortion distortRect1 . apply ( inputLeft , rectLeft ) ; distortRect2 . apply ( inputRight , rectRight ) ; rectifiedImages = true ; } | Removes distortion and rectifies images . | 482 | 8 |
26,842 | private void changeGuiActive ( final boolean error , final boolean reverse ) { SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { control . setActiveGui ( error , reverse ) ; } } ) ; } | Active and deactivates different GUI configurations | 53 | 8 |
26,843 | public static String guessEncoding ( byte [ ] message ) { // this function is inspired by a similarly named function in ZXing, but was written from scratch // using specifications for each encoding since I didn't understand what they were doing boolean isUtf8 = true ; boolean isJis = true ; boolean isIso = true ; for ( int i = 0 ; i < message . length ; i ++ ) { int v = message [ i ] & 0xFF ; if ( isUtf8 ) isUtf8 = isValidUTF8 ( v ) ; if ( isJis ) isJis = isValidJIS ( v ) ; if ( isIso ) isIso = isValidIso8869_1 ( v ) ; } // System.out.printf("UTF-8=%s ISO=%s JIS=%s\n",isUtf8,isIso,isJis); // If there is ambiguity do it based on how common it is and what the specification says if ( isUtf8 ) return UTF8 ; if ( isIso ) return ISO8859_1 ; if ( isJis ) return JIS ; return UTF8 ; } | The encoding for byte messages should be ISO8859_1 or JIS depending on which version of the specification you follow . In reality people use whatever they want and expect it to magically work . This attempts to figure out if it s ISO8859_1 JIS or UTF8 . UTF - 8 is the most common and is used if its ambiguous . | 255 | 72 |
26,844 | public static < T extends ImageGray < T > > T convert ( ImageGray < ? > src , T dst , Class < T > typeDst ) { if ( dst == null ) { dst = ( T ) GeneralizedImageOps . createSingleBand ( typeDst , src . width , src . height ) ; } else { InputSanityCheck . checkSameShape ( src , dst ) ; } convert ( src , dst ) ; return dst ; } | Converts an image from one type to another type . Creates a new image instance if an output is not provided . | 96 | 24 |
26,845 | public void setTensor ( TrifocalTensor tensor ) { this . tensor = tensor ; if ( ! svd . decompose ( tensor . T1 ) ) throw new RuntimeException ( "SVD failed?!" ) ; SingularOps_DDRM . nullVector ( svd , true , v1 ) ; SingularOps_DDRM . nullVector ( svd , false , u1 ) ; // DMatrixRMaj zero = new DMatrixRMaj(3,1); // CommonOps_DDRM.mult(tensor.T1,v1,zero);zero.print(); // CommonOps_DDRM.multTransA(u1,tensor.T1,zero);zero.print(); if ( ! svd . decompose ( tensor . T2 ) ) throw new RuntimeException ( "SVD failed?!" ) ; SingularOps_DDRM . nullVector ( svd , true , v2 ) ; SingularOps_DDRM . nullVector ( svd , false , u2 ) ; // CommonOps_DDRM.mult(tensor.T2,v2,zero);zero.print(); // CommonOps_DDRM.multTransA(u2,tensor.T2,zero);zero.print(); if ( ! svd . decompose ( tensor . T3 ) ) throw new RuntimeException ( "SVD failed?!" ) ; SingularOps_DDRM . nullVector ( svd , true , v3 ) ; SingularOps_DDRM . nullVector ( svd , false , u3 ) ; // CommonOps_DDRM.mult(tensor.T3,v3,zero);zero.print(); // CommonOps_DDRM.multTransA(u3,tensor.T3,zero);zero.print(); for ( int i = 0 ; i < 3 ; i ++ ) { U . set ( i , 0 , u1 . get ( i ) ) ; U . set ( i , 1 , u2 . get ( i ) ) ; U . set ( i , 2 , u3 . get ( i ) ) ; V . set ( i , 0 , v1 . get ( i ) ) ; V . set ( i , 1 , v2 . get ( i ) ) ; V . set ( i , 2 , v3 . get ( i ) ) ; } svd . decompose ( U ) ; SingularOps_DDRM . nullVector ( svd , false , tempE ) ; e2 . set ( tempE . get ( 0 ) , tempE . get ( 1 ) , tempE . get ( 2 ) ) ; svd . decompose ( V ) ; SingularOps_DDRM . nullVector ( svd , false , tempE ) ; e3 . set ( tempE . get ( 0 ) , tempE . get ( 1 ) , tempE . get ( 2 ) ) ; } | Specifies the input tensor . The epipoles are immediately extracted since they are needed to extract all other data structures | 639 | 24 |
26,846 | public void extractEpipoles ( Point3D_F64 e2 , Point3D_F64 e3 ) { e2 . set ( this . e2 ) ; e3 . set ( this . e3 ) ; } | Extracts the epipoles from the trifocal tensor . Extracted epipoles will have a norm of 1 as an artifact of using SVD . | 49 | 34 |
26,847 | public static < T extends ImageGray < T > > void histogram ( T image , double minPixelValue , double maxPixelValue , TupleDesc_F64 histogram ) { if ( image . getClass ( ) == GrayU8 . class ) { HistogramFeatureOps . histogram ( ( GrayU8 ) image , ( int ) maxPixelValue , histogram ) ; } else if ( image . getClass ( ) == GrayU16 . class ) { HistogramFeatureOps . histogram ( ( GrayU16 ) image , ( int ) maxPixelValue , histogram ) ; } else if ( image . getClass ( ) == GrayF32 . class ) { HistogramFeatureOps . histogram ( ( GrayF32 ) image , ( float ) minPixelValue , ( float ) maxPixelValue , histogram ) ; } else { throw new IllegalArgumentException ( "Unsupported band type" ) ; } } | Computes a single - band normalized histogram for any single band image . | 195 | 15 |
26,848 | public static void histogram ( double [ ] colors , int length , Histogram_F64 histogram ) { if ( length % histogram . getDimensions ( ) != 0 ) throw new IllegalArgumentException ( "Length does not match dimensions" ) ; int coordinate [ ] = new int [ histogram . getDimensions ( ) ] ; histogram . fill ( 0 ) ; for ( int i = 0 ; i < length ; ) { for ( int j = 0 ; j < coordinate . length ; j ++ , i ++ ) { coordinate [ j ] = histogram . getDimensionIndex ( j , colors [ i ] ) ; } int index = histogram . getIndex ( coordinate ) ; histogram . value [ index ] += 1.0 ; } } | Computes a coupled histogram from a list of colors . If the input is for integer values then add one to the maximum value . For example if the range of values is 0 to 255 then make it 0 to 256 . | 161 | 45 |
26,849 | void computePointStatistics ( Point [ ] points ) { final int length = points . length ; double v [ ] = new double [ length ] ; for ( int axis = 0 ; axis < 3 ; axis ++ ) { double maxAbs = 0 ; for ( int i = 0 ; i < length ; i ++ ) { v [ i ] = points [ i ] . coordinate [ axis ] ; maxAbs = Math . max ( maxAbs , Math . abs ( v [ i ] ) ) ; } double median = QuickSelect . select ( v , length / 2 , length ) ; switch ( axis ) { case 0 : medianPoint . x = median ; break ; case 1 : medianPoint . y = median ; break ; case 2 : medianPoint . z = median ; break ; } } for ( int i = 0 ; i < length ; i ++ ) { v [ i ] = points [ i ] . distanceSq ( medianPoint ) ; } medianDistancePoint = Math . sqrt ( QuickSelect . select ( v , length / 2 , length ) ) ; // System.out.println("Median P ="+ medianPoint); // System.out.println("Median R ="+ medianDistancePoint); // System.out.println("Scale ="+ (desiredDistancePoint / medianDistancePoint)); } | For 3D points computes the median value and variance along each dimension . | 276 | 15 |
26,850 | public void undoScale ( SceneStructureMetric structure , SceneObservations observations ) { if ( structure . homogenous ) return ; double scale = desiredDistancePoint / medianDistancePoint ; undoNormPoints3D ( structure , scale ) ; Point3D_F64 c = new Point3D_F64 ( ) ; for ( int i = 0 ; i < structure . views . length ; i ++ ) { SceneStructureMetric . View view = structure . views [ i ] ; // X_w = R'*(X_c - T) let X_c = 0 then X_w = -R'*T is center of camera in world GeometryMath_F64 . multTran ( view . worldToView . R , view . worldToView . T , c ) ; // Apply transform c . x = ( - c . x / scale + medianPoint . x ) ; c . y = ( - c . y / scale + medianPoint . y ) ; c . z = ( - c . z / scale + medianPoint . z ) ; // -R*T GeometryMath_F64 . mult ( view . worldToView . R , c , view . worldToView . T ) ; view . worldToView . T . scale ( - 1 ) ; } } | Undoes scale transform for metric . | 276 | 7 |
26,851 | public boolean apply ( T input , Point2D_F64 corner0 , Point2D_F64 corner1 , Point2D_F64 corner2 , Point2D_F64 corner3 ) { if ( createTransform ( corner0 , corner1 , corner2 , corner3 ) ) { distort . input ( input ) . apply ( ) ; return true ; } else { return false ; } } | Applies distortion removal to the specified region in the input image . The undistorted image is returned . | 85 | 21 |
26,852 | public boolean createTransform ( Point2D_F64 tl , Point2D_F64 tr , Point2D_F64 br , Point2D_F64 bl ) { associatedPairs . get ( 0 ) . p2 . set ( tl ) ; associatedPairs . get ( 1 ) . p2 . set ( tr ) ; associatedPairs . get ( 2 ) . p2 . set ( br ) ; associatedPairs . get ( 3 ) . p2 . set ( bl ) ; if ( ! computeHomography . process ( associatedPairs , H ) ) return false ; // if( !refineHomography.fitModel(associatedPairs,H,Hrefined) ) { // return false; // } // homography.set(Hrefined); ConvertMatrixData . convert ( H , H32 ) ; transform . set ( H32 ) ; return true ; } | Compues the distortion removal transform | 191 | 6 |
26,853 | public static void vertical ( Kernel1D_F32 kernel , GrayF32 image , GrayF32 dest , int skip ) { checkParameters ( image , dest , skip ) ; if ( kernel . width >= image . width ) { ConvolveDownNormalizedNaive . vertical ( kernel , image , dest , skip ) ; } else { ConvolveImageDownNoBorder . vertical ( kernel , image , dest , skip ) ; ConvolveDownNormalized_JustBorder . vertical ( kernel , image , dest , skip ) ; } } | Performs a vertical 1D down convolution across the image while re - normalizing the kernel depending on its overlap with the image . | 110 | 27 |
26,854 | public static void removeRadial ( float x , float y , float [ ] radial , float t1 , float t2 , Point2D_F32 out , float tol ) { float origX = x ; float origY = y ; float prevSum = 0 ; for ( int iter = 0 ; iter < 500 ; iter ++ ) { // estimate the radial distance float r2 = x * x + y * y ; float ri2 = r2 ; float sum = 0 ; for ( int i = 0 ; i < radial . length ; i ++ ) { sum += radial [ i ] * ri2 ; ri2 *= r2 ; } float tx = 2.0f * t1 * x * y + t2 * ( r2 + 2.0f * x * x ) ; float ty = t1 * ( r2 + 2.0f * y * y ) + 2.0f * t2 * x * y ; x = ( origX - tx ) / ( 1.0f + sum ) ; y = ( origY - ty ) / ( 1.0f + sum ) ; if ( ( float ) Math . abs ( prevSum - sum ) <= tol ) { break ; } else { prevSum = sum ; } } out . set ( x , y ) ; } | Static function for removing radial and tangential distortion | 280 | 9 |
26,855 | public boolean process ( EllipseRotated_F64 input , EllipseRotated_F64 refined ) { refined . set ( input ) ; previous . set ( input ) ; for ( int iteration = 0 ; iteration < maxIterations ; iteration ++ ) { refined . set ( previous ) ; computePointsAndWeights ( refined ) ; if ( fitter . process ( samplePts . toList ( ) , weights . data ) ) { // Get the results in local coordinates UtilEllipse_F64 . convert ( fitter . getEllipse ( ) , refined ) ; // convert back into image coordinates double scale = previous . a ; refined . center . x = refined . center . x * scale + previous . center . x ; refined . center . y = refined . center . y * scale + previous . center . y ; refined . a *= scale ; refined . b *= scale ; } else { return false ; } // stop once the change between two iterations is insignificant if ( change ( previous , refined ) <= convergenceTol ) { return true ; } else { previous . set ( refined ) ; } } return true ; } | Refines provided list by snapping it to edges found in the image | 242 | 13 |
26,856 | protected static double change ( EllipseRotated_F64 a , EllipseRotated_F64 b ) { double total = 0 ; total += Math . abs ( a . center . x - b . center . x ) ; total += Math . abs ( a . center . y - b . center . y ) ; total += Math . abs ( a . a - b . a ) ; total += Math . abs ( a . b - b . b ) ; // only care about the change of angle when it is not a circle double weight = Math . min ( 4 , 2.0 * ( a . a / a . b - 1.0 ) ) ; total += weight * UtilAngle . distHalf ( a . phi , b . phi ) ; return total ; } | Computes a numerical value for the difference in parameters between the two ellipses | 168 | 16 |
26,857 | public static < T extends ImageGray < T > > MonocularPlaneVisualOdometry < T > monoPlaneInfinity ( int thresholdAdd , int thresholdRetire , double inlierPixelTol , int ransacIterations , PointTracker < T > tracker , ImageType < T > imageType ) { //squared pixel error double ransacTOL = inlierPixelTol * inlierPixelTol ; ModelManagerSe2_F64 manager = new ModelManagerSe2_F64 ( ) ; DistancePlane2DToPixelSq distance = new DistancePlane2DToPixelSq ( ) ; GenerateSe2_PlanePtPixel generator = new GenerateSe2_PlanePtPixel ( ) ; ModelMatcher < Se2_F64 , PlanePtPixel > motion = new Ransac <> ( 2323 , manager , generator , distance , ransacIterations , ransacTOL ) ; VisOdomMonoPlaneInfinity < T > alg = new VisOdomMonoPlaneInfinity <> ( thresholdAdd , thresholdRetire , inlierPixelTol , motion , tracker ) ; return new MonoPlaneInfinity_to_MonocularPlaneVisualOdometry <> ( alg , distance , generator , imageType ) ; } | Monocular plane based visual odometry algorithm which uses both points on the plane and off plane for motion estimation . | 286 | 22 |
26,858 | public static < T extends ImageGray < T > > MonocularPlaneVisualOdometry < T > monoPlaneOverhead ( double cellSize , double maxCellsPerPixel , double mapHeightFraction , double inlierGroundTol , int ransacIterations , int thresholdRetire , int absoluteMinimumTracks , double respawnTrackFraction , double respawnCoverageFraction , PointTracker < T > tracker , ImageType < T > imageType ) { ImageMotion2D < T , Se2_F64 > motion2D = FactoryMotion2D . createMotion2D ( ransacIterations , inlierGroundTol * inlierGroundTol , thresholdRetire , absoluteMinimumTracks , respawnTrackFraction , respawnCoverageFraction , false , tracker , new Se2_F64 ( ) ) ; VisOdomMonoOverheadMotion2D < T > alg = new VisOdomMonoOverheadMotion2D <> ( cellSize , maxCellsPerPixel , mapHeightFraction , motion2D , imageType ) ; return new MonoOverhead_to_MonocularPlaneVisualOdometry <> ( alg , imageType ) ; } | Monocular plane based visual odometry algorithm which creates a synthetic overhead view and tracks image features inside this synthetic view . | 257 | 23 |
26,859 | public static < T extends ImageGray < T > > StereoVisualOdometry < T > stereoDepth ( double inlierPixelTol , int thresholdAdd , int thresholdRetire , int ransacIterations , int refineIterations , boolean doublePass , StereoDisparitySparse < T > sparseDisparity , PointTrackerTwoPass < T > tracker , Class < T > imageType ) { // Range from sparse disparity StereoSparse3D < T > pixelTo3D = new StereoSparse3D <> ( sparseDisparity , imageType ) ; Estimate1ofPnP estimator = FactoryMultiView . pnp_1 ( EnumPNP . P3P_FINSTERWALDER , - 1 , 2 ) ; final DistanceFromModelMultiView < Se3_F64 , Point2D3D > distance = new PnPDistanceReprojectionSq ( ) ; ModelManagerSe3_F64 manager = new ModelManagerSe3_F64 ( ) ; EstimatorToGenerator < Se3_F64 , Point2D3D > generator = new EstimatorToGenerator <> ( estimator ) ; // 1/2 a pixel tolerance for RANSAC inliers double ransacTOL = inlierPixelTol * inlierPixelTol ; ModelMatcher < Se3_F64 , Point2D3D > motion = new Ransac <> ( 2323 , manager , generator , distance , ransacIterations , ransacTOL ) ; RefinePnP refine = null ; if ( refineIterations > 0 ) { refine = FactoryMultiView . pnpRefine ( 1e-12 , refineIterations ) ; } VisOdomPixelDepthPnP < T > alg = new VisOdomPixelDepthPnP <> ( thresholdAdd , thresholdRetire , doublePass , motion , pixelTo3D , refine , tracker , null , null ) ; return new WrapVisOdomPixelDepthPnP <> ( alg , pixelTo3D , distance , imageType ) ; } | Stereo vision based visual odometry algorithm which runs a sparse feature tracker in the left camera and estimates the range of tracks once when first detected using disparity between left and right cameras . | 455 | 36 |
26,860 | public static < Vis extends ImageGray < Vis > , Depth extends ImageGray < Depth > > DepthVisualOdometry < Vis , Depth > depthDepthPnP ( double inlierPixelTol , int thresholdAdd , int thresholdRetire , int ransacIterations , int refineIterations , boolean doublePass , DepthSparse3D < Depth > sparseDepth , PointTrackerTwoPass < Vis > tracker , Class < Vis > visualType , Class < Depth > depthType ) { // Range from sparse disparity ImagePixelTo3D pixelTo3D = new DepthSparse3D_to_PixelTo3D <> ( sparseDepth ) ; Estimate1ofPnP estimator = FactoryMultiView . pnp_1 ( EnumPNP . P3P_FINSTERWALDER , - 1 , 2 ) ; final DistanceFromModelMultiView < Se3_F64 , Point2D3D > distance = new PnPDistanceReprojectionSq ( ) ; ModelManagerSe3_F64 manager = new ModelManagerSe3_F64 ( ) ; EstimatorToGenerator < Se3_F64 , Point2D3D > generator = new EstimatorToGenerator <> ( estimator ) ; // 1/2 a pixel tolerance for RANSAC inliers double ransacTOL = inlierPixelTol * inlierPixelTol ; ModelMatcher < Se3_F64 , Point2D3D > motion = new Ransac <> ( 2323 , manager , generator , distance , ransacIterations , ransacTOL ) ; RefinePnP refine = null ; if ( refineIterations > 0 ) { refine = FactoryMultiView . pnpRefine ( 1e-12 , refineIterations ) ; } VisOdomPixelDepthPnP < Vis > alg = new VisOdomPixelDepthPnP <> ( thresholdAdd , thresholdRetire , doublePass , motion , pixelTo3D , refine , tracker , null , null ) ; return new VisOdomPixelDepthPnP_to_DepthVisualOdometry <> ( sparseDepth , alg , distance , ImageType . single ( visualType ) , depthType ) ; } | Depth sensor based visual odometry algorithm which runs a sparse feature tracker in the visual camera and estimates the range of tracks once when first detected using the depth sensor . | 481 | 32 |
26,861 | public static < T extends ImageGray < T > , Desc extends TupleDesc > StereoVisualOdometry < T > stereoDualTrackerPnP ( int thresholdAdd , int thresholdRetire , double inlierPixelTol , double epipolarPixelTol , int ransacIterations , int refineIterations , PointTracker < T > trackerLeft , PointTracker < T > trackerRight , DescribeRegionPoint < T , Desc > descriptor , Class < T > imageType ) { EstimateNofPnP pnp = FactoryMultiView . pnp_N ( EnumPNP . P3P_FINSTERWALDER , - 1 ) ; DistanceFromModelMultiView < Se3_F64 , Point2D3D > distanceMono = new PnPDistanceReprojectionSq ( ) ; PnPStereoDistanceReprojectionSq distanceStereo = new PnPStereoDistanceReprojectionSq ( ) ; PnPStereoEstimator pnpStereo = new PnPStereoEstimator ( pnp , distanceMono , 0 ) ; ModelManagerSe3_F64 manager = new ModelManagerSe3_F64 ( ) ; EstimatorToGenerator < Se3_F64 , Stereo2D3D > generator = new EstimatorToGenerator <> ( pnpStereo ) ; // Pixel tolerance for RANSAC inliers - euclidean error squared from left + right images double ransacTOL = 2 * inlierPixelTol * inlierPixelTol ; ModelMatcher < Se3_F64 , Stereo2D3D > motion = new Ransac <> ( 2323 , manager , generator , distanceStereo , ransacIterations , ransacTOL ) ; RefinePnPStereo refinePnP = null ; Class < Desc > descType = descriptor . getDescriptionType ( ) ; ScoreAssociation < Desc > scorer = FactoryAssociation . defaultScore ( descType ) ; AssociateStereo2D < Desc > associateStereo = new AssociateStereo2D <> ( scorer , epipolarPixelTol , descType ) ; // need to make sure associations are unique AssociateDescription2D < Desc > associateUnique = associateStereo ; if ( ! associateStereo . uniqueDestination ( ) || ! associateStereo . uniqueSource ( ) ) { associateUnique = new EnforceUniqueByScore . Describe2D <> ( associateStereo , true , true ) ; } if ( refineIterations > 0 ) { refinePnP = new PnPStereoRefineRodrigues ( 1e-12 , refineIterations ) ; } Triangulate2ViewsMetric triangulate = FactoryMultiView . triangulate2ViewMetric ( new ConfigTriangulation ( ConfigTriangulation . Type . GEOMETRIC ) ) ; VisOdomDualTrackPnP < T , Desc > alg = new VisOdomDualTrackPnP <> ( thresholdAdd , thresholdRetire , epipolarPixelTol , trackerLeft , trackerRight , descriptor , associateUnique , triangulate , motion , refinePnP ) ; return new WrapVisOdomDualTrackPnP <> ( pnpStereo , distanceMono , distanceStereo , associateStereo , alg , refinePnP , imageType ) ; } | Creates a stereo visual odometry algorithm that independently tracks features in left and right camera . | 733 | 18 |
26,862 | public static void computeCameraControl ( double beta [ ] , List < Point3D_F64 > nullPts [ ] , FastQueue < Point3D_F64 > cameraPts , int numControl ) { cameraPts . reset ( ) ; for ( int i = 0 ; i < numControl ; i ++ ) { cameraPts . grow ( ) . set ( 0 , 0 , 0 ) ; } for ( int i = 0 ; i < numControl ; i ++ ) { double b = beta [ i ] ; // System.out.printf("%7.3f ", b); for ( int j = 0 ; j < numControl ; j ++ ) { Point3D_F64 s = cameraPts . get ( j ) ; Point3D_F64 p = nullPts [ i ] . get ( j ) ; s . x += b * p . x ; s . y += b * p . y ; s . z += b * p . z ; } } } | Computes the camera control points as weighted sum of null points . | 213 | 13 |
26,863 | public static void constraintMatrix6x3 ( DMatrixRMaj L_6x10 , DMatrixRMaj L_6x3 ) { int index = 0 ; for ( int i = 0 ; i < 6 ; i ++ ) { L_6x3 . data [ index ++ ] = L_6x10 . get ( i , 0 ) ; L_6x3 . data [ index ++ ] = L_6x10 . get ( i , 1 ) ; L_6x3 . data [ index ++ ] = L_6x10 . get ( i , 4 ) ; } } | Extracts the linear constraint matrix for case 2 from the full 6x10 constraint matrix . | 129 | 19 |
26,864 | public static void constraintMatrix6x6 ( DMatrixRMaj L_6x10 , DMatrixRMaj L_6x6 ) { int index = 0 ; for ( int i = 0 ; i < 6 ; i ++ ) { L_6x6 . data [ index ++ ] = L_6x10 . get ( i , 0 ) ; L_6x6 . data [ index ++ ] = L_6x10 . get ( i , 1 ) ; L_6x6 . data [ index ++ ] = L_6x10 . get ( i , 2 ) ; L_6x6 . data [ index ++ ] = L_6x10 . get ( i , 4 ) ; L_6x6 . data [ index ++ ] = L_6x10 . get ( i , 5 ) ; L_6x6 . data [ index ++ ] = L_6x10 . get ( i , 7 ) ; } } | Extracts the linear constraint matrix for case 3 from the full 6x10 constraint matrix . | 204 | 19 |
26,865 | public static void constraintMatrix3x3 ( DMatrixRMaj L_3x6 , DMatrixRMaj L_6x3 ) { int index = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { L_6x3 . data [ index ++ ] = L_3x6 . get ( i , 0 ) ; L_6x3 . data [ index ++ ] = L_3x6 . get ( i , 1 ) ; L_6x3 . data [ index ++ ] = L_3x6 . get ( i , 3 ) ; } } | Extracts the linear constraint matrix for planar case 2 from the full 4x6 constraint matrix . | 129 | 21 |
26,866 | public static void constraintMatrix3x6 ( DMatrixRMaj L , DMatrixRMaj y , FastQueue < Point3D_F64 > controlWorldPts , List < Point3D_F64 > nullPts [ ] ) { int row = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { Point3D_F64 ci = controlWorldPts . get ( i ) ; Point3D_F64 vai = nullPts [ 0 ] . get ( i ) ; Point3D_F64 vbi = nullPts [ 1 ] . get ( i ) ; Point3D_F64 vci = nullPts [ 2 ] . get ( i ) ; for ( int j = i + 1 ; j < 3 ; j ++ , row ++ ) { Point3D_F64 cj = controlWorldPts . get ( j ) ; Point3D_F64 vaj = nullPts [ 0 ] . get ( j ) ; Point3D_F64 vbj = nullPts [ 1 ] . get ( j ) ; Point3D_F64 vcj = nullPts [ 2 ] . get ( j ) ; y . set ( row , 0 , ci . distance2 ( cj ) ) ; double xa = vai . x - vaj . x ; double ya = vai . y - vaj . y ; double za = vai . z - vaj . z ; double xb = vbi . x - vbj . x ; double yb = vbi . y - vbj . y ; double zb = vbi . z - vbj . z ; double xc = vci . x - vcj . x ; double yc = vci . y - vcj . y ; double zc = vci . z - vcj . z ; double da = xa * xa + ya * ya + za * za ; double db = xb * xb + yb * yb + zb * zb ; double dc = xc * xc + yc * yc + zc * zc ; double dab = xa * xb + ya * yb + za * zb ; double dac = xa * xc + ya * yc + za * zc ; double dbc = xb * xc + yb * yc + zb * zc ; L . set ( row , 0 , da ) ; L . set ( row , 1 , 2 * dab ) ; L . set ( row , 2 , 2 * dac ) ; L . set ( row , 3 , db ) ; L . set ( row , 4 , 2 * dbc ) ; L . set ( row , 5 , dc ) ; } } } | Linear constraint matrix for case 4 in the planar case | 607 | 12 |
26,867 | public static void jacobian_Control4 ( DMatrixRMaj L_full , double beta [ ] , DMatrixRMaj A ) { int indexA = 0 ; double b0 = beta [ 0 ] ; double b1 = beta [ 1 ] ; double b2 = beta [ 2 ] ; double b3 = beta [ 3 ] ; final double ld [ ] = L_full . data ; for ( int i = 0 ; i < 6 ; i ++ ) { int li = L_full . numCols * i ; A . data [ indexA ++ ] = 2 * ld [ li + 0 ] * b0 + ld [ li + 1 ] * b1 + ld [ li + 2 ] * b2 + ld [ li + 3 ] * b3 ; A . data [ indexA ++ ] = ld [ li + 1 ] * b0 + 2 * ld [ li + 4 ] * b1 + ld [ li + 5 ] * b2 + ld [ li + 6 ] * b3 ; A . data [ indexA ++ ] = ld [ li + 2 ] * b0 + ld [ li + 5 ] * b1 + 2 * ld [ li + 7 ] * b2 + ld [ li + 8 ] * b3 ; A . data [ indexA ++ ] = ld [ li + 3 ] * b0 + ld [ li + 6 ] * b1 + ld [ li + 8 ] * b2 + 2 * ld [ li + 9 ] * b3 ; } } | Computes the Jacobian given 4 control points . | 338 | 10 |
26,868 | public static void jacobian_Control3 ( DMatrixRMaj L_full , double beta [ ] , DMatrixRMaj A ) { int indexA = 0 ; double b0 = beta [ 0 ] ; double b1 = beta [ 1 ] ; double b2 = beta [ 2 ] ; final double ld [ ] = L_full . data ; for ( int i = 0 ; i < 3 ; i ++ ) { int li = L_full . numCols * i ; A . data [ indexA ++ ] = 2 * ld [ li + 0 ] * b0 + ld [ li + 1 ] * b1 + ld [ li + 2 ] * b2 ; A . data [ indexA ++ ] = ld [ li + 1 ] * b0 + 2 * ld [ li + 3 ] * b1 + ld [ li + 4 ] * b2 ; A . data [ indexA ++ ] = ld [ li + 2 ] * b0 + ld [ li + 4 ] * b1 + 2 * ld [ li + 5 ] * b2 ; } } | Computes the Jacobian given 3 control points . | 241 | 10 |
26,869 | public void process ( ImagePyramid < T > pyramidPrev , ImagePyramid < T > pyramidCurr ) { InputSanityCheck . checkSameShape ( pyramidPrev , pyramidCurr ) ; int numLayers = pyramidPrev . getNumLayers ( ) ; for ( int i = numLayers - 1 ; i >= 0 ; i -- ) { T prev = pyramidPrev . getLayer ( i ) ; T curr = pyramidCurr . getLayer ( i ) ; flowCurrLayer . reshape ( prev . width , prev . height ) ; int N = prev . width * prev . height ; if ( scores . length < N ) scores = new float [ N ] ; // mark all the scores as being very large so that if it has not been processed its score // will be set inside of checkNeighbors. Arrays . fill ( scores , 0 , N , Float . MAX_VALUE ) ; int x1 = prev . width - regionRadius ; int y1 = prev . height - regionRadius ; if ( i == numLayers - 1 ) { // the top most layer in the pyramid has no hint for ( int y = regionRadius ; y < y1 ; y ++ ) { for ( int x = regionRadius ; x < x1 ; x ++ ) { extractTemplate ( x , y , prev ) ; float score = findFlow ( x , y , curr , tmp ) ; if ( tmp . isValid ( ) ) checkNeighbors ( x , y , tmp , flowCurrLayer , score ) ; else flowCurrLayer . unsafe_get ( x , y ) . markInvalid ( ) ; } } } else { // for all the other layers use the hint of the previous layer to start its search double scale = pyramidPrev . getScale ( i + 1 ) / pyramidPrev . getScale ( i ) ; for ( int y = regionRadius ; y < y1 ; y ++ ) { for ( int x = regionRadius ; x < x1 ; x ++ ) { // grab the flow in higher level pyramid ImageFlow . D p = flowPrevLayer . get ( ( int ) ( x / scale ) , ( int ) ( y / scale ) ) ; if ( ! p . isValid ( ) ) continue ; // get the template around the current point in this layer extractTemplate ( x , y , prev ) ; // add the flow from the higher layer (adjusting for scale and rounding) as the start of // this search int deltaX = ( int ) ( p . x * scale + 0.5 ) ; int deltaY = ( int ) ( p . y * scale + 0.5 ) ; int startX = x + deltaX ; int startY = y + deltaY ; float score = findFlow ( startX , startY , curr , tmp ) ; // find flow only does it relative to the starting point tmp . x += deltaX ; tmp . y += deltaY ; if ( tmp . isValid ( ) ) checkNeighbors ( x , y , tmp , flowCurrLayer , score ) ; else flowCurrLayer . unsafe_get ( x , y ) . markInvalid ( ) ; } } } // swap the flow images ImageFlow tmp = flowPrevLayer ; flowPrevLayer = flowCurrLayer ; flowCurrLayer = tmp ; } } | Computes the optical flow form prev to curr and stores the output into output | 703 | 16 |
26,870 | public void setDirection ( double yaw , double pitch , double roll ) { ConvertRotation3D_F64 . eulerToMatrix ( EulerType . YZX , pitch , yaw , roll , R ) ; } | Specifies the rotation offset from the canonical location using yaw and pitch . | 49 | 15 |
26,871 | protected void declareVectors ( int width , int height ) { this . outWidth = width ; if ( vectors . length < width * height ) { Point3D_F64 [ ] tmp = new Point3D_F64 [ width * height ] ; System . arraycopy ( vectors , 0 , tmp , 0 , vectors . length ) ; for ( int i = vectors . length ; i < tmp . length ; i ++ ) { tmp [ i ] = new Point3D_F64 ( ) ; } vectors = tmp ; } } | Declares storage for precomputed pointing vectors to output image | 114 | 12 |
26,872 | public void polyScale ( GrowQueue_I8 input , int scale , GrowQueue_I8 output ) { output . resize ( input . size ) ; for ( int i = 0 ; i < input . size ; i ++ ) { output . data [ i ] = ( byte ) multiply ( input . data [ i ] & 0xFF , scale ) ; } } | Scales the polynomial . | 77 | 7 |
26,873 | public void polyAdd ( GrowQueue_I8 polyA , GrowQueue_I8 polyB , GrowQueue_I8 output ) { output . resize ( Math . max ( polyA . size , polyB . size ) ) ; // compute offset that would align the smaller polynomial with the larger polynomial int offsetA = Math . max ( 0 , polyB . size - polyA . size ) ; int offsetB = Math . max ( 0 , polyA . size - polyB . size ) ; int N = output . size ; for ( int i = 0 ; i < offsetB ; i ++ ) { output . data [ i ] = polyA . data [ i ] ; } for ( int i = 0 ; i < offsetA ; i ++ ) { output . data [ i ] = polyB . data [ i ] ; } for ( int i = Math . max ( offsetA , offsetB ) ; i < N ; i ++ ) { output . data [ i ] = ( byte ) ( ( polyA . data [ i - offsetA ] & 0xFF ) ^ ( polyB . data [ i - offsetB ] & 0xFF ) ) ; } } | Adds two polynomials together . output = polyA + polyB | 251 | 15 |
26,874 | public void polyAdd_S ( GrowQueue_I8 polyA , GrowQueue_I8 polyB , GrowQueue_I8 output ) { output . resize ( Math . max ( polyA . size , polyB . size ) ) ; int M = Math . min ( polyA . size , polyB . size ) ; for ( int i = M ; i < polyA . size ; i ++ ) { output . data [ i ] = polyA . data [ i ] ; } for ( int i = M ; i < polyB . size ; i ++ ) { output . data [ i ] = polyB . data [ i ] ; } for ( int i = 0 ; i < M ; i ++ ) { output . data [ i ] = ( byte ) ( ( polyA . data [ i ] & 0xFF ) ^ ( polyB . data [ i ] & 0xFF ) ) ; } } | Adds two polynomials together . | 194 | 8 |
26,875 | public void polyAddScaleB ( GrowQueue_I8 polyA , GrowQueue_I8 polyB , int scaleB , GrowQueue_I8 output ) { output . resize ( Math . max ( polyA . size , polyB . size ) ) ; // compute offset that would align the smaller polynomial with the larger polynomial int offsetA = Math . max ( 0 , polyB . size - polyA . size ) ; int offsetB = Math . max ( 0 , polyA . size - polyB . size ) ; int N = output . size ; for ( int i = 0 ; i < offsetB ; i ++ ) { output . data [ i ] = polyA . data [ i ] ; } for ( int i = 0 ; i < offsetA ; i ++ ) { output . data [ i ] = ( byte ) multiply ( polyB . data [ i ] & 0xFF , scaleB ) ; } for ( int i = Math . max ( offsetA , offsetB ) ; i < N ; i ++ ) { output . data [ i ] = ( byte ) ( ( polyA . data [ i - offsetA ] & 0xFF ) ^ multiply ( polyB . data [ i - offsetB ] & 0xFF , scaleB ) ) ; } } | Adds two polynomials together while scaling the second . | 274 | 12 |
26,876 | public int polyEval ( GrowQueue_I8 input , int x ) { int y = input . data [ 0 ] & 0xFF ; for ( int i = 1 ; i < input . size ; i ++ ) { y = multiply ( y , x ) ^ ( input . data [ i ] & 0xFF ) ; } return y ; } | Evaluate the polynomial using Horner s method . Avoids explicit calculating the powers of x . | 75 | 22 |
26,877 | public int polyEvalContinue ( int previousOutput , GrowQueue_I8 part , int x ) { int y = previousOutput ; for ( int i = 0 ; i < part . size ; i ++ ) { y = multiply ( y , x ) ^ ( part . data [ i ] & 0xFF ) ; } return y ; } | Continue evaluating a polynomial which has been broken up into multiple arrays . | 72 | 15 |
26,878 | public void polyDivide ( GrowQueue_I8 dividend , GrowQueue_I8 divisor , GrowQueue_I8 quotient , GrowQueue_I8 remainder ) { // handle special case if ( divisor . size > dividend . size ) { remainder . setTo ( dividend ) ; quotient . resize ( 0 ) ; return ; } else { remainder . resize ( divisor . size - 1 ) ; quotient . setTo ( dividend ) ; } int normalizer = divisor . data [ 0 ] & 0xFF ; int N = dividend . size - divisor . size + 1 ; for ( int i = 0 ; i < N ; i ++ ) { quotient . data [ i ] = ( byte ) divide ( quotient . data [ i ] & 0xFF , normalizer ) ; int coef = quotient . data [ i ] & 0xFF ; if ( coef != 0 ) { // division by zero is undefined. for ( int j = 1 ; j < divisor . size ; j ++ ) { // skip the first coeffient in synthetic division int div_j = divisor . data [ j ] & 0xFF ; if ( div_j != 0 ) { // log(0) is undefined. quotient . data [ i + j ] ^= multiply ( div_j , coef ) ; } } } } // quotient currently contains the quotient and remainder. Copy remainder into it's own polynomial System . arraycopy ( quotient . data , quotient . size - remainder . size , remainder . data , 0 , remainder . size ) ; quotient . size -= remainder . size ; } | Performs polynomial division using a synthetic division algorithm . | 355 | 12 |
26,879 | public static ConfigQrCode fast ( ) { // A global threshold is faster than any local algorithm // plus it will generate a simpler set of internal contours speeding up that process ConfigQrCode config = new ConfigQrCode ( ) ; config . threshold = ConfigThreshold . global ( ThresholdType . GLOBAL_OTSU ) ; return config ; } | Default configuration for a QR Code detector which is optimized for speed | 76 | 12 |
26,880 | private void drawDistribution ( Graphics2D g2 , List < Point2D_F64 > candidates , int offX , int offY , double scale ) { findStatistics ( ) ; // draw all the features, adjusting their size based on the first score g2 . setColor ( Color . RED ) ; g2 . setStroke ( new BasicStroke ( 3 ) ) ; double normalizer ; if ( scorer . getScoreType ( ) . isZeroBest ( ) ) normalizer = best * containmentFraction ; else normalizer = Math . abs ( best ) * ( Math . exp ( - 1.0 / containmentFraction ) ) ; for ( int i = 0 ; i < candidates . size ( ) ; i ++ ) { Point2D_F64 p = candidates . get ( i ) ; double s = associationScore [ i ] ; // scale the circle based on how bad it is double ratio = 1 - Math . abs ( s - best ) / normalizer ; if ( ratio < 0 ) continue ; int r = maxCircleRadius - ( int ) ( maxCircleRadius * ratio ) ; if ( r > 0 ) { int x = ( int ) ( p . x * scale + offX ) ; int y = ( int ) ( p . y * scale + offY ) ; g2 . drawOval ( x - r , y - r , r * 2 + 1 , r * 2 + 1 ) ; } } // draw the best feature g2 . setColor ( Color . GREEN ) ; g2 . setStroke ( new BasicStroke ( 10 ) ) ; int w = maxCircleRadius * 2 + 1 ; Point2D_F64 p = candidates . get ( indexBest ) ; int x = ( int ) ( p . x * scale + offX ) ; int y = ( int ) ( p . y * scale + offY ) ; g2 . drawOval ( x - maxCircleRadius , y - maxCircleRadius , w , w ) ; } | Visualizes score distribution . Larger circles mean its closer to the best fit score . | 436 | 17 |
26,881 | public void process ( List < ChessboardCorner > corners ) { this . corners = corners ; // reset internal data structures vertexes . reset ( ) ; edges . reset ( ) ; clusters . reset ( ) ; // Create a vertex for each corner for ( int idx = 0 ; idx < corners . size ( ) ; idx ++ ) { Vertex v = vertexes . grow ( ) ; v . reset ( ) ; v . index = idx ; } // Initialize nearest-neighbor search. nn . setPoints ( corners , true ) ; // Connect corners to each other based on relative distance on orientation for ( int i = 0 ; i < corners . size ( ) ; i ++ ) { findVertexNeighbors ( vertexes . get ( i ) , corners ) ; } // If more than one vertex's are near each other, pick one and remove the others handleAmbiguousVertexes ( corners ) ; // printDualGraph(); // Prune connections which are not mutual for ( int i = 0 ; i < vertexes . size ; i ++ ) { Vertex v = vertexes . get ( i ) ; v . pruneNonMutal ( EdgeType . PARALLEL ) ; v . pruneNonMutal ( EdgeType . PERPENDICULAR ) ; } // printDualGraph(); // Select the final 2 to 4 connections from perpendicular set // each pair of adjacent perpendicular edge needs to have a matching parallel edge between them // Use each perpendicular edge as a seed and select the best one for ( int idx = 0 ; idx < vertexes . size ( ) ; idx ++ ) { selectConnections ( vertexes . get ( idx ) ) ; } // printConnectionGraph(); // Connects must be mutual to be accepted. Keep track of vertexes which were modified dirtyVertexes . clear ( ) ; for ( int i = 0 ; i < vertexes . size ; i ++ ) { Vertex v = vertexes . get ( i ) ; int before = v . connections . size ( ) ; v . pruneNonMutal ( EdgeType . CONNECTION ) ; if ( before != v . connections . size ( ) ) { dirtyVertexes . add ( v ) ; v . marked = true ; } } // printConnectionGraph(); // attempt to recover from poorly made decisions in the past from the greedy algorithm repairVertexes ( ) ; // Prune non-mutual edges again. Only need to consider dirty edges since it makes sure that the new // set of connections is a super set of the old for ( int i = 0 ; i < dirtyVertexes . size ( ) ; i ++ ) { dirtyVertexes . get ( i ) . pruneNonMutal ( EdgeType . CONNECTION ) ; dirtyVertexes . get ( i ) . marked = false ; } // Final clean up to return just valid grids disconnectInvalidVertices ( ) ; // Name says it all convertToOutput ( corners ) ; } | Processes corners and finds clusters of chessboard patterns | 629 | 10 |
26,882 | public void printDualGraph ( ) { System . out . println ( "============= Dual" ) ; int l = BoofMiscOps . numDigits ( vertexes . size ) ; String format = "%" + l + "d" ; for ( Vertex n : vertexes . toList ( ) ) { ChessboardCorner c = corners . get ( n . index ) ; System . out . printf ( "[" + format + "] {%3.0f, %3.0f} -> 90[ " , n . index , c . x , c . y ) ; for ( int i = 0 ; i < n . perpendicular . size ( ) ; i ++ ) { Edge e = n . perpendicular . get ( i ) ; System . out . printf ( format + " " , e . dst . index ) ; } System . out . println ( "]" ) ; System . out . print ( " -> 180[ " ) ; for ( int i = 0 ; i < n . parallel . size ( ) ; i ++ ) { Edge e = n . parallel . get ( i ) ; System . out . printf ( format + " " , e . dst . index ) ; } System . out . println ( "]" ) ; } } | Prints the graph . Used for debugging the code . | 265 | 11 |
26,883 | void findVertexNeighbors ( Vertex target , List < ChessboardCorner > corners ) { // if( target.index == 18 ) { // System.out.println("Vertex Neighbors "+target.index); // } ChessboardCorner targetCorner = corners . get ( target . index ) ; // distance is Euclidean squared double maxDist = Double . MAX_VALUE == maxNeighborDistance ? maxNeighborDistance : maxNeighborDistance * maxNeighborDistance ; nnSearch . findNearest ( corners . get ( target . index ) , maxDist , maxNeighbors , nnResults ) ; // storage distances here to find median distance of closest neighbors distanceTmp . reset ( ) ; for ( int i = 0 ; i < nnResults . size ; i ++ ) { NnData < ChessboardCorner > r = nnResults . get ( i ) ; if ( r . index == target . index ) continue ; distanceTmp . add ( r . distance ) ; double oriDiff = UtilAngle . distHalf ( targetCorner . orientation , r . point . orientation ) ; Edge edge = edges . grow ( ) ; boolean parallel ; if ( oriDiff <= orientationTol ) { // see if it's parallel parallel = true ; } else if ( Math . abs ( oriDiff - Math . PI / 2.0 ) <= orientationTol ) { // see if it's perpendicular parallel = false ; } else { edges . removeTail ( ) ; continue ; } // Use the relative angles of orientation and direction to prune more obviously bad matches double dx = r . point . x - targetCorner . x ; double dy = r . point . y - targetCorner . y ; edge . distance = Math . sqrt ( r . distance ) ; edge . dst = vertexes . get ( r . index ) ; edge . direction = Math . atan2 ( dy , dx ) ; double direction180 = UtilAngle . boundHalf ( edge . direction ) ; double directionDiff = UtilAngle . distHalf ( direction180 , r . point . orientation ) ; boolean remove ; EdgeSet edgeSet ; if ( parallel ) { // test to see if direction and orientation are aligned or off by 90 degrees remove = directionDiff > 2 * directionTol && Math . abs ( directionDiff - Math . PI / 2.0 ) > 2 * directionTol ; edgeSet = target . parallel ; } else { // should be at 45 degree angle remove = Math . abs ( directionDiff - Math . PI / 4.0 ) > 2 * directionTol ; edgeSet = target . perpendicular ; } if ( remove ) { edges . removeTail ( ) ; continue ; } edgeSet . add ( edge ) ; } // Compute the distance of the closest neighbors. This is used later on to identify ambiguous corners. // If it's a graph corner there should be at least 3 right next to the node. if ( distanceTmp . size == 0 ) { target . neighborDistance = 0 ; } else { sorter . sort ( distanceTmp . data , distanceTmp . size ) ; int idx = Math . min ( 3 , distanceTmp . size - 1 ) ; target . neighborDistance = Math . sqrt ( distanceTmp . data [ idx ] ) ; // NN distance is Euclidean squared } } | Use nearest neighbor search to find closest corners . Split those into two groups parallel and perpendicular . | 711 | 18 |
26,884 | void handleAmbiguousVertexes ( List < ChessboardCorner > corners ) { List < Vertex > candidates = new ArrayList <> ( ) ; for ( int idx = 0 ; idx < vertexes . size ( ) ; idx ++ ) { Vertex target = vertexes . get ( idx ) ; // median distance was previously found based on the closer neighbors. In an actual chessboard // there are solid white and black squares with no features, in theory double threshold = target . neighborDistance * ambiguousTol ; candidates . clear ( ) ; // only need to search parallel since perpendicular nodes won't be confused for the target for ( int i = 0 ; i < target . parallel . size ( ) ; i ++ ) { Edge c = target . parallel . get ( i ) ; if ( c . distance <= threshold ) { candidates . add ( c . dst ) ; } } if ( candidates . size ( ) > 0 ) { candidates . add ( target ) ; int bestIndex = - 1 ; double bestScore = 0 ; // System.out.println("==== Resolving ambiguity. src="+target.index); for ( int i = 0 ; i < candidates . size ( ) ; i ++ ) { Vertex v = candidates . get ( i ) ; // System.out.println(" candidate = "+v.index); double intensity = corners . get ( v . index ) . intensity ; if ( intensity > bestScore ) { bestScore = intensity ; bestIndex = i ; } } // System.out.println("==== Resolved ambiguity. Selected "+candidates.get(bestIndex).index); for ( int i = 0 ; i < candidates . size ( ) ; i ++ ) { if ( i == bestIndex ) continue ; removeReferences ( candidates . get ( i ) , EdgeType . PARALLEL ) ; removeReferences ( candidates . get ( i ) , EdgeType . PERPENDICULAR ) ; } } } } | Identify ambiguous vertexes which are too close to each other . Select the corner with the highest intensity score and remove the rest | 410 | 25 |
26,885 | void disconnectInvalidVertices ( ) { // add elements with 1 or 2 edges openVertexes . clear ( ) ; for ( int idxVert = 0 ; idxVert < vertexes . size ; idxVert ++ ) { Vertex n = vertexes . get ( idxVert ) ; if ( n . connections . size ( ) == 1 || n . connections . size ( ) == 2 ) { openVertexes . add ( n ) ; } } // continue until there are no changes while ( ! openVertexes . isEmpty ( ) ) { dirtyVertexes . clear ( ) ; for ( int idxVert = 0 ; idxVert < openVertexes . size ( ) ; idxVert ++ ) { boolean remove = false ; Vertex n = openVertexes . get ( idxVert ) ; if ( n . connections . size ( ) == 1 ) { remove = true ; } else if ( n . connections . size ( ) == 2 ) { Edge ea = n . connections . get ( 0 ) ; Edge eb = n . connections . get ( 1 ) ; // Look for a common vertex that isn't 'n' remove = true ; for ( int i = 0 ; i < ea . dst . connections . size ( ) ; i ++ ) { Vertex va = ea . dst . connections . get ( i ) . dst ; if ( va == n ) continue ; for ( int j = 0 ; j < eb . dst . connections . size ( ) ; j ++ ) { Vertex vb = ea . dst . connections . get ( j ) . dst ; if ( va == vb ) { remove = false ; break ; } } } } if ( remove ) { // only go through the subset referenced the disconnected. Yes there could be duplicates // not worth the time to fix that for ( int i = 0 ; i < n . connections . size ( ) ; i ++ ) { dirtyVertexes . add ( n . connections . get ( i ) . dst ) ; } removeReferences ( n , EdgeType . CONNECTION ) ; } } openVertexes . clear ( ) ; openVertexes . addAll ( dirtyVertexes ) ; } } | Disconnect the edges from invalid vertices . Invalid ones have only one edge or two edges which do not connect to a common vertex i . e . they are point 180 degrees away from each other . | 470 | 40 |
26,886 | void removeReferences ( Vertex remove , EdgeType type ) { EdgeSet removeSet = remove . getEdgeSet ( type ) ; for ( int i = removeSet . size ( ) - 1 ; i >= 0 ; i -- ) { Vertex v = removeSet . get ( i ) . dst ; EdgeSet setV = v . getEdgeSet ( type ) ; // remove the connection from v to 'remove'. Be careful since the connection isn't always mutual // at this point int ridx = setV . find ( remove ) ; if ( ridx != - 1 ) setV . edges . remove ( ridx ) ; } removeSet . reset ( ) ; } | Go through all the vertexes that remove is connected to and remove that link . if it is in the connected list swap it with replaceWith . | 140 | 29 |
26,887 | void selectConnections ( Vertex target ) { // There needs to be at least two corners if ( target . perpendicular . size ( ) <= 1 ) return ; // if( target.index == 16 ) { // System.out.println("ASDSAD"); // } // System.out.println("======= Connecting "+target.index); double bestError = Double . MAX_VALUE ; List < Edge > bestSolution = target . connections . edges ; // Greedily select one vertex at a time to connect to. findNext() looks at all possible // vertexes it can connect too and minimizes an error function based on projectively invariant features for ( int i = 0 ; i < target . perpendicular . size ( ) ; i ++ ) { Edge e = target . perpendicular . get ( i ) ; solution . clear ( ) ; solution . add ( e ) ; double sumDistance = solution . get ( 0 ) . distance ; double minDistance = sumDistance ; if ( ! findNext ( i , target . parallel , target . perpendicular , Double . NaN , results ) ) { continue ; } solution . add ( target . perpendicular . get ( results . index ) ) ; sumDistance += solution . get ( 1 ) . distance ; minDistance = Math . min ( minDistance , solution . get ( 1 ) . distance ) ; // Use knowledge that solution[0] and solution[2] form a line. // Lines are straight under projective distortion if ( findNext ( results . index , target . parallel , target . perpendicular , solution . get ( 0 ) . direction , results ) ) { solution . add ( target . perpendicular . get ( results . index ) ) ; sumDistance += solution . get ( 2 ) . distance ; minDistance = Math . min ( minDistance , solution . get ( 2 ) . distance ) ; // Use knowledge that solution[1] and solution[3] form a line. if ( findNext ( results . index , target . parallel , target . perpendicular , solution . get ( 1 ) . direction , results ) ) { solution . add ( target . perpendicular . get ( results . index ) ) ; sumDistance += solution . get ( 3 ) . distance ; minDistance = Math . min ( minDistance , solution . get ( 3 ) . distance ) ; } } // Prefer closer valid sets of edges and larger sets. // the extra + minDistance was needed to bias it against smaller sets which would be more likely // to have a smaller average error. Division by the square of set/solution size biases it towards larger sets double error = ( sumDistance + minDistance ) / ( solution . size ( ) * solution . size ( ) ) ; // System.out.println(" first="+solution.get(0).dst.index+" size="+solution.size()+" error="+error); if ( error < bestError ) { bestError = error ; bestSolution . clear ( ) ; bestSolution . addAll ( solution ) ; } } } | Select the best 2 3 or 4 perpendicular vertexes to connect to . These are the output grid connections . | 627 | 21 |
26,888 | boolean findNext ( int firstIdx , EdgeSet splitterSet , EdgeSet candidateSet , double parallel , SearchResults results ) { Edge e0 = candidateSet . get ( firstIdx ) ; results . index = - 1 ; results . error = Double . MAX_VALUE ; boolean checkParallel = ! Double . isNaN ( parallel ) ; for ( int i = 0 ; i < candidateSet . size ( ) ; i ++ ) { if ( i == firstIdx ) continue ; // stop considering edges when they are more than 180 degrees away Edge eI = candidateSet . get ( i ) ; double distanceCCW = UtilAngle . distanceCCW ( e0 . direction , eI . direction ) ; if ( distanceCCW >= Math . PI * 0.9 ) // Multiplying by 0.9 helped remove a lot of bad matches continue ; // It was pairing up opposite corners under heavy perspective distortion // It should be parallel to a previously found line if ( checkParallel ) { double a = UtilAngle . boundHalf ( eI . direction ) ; double b = UtilAngle . boundHalf ( parallel ) ; double distanceParallel = UtilAngle . distHalf ( a , b ) ; if ( distanceParallel > parallelTol ) { continue ; } } // find the perpendicular corner which splits these two edges and also find the index of // the perpendicular sets which points towards the splitter. if ( ! findSplitter ( e0 . direction , eI . direction , splitterSet , e0 . dst . perpendicular , eI . dst . perpendicular , tuple3 ) ) continue ; double acute0 = UtilAngle . dist ( candidateSet . get ( firstIdx ) . direction , e0 . dst . perpendicular . get ( tuple3 . b ) . direction ) ; double error0 = UtilAngle . dist ( acute0 , Math . PI / 2.0 ) ; if ( error0 > Math . PI * 0.3 ) continue ; double acute1 = UtilAngle . dist ( candidateSet . get ( i ) . direction , eI . dst . perpendicular . get ( tuple3 . c ) . direction ) ; double error1 = UtilAngle . dist ( acute1 , Math . PI / 2.0 ) ; if ( error1 > Math . PI * 0.3 ) continue ; // Find the edge from corner 0 to corner i. The direction of this vector and the corner's // orientation has a known relationship described by 'phaseOri' int e0_to_eI = e0 . dst . parallel . find ( eI . dst ) ; if ( e0_to_eI < 0 ) continue ; // The quadrilateral with the smallest area is most often the best solution. Area is more expensive // so the perimeter is computed instead. one side is left off since all of them have that side double error = e0 . dst . perpendicular . get ( tuple3 . b ) . distance ; error += eI . dst . perpendicular . get ( tuple3 . c ) . distance ; error += eI . distance ; if ( error < results . error ) { results . error = error ; results . index = i ; } } return results . index != - 1 ; } | Greedily select the next edge that will belong to the final graph . | 690 | 15 |
26,889 | boolean findSplitter ( double ccw0 , double ccw1 , EdgeSet master , EdgeSet other1 , EdgeSet other2 , TupleI32 output ) { double bestDistance = Double . MAX_VALUE ; for ( int i = 0 ; i < master . size ( ) ; i ++ ) { // select the splitter Edge me = master . get ( i ) ; // TODO decide if this is helpful or not // check that it lies between these two angles if ( UtilAngle . distanceCCW ( ccw0 , me . direction ) > Math . PI * 0.9 || UtilAngle . distanceCW ( ccw1 , me . direction ) > Math . PI * 0.9 ) continue ; // Find indexes which point towards the splitter corner int idxB = other1 . find ( me . dst ) ; if ( idxB == - 1 ) continue ; double thetaB = UtilAngle . distanceCCW ( ccw0 , other1 . get ( idxB ) . direction ) ; if ( thetaB < 0.05 ) continue ; int idxC = other2 . find ( me . dst ) ; if ( idxC == - 1 ) continue ; double thetaC = UtilAngle . distanceCW ( ccw1 , other2 . get ( idxC ) . direction ) ; if ( thetaC < 0.05 ) continue ; // want it to be closer and without parallel lines double error = me . distance / ( 0.5 + Math . min ( thetaB , thetaC ) ) ; if ( error < bestDistance ) { bestDistance = error ; output . a = i ; output . b = idxB ; output . c = idxC ; } } // Reject the best solution if it doesn't form a convex quadrilateral if ( bestDistance < Double . MAX_VALUE ) { // 2 is CCW of 1, and since both of them are pointing towards the splitter we know // how to compute the angular distance double pointingB = other1 . edges . get ( output . b ) . direction ; double pointingC = other2 . edges . get ( output . c ) . direction ; return UtilAngle . distanceCW ( pointingB , pointingC ) < Math . PI ; } else { return false ; } } | Splitter is a vertex that has an angle between two edges being considered . | 496 | 15 |
26,890 | private void repairVertexes ( ) { // System.out.println("######## Repair"); for ( int idxV = 0 ; idxV < dirtyVertexes . size ( ) ; idxV ++ ) { final Vertex v = dirtyVertexes . get ( idxV ) ; // System.out.println(" dirty="+v.index); bestSolution . clear ( ) ; for ( int idxE = 0 ; idxE < v . perpendicular . size ( ) ; idxE ++ ) { // Assume this edge is in the solutions Edge e = v . perpendicular . get ( idxE ) ; // only can connect new modified vertexes or ones already connected too if ( ! ( e . dst . marked || - 1 != v . connections . find ( e . dst ) ) ) { continue ; } // System.out.println(" e[0].dst = "+e.dst.index); solution . clear ( ) ; solution . add ( e ) ; // search for connections until there's no more to be found for ( int count = 0 ; count < 3 ; count ++ ) { // Find the an edge which is about to 90 degrees CCW of the previous edge 'v' Vertex va = null ; double dir90 = UtilAngle . bound ( e . direction + Math . PI / 2.0 ) ; for ( int i = 0 ; i < e . dst . connections . size ( ) ; i ++ ) { Edge ei = e . dst . connections . get ( i ) ; if ( UtilAngle . dist ( ei . direction , dir90 ) < Math . PI / 3 ) { va = ei . dst ; break ; } } // Search for an edge in v which has a connection to 'va' and is ccw of 'e' boolean matched = false ; for ( int i = 0 ; i < v . perpendicular . size ( ) ; i ++ ) { Edge ei = v . perpendicular . get ( i ) ; if ( e == ei ) continue ; // angle test double ccw = UtilAngle . distanceCCW ( e . direction , ei . direction ) ; if ( ccw > Math . PI * 0.9 ) continue ; if ( ! ( ei . dst . marked || - 1 != v . connections . find ( ei . dst ) ) ) { continue ; } // connection test if ( ei . dst . connections . find ( va ) != - 1 ) { // System.out.println(" e[i].dst = "+ei.dst.index+" va="+va.index); e = ei ; solution . add ( ei ) ; matched = true ; break ; } } if ( ! matched ) break ; } if ( solution . size ( ) > bestSolution . size ( ) ) { bestSolution . clear ( ) ; bestSolution . addAll ( solution ) ; } } if ( bestSolution . size ( ) > 1 ) { // See if any connection that was there before is now gone. If that's the case the destination // will need to be checked for mutual matches for ( int i = 0 ; i < v . connections . edges . size ( ) ; i ++ ) { if ( ! bestSolution . contains ( v . connections . edges . get ( i ) ) ) { v . connections . edges . get ( i ) . dst . marked = true ; break ; } } // Save the new connections v . connections . edges . clear ( ) ; v . connections . edges . addAll ( bestSolution ) ; } } } | Given the current graph attempt to replace edges from vertexes which lost them in an apparent bad decision . This is a very simple algorithm and gives up if the graph around the current node is less than perfect . | 757 | 41 |
26,891 | private void convertToOutput ( List < ChessboardCorner > corners ) { c2n . resize ( corners . size ( ) ) ; n2c . resize ( vertexes . size ( ) ) ; open . reset ( ) ; n2c . fill ( - 1 ) ; c2n . fill ( - 1 ) ; for ( int seedIdx = 0 ; seedIdx < vertexes . size ; seedIdx ++ ) { Vertex seedN = vertexes . get ( seedIdx ) ; if ( seedN . marked ) continue ; ChessboardCornerGraph graph = clusters . grow ( ) ; graph . reset ( ) ; // traverse the graph and add all the nodes in this cluster growCluster ( corners , seedIdx , graph ) ; // Connect the nodes together in the output graph for ( int i = 0 ; i < graph . corners . size ; i ++ ) { ChessboardCornerGraph . Node gn = graph . corners . get ( i ) ; Vertex n = vertexes . get ( n2c . get ( i ) ) ; for ( int j = 0 ; j < n . connections . size ( ) ; j ++ ) { int edgeCornerIdx = n . connections . get ( j ) . dst . index ; int outputIdx = c2n . get ( edgeCornerIdx ) ; if ( outputIdx == - 1 ) { throw new IllegalArgumentException ( "Edge to node not in the graph. n.idx=" + n . index + " conn.idx=" + edgeCornerIdx ) ; } gn . edges [ j ] = graph . corners . get ( outputIdx ) ; } } // ensure arrays are all -1 again for sanity checks for ( int i = 0 ; i < graph . corners . size ; i ++ ) { ChessboardCornerGraph . Node gn = graph . corners . get ( i ) ; int indexCorner = n2c . get ( gn . index ) ; c2n . data [ indexCorner ] = - 1 ; n2c . data [ gn . index ] = - 1 ; } if ( graph . corners . size <= 1 ) clusters . removeTail ( ) ; } } | Converts the internal graphs into unordered chessboard grids . | 469 | 12 |
26,892 | private void growCluster ( List < ChessboardCorner > corners , int seedIdx , ChessboardCornerGraph graph ) { // open contains corner list indexes open . add ( seedIdx ) ; while ( open . size > 0 ) { int cornerIdx = open . pop ( ) ; Vertex v = vertexes . get ( cornerIdx ) ; // make sure it hasn't already been processed if ( v . marked ) continue ; v . marked = true ; // Create the node in the output cluster for this corner ChessboardCornerGraph . Node gn = graph . growCorner ( ) ; c2n . data [ cornerIdx ] = gn . index ; n2c . data [ gn . index ] = cornerIdx ; gn . set ( corners . get ( cornerIdx ) ) ; // Add to the open list all the edges which haven't been processed yet; for ( int i = 0 ; i < v . connections . size ( ) ; i ++ ) { Vertex dst = v . connections . get ( i ) . dst ; if ( dst . marked ) continue ; open . add ( dst . index ) ; } } } | Given the initial seed add all connected nodes to the output cluster while keeping track of how to convert one node index into another one between the two graphs | 244 | 29 |
26,893 | public void setTransform ( PixelTransform < Point2D_F32 > undistToDist ) { if ( undistToDist != null ) { InterpolatePixelS < T > interpolate = FactoryInterpolation . bilinearPixelS ( imageType , BorderType . EXTENDED ) ; integralImage = new GImageGrayDistorted <> ( undistToDist , interpolate ) ; } else { integralImage = FactoryGImageGray . create ( imageType ) ; } } | Used to specify a transform that is applied to pixel coordinates to bring them back into original input image coordinates . For example if the input image has lens distortion but the edge were found in undistorted coordinates this code needs to know how to go from undistorted back into distorted image coordinates in order to read the pixel s value . | 103 | 66 |
26,894 | public void process ( Point3D_F64 e2 , Point3D_F64 e3 , DMatrixRMaj A ) { // construct the linear system that the solution which solves the unknown square // matrices in the camera matrices constructE ( e2 , e3 ) ; // Computes U, which is used to map the 18 unknowns onto the 27 trifocal unknowns svdU . decompose ( E ) ; svdU . getU ( U , false ) ; // Copy the parts of U which correspond to the non singular parts if the SVD // since there are only really 18-nullity unknowns due to linear dependencies SingularOps_DDRM . descendingOrder ( U , false , svdU . getSingularValues ( ) , svdU . numberOfSingularValues ( ) , null , false ) ; int rank = SingularOps_DDRM . rank ( svdU , 1e-13 ) ; Up . reshape ( U . numRows , rank ) ; CommonOps_DDRM . extract ( U , 0 , U . numRows , 0 , Up . numCols , Up , 0 , 0 ) ; // project the linear constraint matrix into this subspace AU . reshape ( A . numRows , Up . numCols ) ; CommonOps_DDRM . mult ( A , Up , AU ) ; // Extract the solution of ||A*U*x|| = 0 from the null space svdV . decompose ( AU ) ; xp . reshape ( rank , 1 ) ; SingularOps_DDRM . nullVector ( svdV , true , xp ) ; // Translate the solution from the subspace and into a valid trifocal tensor CommonOps_DDRM . mult ( Up , xp , vectorT ) ; // the sign of vectorT is arbitrary, but make it positive for consistency if ( vectorT . data [ 0 ] > 0 ) CommonOps_DDRM . changeSign ( vectorT ) ; } | Computes a trifocal tensor which minimizes the algebraic error given the two epipoles and the linear constraint matrix . The epipoles are from a previously computed trifocal tensor . | 431 | 42 |
26,895 | protected void constructE ( Point3D_F64 e2 , Point3D_F64 e3 ) { E . zero ( ) ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { for ( int k = 0 ; k < 3 ; k ++ ) { // which element in the trifocal tensor is being manipulated int row = 9 * i + 3 * j + k ; // which unknowns are being multiplied by int col1 = j * 3 + i ; int col2 = k * 3 + i + 9 ; E . data [ row * 18 + col1 ] = e3 . getIdx ( k ) ; E . data [ row * 18 + col2 ] = - e2 . getIdx ( j ) ; } } } } | The matrix E is a linear system for computing the trifocal tensor . The columns are the unknown square matrices from view 2 and 3 . The right most column in both projection matrices are the provided epipoles whose values are inserted into E | 180 | 51 |
26,896 | public TrifocalTensor copy ( ) { TrifocalTensor ret = new TrifocalTensor ( ) ; ret . T1 . set ( T1 ) ; ret . T2 . set ( T2 ) ; ret . T3 . set ( T3 ) ; return ret ; } | Returns a new copy of the TrifocalTensor | 63 | 11 |
26,897 | public void setImages ( Input left , Input right ) { InputSanityCheck . checkSameShape ( left , right ) ; this . left = left ; this . right = right ; } | Specify inputs for left and right camera images . | 39 | 10 |
26,898 | protected < T extends ImageBase > ImageType < T > getImageType ( int which ) { synchronized ( inputStreams ) { return inputStreams . get ( which ) . imageType ; } } | Get input input type for a stream safely | 42 | 8 |
26,899 | private void updateRecentItems ( ) { if ( menuRecent == null ) return ; menuRecent . removeAll ( ) ; List < String > recentFiles = BoofSwingUtil . getListOfRecentFiles ( this ) ; for ( String filePath : recentFiles ) { final File f = new File ( filePath ) ; JMenuItem recentItem = new JMenuItem ( f . getName ( ) ) ; recentItem . addActionListener ( new ActionListener ( ) { @ Override public void actionPerformed ( ActionEvent e ) { openFile ( f ) ; } } ) ; menuRecent . add ( recentItem ) ; } } | Updates the list in recent menu | 136 | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.