idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
26,700 | public void start ( Device device , Resolution resolution , Listener listener ) { if ( resolution != Resolution . MEDIUM ) { throw new IllegalArgumentException ( "Depth image is always at medium resolution. Possible bug in kinect driver" ) ; } this . device = device ; this . listener = listener ; device . setDepthFormat ( DepthFormat . REGISTERED , resolution ) ; device . setVideoFormat ( VideoFormat . RGB , resolution ) ; int w = UtilOpenKinect . getWidth ( resolution ) ; int h = UtilOpenKinect . getHeight ( resolution ) ; dataDepth = new byte [ w * h * 2 ] ; dataRgb = new byte [ w * h * 3 ] ; depth . reshape ( w , h ) ; rgb . reshape ( w , h ) ; thread = new CombineThread ( ) ; thread . start ( ) ; while ( ! thread . running ) Thread . yield ( ) ; device . startDepth ( new DepthHandler ( ) { public void onFrameReceived ( FrameMode mode , ByteBuffer frame , int timestamp ) { processDepth ( frame , timestamp ) ; } } ) ; device . startVideo ( new VideoHandler ( ) { public void onFrameReceived ( FrameMode mode , ByteBuffer frame , int timestamp ) { processRgb ( frame , timestamp ) ; } } ) ; } | Adds listeners to the device and sets its resolutions . |
26,701 | public void stop ( ) { thread . requestStop = true ; long start = System . currentTimeMillis ( ) + timeout ; while ( start > System . currentTimeMillis ( ) && thread . running ) Thread . yield ( ) ; device . stopDepth ( ) ; device . stopVideo ( ) ; device . close ( ) ; } | Stops all the threads from running and closes the video channels and video device |
26,702 | public boolean refine ( List < CameraPinhole > calibration , DMatrix4x4 Q ) { if ( calibration . size ( ) != cameras . size ) throw new RuntimeException ( "Calibration and cameras do not match" ) ; computeNumberOfCalibrationParameters ( ) ; func = new ResidualK ( ) ; if ( func . getNumOfInputsN ( ) > 6 * calibration . size ( ) ) throw new IllegalArgumentException ( "Need more views to refine. eqs=" + ( 3 * calibration . size ( ) + " unknowns=" + func . getNumOfInputsN ( ) ) ) ; ConvertDMatrixStruct . convert ( Q , _Q ) ; nullspace . process ( _Q , 1 , p ) ; CommonOps_DDRM . divide ( p , p . get ( 3 ) ) ; p . numRows = 3 ; encode ( calibration , p , param ) ; optimizer . setFunction ( func , null ) ; optimizer . initialize ( param . data , converge . ftol , converge . gtol ) ; if ( ! UtilOptimize . process ( optimizer , converge . maxIterations ) ) return false ; decode ( optimizer . getParameters ( ) , calibration , p ) ; recomputeQ ( p , Q ) ; return true ; } | Refine calibration matrix K given the dual absolute quadratic Q . |
26,703 | void recomputeQ ( DMatrixRMaj p , DMatrix4x4 Q ) { Equation eq = new Equation ( ) ; DMatrix3x3 K = new DMatrix3x3 ( ) ; encodeK ( K , 0 , 3 , param . data ) ; eq . alias ( p , "p" , K , "K" ) ; eq . process ( "w=K*K'" ) ; eq . process ( "Q=[w , -w*p;-p'*w , p'*w*p]" ) ; DMatrixRMaj _Q = eq . lookupDDRM ( "Q" ) ; CommonOps_DDRM . divide ( _Q , NormOps_DDRM . normF ( _Q ) ) ; ConvertDMatrixStruct . convert ( _Q , Q ) ; } | Compuets the absolute dual quadratic from the first camera parameters and plane at infinity |
26,704 | public int encodeK ( DMatrix3x3 K , int which , int offset , double params [ ] ) { if ( fixedAspectRatio ) { K . a11 = params [ offset ++ ] ; K . a22 = aspect . data [ which ] * K . a11 ; } else { K . a11 = params [ offset ++ ] ; K . a22 = params [ offset ++ ] ; } if ( ! zeroSkew ) { K . a12 = params [ offset ++ ] ; } if ( ! zeroPrinciplePoint ) { K . a13 = params [ offset ++ ] ; K . a23 = params [ offset ++ ] ; } K . a33 = 1 ; return offset ; } | Encode the calibration as a 3x3 matrix . K is assumed to zero initially or at least all non - zero elements will align with values that are written to . |
26,705 | public void initializeMerge ( int numRegions ) { mergeList . resize ( numRegions ) ; for ( int i = 0 ; i < numRegions ; i ++ ) mergeList . data [ i ] = i ; } | Must call before any other functions . |
26,706 | public void performMerge ( GrayS32 pixelToRegion , GrowQueue_I32 regionMemberCount ) { flowIntoRootNode ( regionMemberCount ) ; setToRootNodeNewID ( regionMemberCount ) ; BinaryImageOps . relabel ( pixelToRegion , mergeList . data ) ; } | Merges regions together and updates the provided data structures for said changes . |
26,707 | protected void flowIntoRootNode ( GrowQueue_I32 regionMemberCount ) { rootID . resize ( regionMemberCount . size ) ; int count = 0 ; for ( int i = 0 ; i < mergeList . size ; i ++ ) { int p = mergeList . data [ i ] ; if ( p == i ) { rootID . data [ i ] = count ++ ; continue ; } int gp = mergeList . data [ p ] ; while ( gp != p ) { p = gp ; gp = mergeList . data [ p ] ; } regionMemberCount . data [ p ] += regionMemberCount . data [ i ] ; mergeList . data [ i ] = p ; } } | For each region in the merge list which is not a root node find its root node and add to the root node its member count and set the index in mergeList to the root node . If a node is a root node just note what its new ID will be after all the other segments are removed . |
26,708 | protected void setToRootNodeNewID ( GrowQueue_I32 regionMemberCount ) { tmpMemberCount . reset ( ) ; for ( int i = 0 ; i < mergeList . size ; i ++ ) { int p = mergeList . data [ i ] ; if ( p == i ) { mergeList . data [ i ] = rootID . data [ i ] ; tmpMemberCount . add ( regionMemberCount . data [ i ] ) ; } else { mergeList . data [ i ] = rootID . data [ mergeList . data [ i ] ] ; } } regionMemberCount . reset ( ) ; regionMemberCount . addAll ( tmpMemberCount ) ; } | Does much of the work needed to remove the redundant segments that are being merged into their root node . The list of member count is updated . mergeList is updated with the new segment IDs . |
26,709 | public static RefineEpipolar homographyRefine ( double tol , int maxIterations , EpipolarError type ) { ModelObservationResidualN residuals ; switch ( type ) { case SIMPLE : residuals = new HomographyResidualTransfer ( ) ; break ; case SAMPSON : residuals = new HomographyResidualSampson ( ) ; break ; default : throw new IllegalArgumentException ( "Type not supported: " + type ) ; } return new LeastSquaresHomography ( tol , maxIterations , residuals ) ; } | Creates a non - linear optimizer for refining estimates of homography matrices . |
26,710 | public static RefineEpipolar fundamentalRefine ( double tol , int maxIterations , EpipolarError type ) { switch ( type ) { case SAMPSON : return new LeastSquaresFundamental ( tol , maxIterations , true ) ; case SIMPLE : return new LeastSquaresFundamental ( tol , maxIterations , false ) ; } throw new IllegalArgumentException ( "Type not supported: " + type ) ; } | Creates a non - linear optimizer for refining estimates of fundamental or essential matrices . |
26,711 | public static EstimateNofPnP pnp_N ( EnumPNP which , int numIterations ) { MotionTransformPoint < Se3_F64 , Point3D_F64 > motionFit = FitSpecialEuclideanOps_F64 . fitPoints3D ( ) ; switch ( which ) { case P3P_GRUNERT : P3PGrunert grunert = new P3PGrunert ( PolynomialOps . createRootFinder ( 5 , RootFinderType . STURM ) ) ; return new WrapP3PLineDistance ( grunert , motionFit ) ; case P3P_FINSTERWALDER : P3PFinsterwalder finster = new P3PFinsterwalder ( PolynomialOps . createRootFinder ( 4 , RootFinderType . STURM ) ) ; return new WrapP3PLineDistance ( finster , motionFit ) ; case EPNP : Estimate1ofPnP epnp = pnp_1 ( which , numIterations , 0 ) ; return new Estimate1toNofPnP ( epnp ) ; case IPPE : Estimate1ofEpipolar H = FactoryMultiView . homographyTLS ( ) ; return new Estimate1toNofPnP ( new IPPE_to_EstimatePnP ( H ) ) ; } throw new IllegalArgumentException ( "Type " + which + " not known" ) ; } | Creates an estimator for the PnP problem that uses only three observations which is the minimal case and known as P3P . |
26,712 | public static Estimate1ofPnP pnp_1 ( EnumPNP which , int numIterations , int numTest ) { if ( which == EnumPNP . EPNP ) { PnPLepetitEPnP alg = new PnPLepetitEPnP ( 0.1 ) ; alg . setNumIterations ( numIterations ) ; return new WrapPnPLepetitEPnP ( alg ) ; } else if ( which == EnumPNP . IPPE ) { Estimate1ofEpipolar H = FactoryMultiView . homographyTLS ( ) ; return new IPPE_to_EstimatePnP ( H ) ; } FastQueue < Se3_F64 > solutions = new FastQueue < > ( 4 , Se3_F64 . class , true ) ; return new EstimateNto1ofPnP ( pnp_N ( which , - 1 ) , solutions , numTest ) ; } | Created an estimator for the P3P problem that selects a single solution by considering additional observations . |
26,713 | public static Estimate1ofPnP computePnPwithEPnP ( int numIterations , double magicNumber ) { PnPLepetitEPnP alg = new PnPLepetitEPnP ( magicNumber ) ; alg . setNumIterations ( numIterations ) ; return new WrapPnPLepetitEPnP ( alg ) ; } | Returns a solution to the PnP problem for 4 or more points using EPnP . Fast and fairly accurate algorithm . Can handle general and planar scenario automatically . |
26,714 | public static < K extends Kernel2D > SteerableKernel < K > gaussian ( Class < K > kernelType , int orderX , int orderY , double sigma , int radius ) { if ( orderX < 0 || orderX > 4 ) throw new IllegalArgumentException ( "derivX must be from 0 to 4 inclusive." ) ; if ( orderY < 0 || orderY > 4 ) throw new IllegalArgumentException ( "derivT must be from 0 to 4 inclusive." ) ; int order = orderX + orderY ; if ( order > 4 ) { throw new IllegalArgumentException ( "The total order of x and y can't be greater than 4" ) ; } int maxOrder = Math . max ( orderX , orderY ) ; if ( sigma <= 0 ) sigma = ( float ) FactoryKernelGaussian . sigmaForRadius ( radius , maxOrder ) ; else if ( radius <= 0 ) radius = FactoryKernelGaussian . radiusForSigma ( sigma , maxOrder ) ; Class kernel1DType = FactoryKernel . get1DType ( kernelType ) ; Kernel1D kerX = FactoryKernelGaussian . derivativeK ( kernel1DType , orderX , sigma , radius ) ; Kernel1D kerY = FactoryKernelGaussian . derivativeK ( kernel1DType , orderY , sigma , radius ) ; Kernel2D kernel = GKernelMath . convolve ( kerY , kerX ) ; Kernel2D [ ] basis = new Kernel2D [ order + 1 ] ; ImageGray image = GKernelMath . convertToImage ( kernel ) ; ImageGray imageRotated = ( ImageGray ) image . createNew ( image . width , image . height ) ; basis [ 0 ] = kernel ; double angleStep = Math . PI / basis . length ; for ( int index = 1 ; index <= order ; index ++ ) { float angle = ( float ) ( angleStep * index ) ; GImageMiscOps . fill ( imageRotated , 0 ) ; new FDistort ( image , imageRotated ) . rotate ( angle ) . apply ( ) ; basis [ index ] = GKernelMath . convertToKernel ( imageRotated ) ; } SteerableKernel < K > ret ; if ( kernelType == Kernel2D_F32 . class ) ret = ( SteerableKernel < K > ) new SteerableKernel_F32 ( ) ; else ret = ( SteerableKernel < K > ) new SteerableKernel_I32 ( ) ; ret . setBasis ( FactorySteerCoefficients . polynomial ( order ) , basis ) ; return ret ; } | Steerable filter for 2D Gaussian derivatives . The basis is composed of a set of rotated kernels . |
26,715 | public void process ( GrayU8 input ) { removedWatersheds = false ; output . reshape ( input . width + 2 , input . height + 2 ) ; distance . reshape ( input . width + 2 , input . height + 2 ) ; ImageMiscOps . fill ( output , INIT ) ; ImageMiscOps . fill ( distance , 0 ) ; fifo . reset ( ) ; sortPixels ( input ) ; currentLabel = 0 ; for ( int i = 0 ; i < histogram . length ; i ++ ) { GrowQueue_I32 level = histogram [ i ] ; if ( level . size == 0 ) continue ; for ( int j = 0 ; j < level . size ; j ++ ) { int index = level . data [ j ] ; output . data [ index ] = MASK ; assignNewToNeighbors ( index ) ; } currentDistance = 1 ; fifo . add ( MARKER_PIXEL ) ; while ( true ) { int p = fifo . popHead ( ) ; if ( p == MARKER_PIXEL ) { if ( fifo . isEmpty ( ) ) break ; else { fifo . add ( MARKER_PIXEL ) ; currentDistance ++ ; p = fifo . popHead ( ) ; } } checkNeighborsAssign ( p ) ; } for ( int j = 0 ; j < level . size ; j ++ ) { int index = level . get ( j ) ; distance . data [ index ] = 0 ; if ( output . data [ index ] == MASK ) { currentLabel ++ ; fifo . add ( index ) ; output . data [ index ] = currentLabel ; while ( ! fifo . isEmpty ( ) ) { checkNeighborsMasks ( fifo . popHead ( ) ) ; } } } } } | Perform watershed segmentation on the provided input image . New basins are created at each local minima . |
26,716 | protected void sortPixels ( GrayU8 input ) { for ( int i = 0 ; i < histogram . length ; i ++ ) { histogram [ i ] . reset ( ) ; } for ( int y = 0 ; y < input . height ; y ++ ) { int index = input . startIndex + y * input . stride ; int indexOut = ( y + 1 ) * output . stride + 1 ; for ( int x = 0 ; x < input . width ; x ++ , index ++ , indexOut ++ ) { int value = input . data [ index ] & 0xFF ; histogram [ value ] . add ( indexOut ) ; } } } | Very fast histogram based sorting . Index of each pixel is placed inside a list for its intensity level . |
26,717 | public static int numDigits ( int number ) { if ( number == 0 ) return 1 ; int adjustment = 0 ; if ( number < 0 ) { adjustment = 1 ; number = - number ; } return adjustment + ( int ) Math . log10 ( number ) + 1 ; } | Returns the number of digits in a number . E . g . 345 = 3 - 345 = 4 0 = 1 |
26,718 | public static void boundRectangleInside ( ImageBase b , ImageRectangle r ) { if ( r . x0 < 0 ) r . x0 = 0 ; if ( r . x1 > b . width ) r . x1 = b . width ; if ( r . y0 < 0 ) r . y0 = 0 ; if ( r . y1 > b . height ) r . y1 = b . height ; } | Bounds the provided rectangle to be inside the image . |
26,719 | public static boolean checkInside ( ImageBase b , int x , int y , int radius ) { if ( x - radius < 0 ) return false ; if ( x + radius >= b . width ) return false ; if ( y - radius < 0 ) return false ; if ( y + radius >= b . height ) return false ; return true ; } | Returns true if the point is contained inside the image and radius away from the image border . |
26,720 | public static void pause ( long milli ) { final Thread t = Thread . currentThread ( ) ; long start = System . currentTimeMillis ( ) ; while ( System . currentTimeMillis ( ) - start < milli ) { synchronized ( t ) { try { long target = milli - ( System . currentTimeMillis ( ) - start ) ; if ( target > 0 ) t . wait ( target ) ; } catch ( InterruptedException ignore ) { } } } } | Invokes wait until the elapsed time has passed . In the thread is interrupted the interrupt is ignored . |
26,721 | private void processStream ( CameraPinholeBrown intrinsic , SimpleImageSequence < GrayU8 > sequence , ImagePanel gui , long pauseMilli ) { Font font = new Font ( "Serif" , Font . BOLD , 24 ) ; Se3_F64 fiducialToCamera = new Se3_F64 ( ) ; int frameNumber = 0 ; while ( sequence . hasNext ( ) ) { long before = System . currentTimeMillis ( ) ; GrayU8 input = sequence . next ( ) ; BufferedImage buffered = sequence . getGuiImage ( ) ; try { detector . detect ( input ) ; } catch ( RuntimeException e ) { System . err . println ( "BUG!!! saving image to crash_image.png" ) ; UtilImageIO . saveImage ( buffered , "crash_image.png" ) ; throw e ; } Graphics2D g2 = buffered . createGraphics ( ) ; for ( int i = 0 ; i < detector . totalFound ( ) ; i ++ ) { detector . getFiducialToCamera ( i , fiducialToCamera ) ; long id = detector . getId ( i ) ; double width = detector . getWidth ( i ) ; VisualizeFiducial . drawCube ( fiducialToCamera , intrinsic , width , 3 , g2 ) ; VisualizeFiducial . drawLabelCenter ( fiducialToCamera , intrinsic , "" + id , g2 ) ; } saveResults ( frameNumber ++ ) ; if ( intrinsicPath == null ) { g2 . setColor ( Color . RED ) ; g2 . setFont ( font ) ; g2 . drawString ( "Uncalibrated" , 10 , 20 ) ; } gui . setImage ( buffered ) ; long after = System . currentTimeMillis ( ) ; long time = Math . max ( 0 , pauseMilli - ( after - before ) ) ; if ( time > 0 ) { try { Thread . sleep ( time ) ; } catch ( InterruptedException ignore ) { } } } } | Displays a continuous stream of images |
26,722 | private void processImage ( CameraPinholeBrown intrinsic , BufferedImage buffered , ImagePanel gui ) { Font font = new Font ( "Serif" , Font . BOLD , 24 ) ; GrayU8 gray = new GrayU8 ( buffered . getWidth ( ) , buffered . getHeight ( ) ) ; ConvertBufferedImage . convertFrom ( buffered , gray ) ; Se3_F64 fiducialToCamera = new Se3_F64 ( ) ; try { detector . detect ( gray ) ; } catch ( RuntimeException e ) { System . err . println ( "BUG!!! saving image to crash_image.png" ) ; UtilImageIO . saveImage ( buffered , "crash_image.png" ) ; throw e ; } Graphics2D g2 = buffered . createGraphics ( ) ; for ( int i = 0 ; i < detector . totalFound ( ) ; i ++ ) { detector . getFiducialToCamera ( i , fiducialToCamera ) ; long id = detector . getId ( i ) ; double width = detector . getWidth ( i ) ; VisualizeFiducial . drawCube ( fiducialToCamera , intrinsic , width , 3 , g2 ) ; VisualizeFiducial . drawLabelCenter ( fiducialToCamera , intrinsic , "" + id , g2 ) ; } saveResults ( 0 ) ; if ( intrinsicPath == null ) { g2 . setColor ( Color . RED ) ; g2 . setFont ( font ) ; g2 . drawString ( "Uncalibrated" , 10 , 20 ) ; } gui . setImage ( buffered ) ; } | Displays a simple image |
26,723 | public byte [ ] readFrame ( DataInputStream in ) { try { if ( findMarker ( in , SOI ) && in . available ( ) > 0 ) { return readJpegData ( in , EOI ) ; } } catch ( IOException e ) { } return null ; } | Read a single frame at a time |
26,724 | void applyToBorder ( GrayU8 input , GrayU8 output , int y0 , int y1 , int x0 , int x1 , ApplyHelper h ) { h . computeHistogram ( 0 , 0 , input ) ; h . applyToBlock ( 0 , 0 , x0 + 1 , y0 + 1 , input , output ) ; for ( int x = x0 + 1 ; x < x1 ; x ++ ) { h . updateHistogramX ( x - x0 , 0 , input ) ; h . applyToBlock ( x , 0 , x + 1 , y0 , input , output ) ; } h . updateHistogramX ( x1 - x0 , 0 , input ) ; h . applyToBlock ( x1 , 0 , input . width , y0 + 1 , input , output ) ; for ( int y = y0 + 1 ; y < y1 ; y ++ ) { h . updateHistogramY ( x1 - x0 , y - y0 , input ) ; h . applyToBlock ( x1 , y , input . width , y + 1 , input , output ) ; } h . updateHistogramY ( x1 - x0 , y1 - y0 , input ) ; h . applyToBlock ( x1 , y1 , input . width , input . height , input , output ) ; h . computeHistogram ( 0 , 0 , input ) ; for ( int y = y0 + 1 ; y < y1 ; y ++ ) { h . updateHistogramY ( 0 , y - y0 , input ) ; h . applyToBlock ( 0 , y , x0 , y + 1 , input , output ) ; } h . updateHistogramY ( 0 , y1 - y0 , input ) ; h . applyToBlock ( 0 , y1 , x0 + 1 , input . height , input , output ) ; for ( int x = x0 + 1 ; x < x1 ; x ++ ) { h . updateHistogramX ( x - x0 , y1 - y0 , input ) ; h . applyToBlock ( x , y1 , x + 1 , input . height , input , output ) ; } } | Apply around the image border . Use a region that s the full size but apply to all pixels that the region would go outside of it was centered on them . |
26,725 | public static PixelTransform < Point2D_F32 > createPixelTransform ( InvertibleTransform transform ) { PixelTransform < Point2D_F32 > pixelTran ; if ( transform instanceof Homography2D_F64 ) { Homography2D_F32 t = ConvertFloatType . convert ( ( Homography2D_F64 ) transform , null ) ; pixelTran = new PixelTransformHomography_F32 ( t ) ; } else if ( transform instanceof Homography2D_F32 ) { pixelTran = new PixelTransformHomography_F32 ( ( Homography2D_F32 ) transform ) ; } else if ( transform instanceof Affine2D_F64 ) { Affine2D_F32 t = UtilAffine . convert ( ( Affine2D_F64 ) transform , null ) ; pixelTran = new PixelTransformAffine_F32 ( t ) ; } else if ( transform instanceof Affine2D_F32 ) { pixelTran = new PixelTransformAffine_F32 ( ( Affine2D_F32 ) transform ) ; } else { throw new RuntimeException ( "Unknown model type" ) ; } return pixelTran ; } | Given a motion model create a PixelTransform used to distort the image |
26,726 | public static < T extends ImageGray < T > > OrientationImage < T > sift ( ConfigSiftScaleSpace configSS , ConfigSiftOrientation configOri , Class < T > imageType ) { if ( configSS == null ) configSS = new ConfigSiftScaleSpace ( ) ; configSS . checkValidity ( ) ; OrientationHistogramSift < GrayF32 > ori = FactoryOrientationAlgs . sift ( configOri , GrayF32 . class ) ; SiftScaleSpace ss = new SiftScaleSpace ( configSS . firstOctave , configSS . lastOctave , configSS . numScales , configSS . sigma0 ) ; return new OrientationSiftToImage < > ( ori , ss , imageType ) ; } | Creates an implementation of the SIFT orientation estimation algorithm |
26,727 | public static List < Point2D_F64 > gridChess ( int numRows , int numCols , double squareWidth ) { List < Point2D_F64 > all = new ArrayList < > ( ) ; numCols = numCols - 1 ; numRows = numRows - 1 ; double startX = - ( ( numCols - 1 ) * squareWidth ) / 2.0 ; double startY = - ( ( numRows - 1 ) * squareWidth ) / 2.0 ; for ( int i = numRows - 1 ; i >= 0 ; i -- ) { double y = startY + i * squareWidth ; for ( int j = 0 ; j < numCols ; j ++ ) { double x = startX + j * squareWidth ; all . add ( new Point2D_F64 ( x , y ) ) ; } } return all ; } | This target is composed of a checkered chess board like squares . Each corner of an interior square touches an adjacent square but the sides are separated . Only interior square corners provide calibration points . |
26,728 | public static < T extends ImageGray < T > > void naiveGradient ( T ii , double tl_x , double tl_y , double samplePeriod , int regionSize , double kernelSize , boolean useHaar , double [ ] derivX , double derivY [ ] ) { SparseScaleGradient < T , ? > gg = SurfDescribeOps . createGradient ( useHaar , ( Class < T > ) ii . getClass ( ) ) ; gg . setWidth ( kernelSize ) ; gg . setImage ( ii ) ; SparseGradientSafe g = new SparseGradientSafe ( gg ) ; tl_x += 0.5 ; tl_y += 0.5 ; int i = 0 ; for ( int y = 0 ; y < regionSize ; y ++ ) { for ( int x = 0 ; x < regionSize ; x ++ , i ++ ) { int xx = ( int ) ( tl_x + x * samplePeriod ) ; int yy = ( int ) ( tl_y + y * samplePeriod ) ; GradientValue deriv = g . compute ( xx , yy ) ; derivX [ i ] = deriv . getX ( ) ; derivY [ i ] = deriv . getY ( ) ; } } } | Simple algorithm for computing the gradient of a region . Can handle image borders |
26,729 | public void setImageGradient ( D derivX , D derivY ) { InputSanityCheck . checkSameShape ( derivX , derivY ) ; if ( derivX . stride != derivY . stride || derivX . startIndex != derivY . startIndex ) throw new IllegalArgumentException ( "stride and start index must be the same" ) ; savedAngle . reshape ( derivX . width , derivX . height ) ; savedMagnitude . reshape ( derivX . width , derivX . height ) ; imageDerivX . wrap ( derivX ) ; imageDerivY . wrap ( derivY ) ; precomputeAngles ( derivX ) ; } | Sets the gradient and precomputes pixel orientation and magnitude |
26,730 | public void process ( ) { int width = widthSubregion * widthGrid ; int radius = width / 2 ; int X0 = radius , X1 = savedAngle . width - radius ; int Y0 = radius , Y1 = savedAngle . height - radius ; int numX = ( int ) ( ( X1 - X0 ) / periodColumns ) ; int numY = ( int ) ( ( Y1 - Y0 ) / periodRows ) ; descriptors . reset ( ) ; sampleLocations . reset ( ) ; for ( int i = 0 ; i < numY ; i ++ ) { int y = ( Y1 - Y0 ) * i / ( numY - 1 ) + Y0 ; for ( int j = 0 ; j < numX ; j ++ ) { int x = ( X1 - X0 ) * j / ( numX - 1 ) + X0 ; TupleDesc_F64 desc = descriptors . grow ( ) ; computeDescriptor ( x , y , desc ) ; sampleLocations . grow ( ) . set ( x , y ) ; } } } | Computes SIFT descriptors across the entire image |
26,731 | void precomputeAngles ( D image ) { int savecIndex = 0 ; for ( int y = 0 ; y < image . height ; y ++ ) { int pixelIndex = y * image . stride + image . startIndex ; for ( int x = 0 ; x < image . width ; x ++ , pixelIndex ++ , savecIndex ++ ) { float spacialDX = imageDerivX . getF ( pixelIndex ) ; float spacialDY = imageDerivY . getF ( pixelIndex ) ; savedAngle . data [ savecIndex ] = UtilAngle . domain2PI ( Math . atan2 ( spacialDY , spacialDX ) ) ; savedMagnitude . data [ savecIndex ] = ( float ) Math . sqrt ( spacialDX * spacialDX + spacialDY * spacialDY ) ; } } } | Computes the angle of each pixel and its gradient magnitude |
26,732 | public void computeDescriptor ( int cx , int cy , TupleDesc_F64 desc ) { desc . fill ( 0 ) ; int widthPixels = widthSubregion * widthGrid ; int radius = widthPixels / 2 ; for ( int i = 0 ; i < widthPixels ; i ++ ) { int angleIndex = ( cy - radius + i ) * savedAngle . width + ( cx - radius ) ; float subY = i / ( float ) widthSubregion ; for ( int j = 0 ; j < widthPixels ; j ++ , angleIndex ++ ) { float subX = j / ( float ) widthSubregion ; double angle = savedAngle . data [ angleIndex ] ; float weightGaussian = gaussianWeight [ i * widthPixels + j ] ; float weightGradient = savedMagnitude . data [ angleIndex ] ; trilinearInterpolation ( weightGaussian * weightGradient , subX , subY , angle , desc ) ; } } normalizeDescriptor ( desc , maxDescriptorElementValue ) ; } | Computes the descriptor centered at the specified coordinate |
26,733 | static public void naive4 ( GrayF32 _intensity , GrayS8 direction , GrayF32 output ) { final int w = _intensity . width ; final int h = _intensity . height ; ImageBorder_F32 intensity = ( ImageBorder_F32 ) FactoryImageBorderAlgs . value ( _intensity , 0 ) ; BoofConcurrency . loopFor ( 0 , h , y -> { for ( int x = 0 ; x < w ; x ++ ) { int dir = direction . get ( x , y ) ; int dx , dy ; if ( dir == 0 ) { dx = 1 ; dy = 0 ; } else if ( dir == 1 ) { dx = 1 ; dy = 1 ; } else if ( dir == 2 ) { dx = 0 ; dy = 1 ; } else { dx = 1 ; dy = - 1 ; } float left = intensity . get ( x - dx , y - dy ) ; float middle = intensity . get ( x , y ) ; float right = intensity . get ( x + dx , y + dy ) ; if ( left > middle || right > middle ) { output . set ( x , y , 0 ) ; } else { output . set ( x , y , middle ) ; } } } ) ; } | Slow algorithm which processes the whole image . |
26,734 | public void reset ( ) { for ( int i = 0 ; i < 4 ; i ++ ) { ppCorner . get ( i ) . set ( 0 , 0 ) ; ppDown . get ( i ) . set ( 0 , 0 ) ; ppRight . get ( i ) . set ( 0 , 0 ) ; } this . threshCorner = 0 ; this . threshDown = 0 ; this . threshRight = 0 ; version = - 1 ; error = L ; mask = QrCodeMaskPattern . M111 ; alignment . reset ( ) ; mode = Mode . UNKNOWN ; failureCause = Failure . NONE ; rawbits = null ; corrected = null ; message = null ; } | Resets the QR - Code so that it s in its initial state . |
26,735 | public void set ( QrCode o ) { this . version = o . version ; this . error = o . error ; this . mask = o . mask ; this . mode = o . mode ; this . rawbits = o . rawbits == null ? null : o . rawbits . clone ( ) ; this . corrected = o . corrected == null ? null : o . corrected . clone ( ) ; this . message = o . message ; this . threshCorner = o . threshCorner ; this . threshDown = o . threshDown ; this . threshRight = o . threshRight ; this . ppCorner . set ( o . ppCorner ) ; this . ppDown . set ( o . ppDown ) ; this . ppRight . set ( o . ppRight ) ; this . failureCause = o . failureCause ; this . bounds . set ( o . bounds ) ; this . alignment . reset ( ) ; for ( int i = 0 ; i < o . alignment . size ; i ++ ) { this . alignment . grow ( ) . set ( o . alignment . get ( i ) ) ; } this . Hinv . set ( o . Hinv ) ; } | Sets this so that it s equivalent to o . |
26,736 | public static void ensureDeterminantOfOne ( List < Homography2D_F64 > homography0toI ) { int N = homography0toI . size ( ) ; for ( int i = 0 ; i < N ; i ++ ) { Homography2D_F64 H = homography0toI . get ( i ) ; double d = CommonOps_DDF3 . det ( H ) ; if ( d < 0 ) CommonOps_DDF3 . divide ( H , - Math . pow ( - d , 1.0 / 3 ) ) ; else CommonOps_DDF3 . divide ( H , Math . pow ( d , 1.0 / 3 ) ) ; } } | Scales all homographies so that their determinants are equal to one |
26,737 | private boolean extractCalibration ( DMatrixRMaj x , CameraPinhole calibration ) { double s = x . data [ 5 ] ; double cx = calibration . cx = x . data [ 2 ] / s ; double cy = calibration . cy = x . data [ 4 ] / s ; double fy = calibration . fy = Math . sqrt ( x . data [ 3 ] / s - cy * cy ) ; double sk = calibration . skew = ( x . data [ 1 ] / s - cx * cy ) / fy ; calibration . fx = Math . sqrt ( x . data [ 0 ] / s - sk * sk - cx * cx ) ; if ( calibration . fx < 0 || calibration . fy < 0 ) return false ; if ( UtilEjml . isUncountable ( fy ) || UtilEjml . isUncountable ( calibration . fx ) ) return false ; if ( UtilEjml . isUncountable ( sk ) ) return false ; return true ; } | Extracts camera parameters from the solution . Checks for errors |
26,738 | private static WlBorderCoef < WlCoef_F32 > computeBorderCoefficients ( BorderIndex1D border , WlCoef_F32 forward , WlCoef_F32 inverse ) { int N = Math . max ( forward . getScalingLength ( ) , forward . getWaveletLength ( ) ) ; N += N % 2 ; N *= 2 ; border . setLength ( N ) ; DMatrixRMaj A = new DMatrixRMaj ( N , N ) ; for ( int i = 0 ; i < N ; i += 2 ) { for ( int j = 0 ; j < forward . scaling . length ; j ++ ) { int index = border . getIndex ( j + i + forward . offsetScaling ) ; A . add ( i , index , forward . scaling [ j ] ) ; } for ( int j = 0 ; j < forward . wavelet . length ; j ++ ) { int index = border . getIndex ( j + i + forward . offsetWavelet ) ; A . add ( i + 1 , index , forward . wavelet [ j ] ) ; } } LinearSolverDense < DMatrixRMaj > solver = LinearSolverFactory_DDRM . linear ( N ) ; if ( ! solver . setA ( A ) || solver . quality ( ) < 1e-5 ) { throw new IllegalArgumentException ( "Can't invert matrix" ) ; } DMatrixRMaj A_inv = new DMatrixRMaj ( N , N ) ; solver . invert ( A_inv ) ; int numBorder = UtilWavelet . borderForwardLower ( inverse ) / 2 ; WlBorderCoefFixed < WlCoef_F32 > ret = new WlBorderCoefFixed < > ( numBorder , numBorder + 1 ) ; ret . setInnerCoef ( inverse ) ; for ( int i = 0 ; i < ret . getLowerLength ( ) ; i ++ ) { computeLowerCoef ( inverse , A_inv , ret , i * 2 ) ; } for ( int i = 0 ; i < ret . getUpperLength ( ) ; i ++ ) { computeUpperCoef ( inverse , N , A_inv , ret , i * 2 ) ; } return ret ; } | Computes inverse coefficients |
26,739 | public static WlBorderCoefFixed < WlCoef_I32 > convertToInt ( WlBorderCoefFixed < WlCoef_F32 > orig , WlCoef_I32 inner ) { WlBorderCoefFixed < WlCoef_I32 > ret = new WlBorderCoefFixed < > ( orig . getLowerLength ( ) , orig . getUpperLength ( ) ) ; for ( int i = 0 ; i < orig . getLowerLength ( ) ; i ++ ) { WlCoef_F32 o = orig . getLower ( i ) ; WlCoef_I32 r = new WlCoef_I32 ( ) ; ret . setLower ( i , r ) ; convertCoef_F32_to_I32 ( inner . denominatorScaling , inner . denominatorWavelet , o , r ) ; } for ( int i = 0 ; i < orig . getUpperLength ( ) ; i ++ ) { WlCoef_F32 o = orig . getUpper ( i ) ; WlCoef_I32 r = new WlCoef_I32 ( ) ; ret . setUpper ( i , r ) ; convertCoef_F32_to_I32 ( inner . denominatorScaling , inner . denominatorWavelet , o , r ) ; } ret . setInnerCoef ( inner ) ; return ret ; } | todo rename and move to a utility function? |
26,740 | public int updateMixture ( float [ ] pixelValue , float [ ] dataRow , int modelIndex ) { int index = modelIndex ; float bestDistance = maxDistance * numBands ; int bestIndex = - 1 ; int ng ; for ( ng = 0 ; ng < maxGaussians ; ng ++ , index += gaussianStride ) { float variance = dataRow [ index + 1 ] ; if ( variance <= 0 ) { break ; } float mahalanobis = 0 ; for ( int i = 0 ; i < numBands ; i ++ ) { float mean = dataRow [ index + 2 + i ] ; float delta = pixelValue [ i ] - mean ; mahalanobis += delta * delta / variance ; } if ( mahalanobis < bestDistance ) { bestDistance = mahalanobis ; bestIndex = index ; } } if ( bestIndex != - 1 ) { float weight = dataRow [ bestIndex ] ; float variance = dataRow [ bestIndex + 1 ] ; weight += learningRate * ( 1f - weight ) ; dataRow [ bestIndex ] = 1 ; float sumDeltaSq = 0 ; for ( int i = 0 ; i < numBands ; i ++ ) { float mean = dataRow [ bestIndex + 2 + i ] ; float delta = pixelValue [ i ] - mean ; dataRow [ bestIndex + 2 + i ] = mean + delta * learningRate / weight ; sumDeltaSq += delta * delta ; } sumDeltaSq /= numBands ; dataRow [ bestIndex + 1 ] = variance + ( learningRate / weight ) * ( sumDeltaSq * 1.2F - variance ) ; updateWeightAndPrune ( dataRow , modelIndex , ng , bestIndex , weight ) ; return weight >= significantWeight ? 0 : 1 ; } else if ( ng < maxGaussians ) { bestIndex = modelIndex + ng * gaussianStride ; dataRow [ bestIndex ] = 1 ; dataRow [ bestIndex + 1 ] = initialVariance ; for ( int i = 0 ; i < numBands ; i ++ ) { dataRow [ bestIndex + 2 + i ] = pixelValue [ i ] ; } if ( ng == 0 ) return unknownValue ; updateWeightAndPrune ( dataRow , modelIndex , ng + 1 , bestIndex , learningRate ) ; return 1 ; } else { return 1 ; } } | Updates the mixtures of gaussian and determines if the pixel matches the background model |
26,741 | public void updateWeightAndPrune ( float [ ] dataRow , int modelIndex , int ng , int bestIndex , float bestWeight ) { int index = modelIndex ; float weightTotal = 0 ; for ( int i = 0 ; i < ng ; ) { float weight = dataRow [ index ] ; weight = weight - learningRate * ( weight + decay ) ; if ( weight <= 0 ) { int indexLast = modelIndex + ( ng - 1 ) * gaussianStride ; for ( int j = 0 ; j < gaussianStride ; j ++ ) { dataRow [ index + j ] = dataRow [ indexLast + j ] ; } if ( indexLast == bestIndex ) bestIndex = index ; dataRow [ indexLast + 1 ] = 0 ; ng -= 1 ; } else { dataRow [ index ] = weight ; weightTotal += weight ; index += gaussianStride ; i ++ ; } } if ( bestIndex != - 1 ) { weightTotal -= dataRow [ bestIndex ] ; weightTotal += bestWeight ; dataRow [ bestIndex ] = bestWeight ; } index = modelIndex ; for ( int i = 0 ; i < ng ; i ++ , index += gaussianStride ) { dataRow [ index ] /= weightTotal ; } } | Updates the weight of each Gaussian and prunes one which have a negative weight after the update . |
26,742 | public int checkBackground ( float [ ] pixelValue , float [ ] dataRow , int modelIndex ) { int index = modelIndex ; float bestDistance = maxDistance * numBands ; float bestWeight = 0 ; int ng ; for ( ng = 0 ; ng < maxGaussians ; ng ++ , index += gaussianStride ) { float variance = dataRow [ index + 1 ] ; if ( variance <= 0 ) { break ; } float mahalanobis = 0 ; for ( int i = 0 ; i < numBands ; i ++ ) { float mean = dataRow [ index + 2 + i ] ; float delta = pixelValue [ i ] - mean ; mahalanobis += delta * delta / variance ; } if ( mahalanobis < bestDistance ) { bestDistance = mahalanobis ; bestWeight = dataRow [ index ] ; } } if ( ng == 0 ) return unknownValue ; return bestWeight >= significantWeight ? 0 : 1 ; } | Checks to see if the the pivel value refers to the background or foreground |
26,743 | public static < T extends ImageGray < T > > T yuvToGray ( ByteBuffer bufferY , int width , int height , int strideRow , T output , BWorkArrays workArrays , Class < T > outputType ) { if ( outputType == GrayU8 . class ) { return ( T ) yuvToGray ( bufferY , width , height , strideRow , ( GrayU8 ) output ) ; } else if ( outputType == GrayF32 . class ) { return ( T ) yuvToGray ( bufferY , width , height , strideRow , ( GrayF32 ) output , workArrays ) ; } else { throw new IllegalArgumentException ( "Unsupported BoofCV Image Type " + outputType . getSimpleName ( ) ) ; } } | Converts an YUV 420 888 into gray |
26,744 | public void requestSaveInputImage ( ) { saveRequested = false ; switch ( inputMethod ) { case IMAGE : new Thread ( ( ) -> saveInputImage ( ) ) . start ( ) ; break ; case VIDEO : case WEBCAM : if ( streamPaused ) { saveInputImage ( ) ; } else { saveRequested = true ; } break ; } } | Makes a request that the input image be saved . This request might be carried out immediately or when then next image is processed . |
26,745 | public boolean generate ( List < AssociatedPair > dataSet , Se3_F64 model ) { if ( ! computeEssential . process ( dataSet , E ) ) return false ; decomposeE . decompose ( E ) ; selectBest . select ( decomposeE . getSolutions ( ) , dataSet , model ) ; return true ; } | Computes the camera motion from the set of observations . The motion is from the first into the second camera frame . |
26,746 | public void setCameraParameters ( float fx , float fy , float cx , float cy , int width , int height ) { this . fx = fx ; this . fy = fy ; this . cx = cx ; this . cy = cy ; derivX . reshape ( width , height ) ; derivY . reshape ( width , height ) ; int N = width * height * imageType . getNumBands ( ) ; A . reshape ( N , 6 ) ; y . reshape ( N , 1 ) ; } | Specifies intrinsic camera parameters . Must be called . |
26,747 | public void setInterpolation ( double inputMin , double inputMax , double derivMin , double derivMax , InterpolationType type ) { interpI = FactoryInterpolation . createPixelS ( inputMin , inputMax , type , BorderType . EXTENDED , imageType . getImageClass ( ) ) ; interpDX = FactoryInterpolation . createPixelS ( derivMin , derivMax , type , BorderType . EXTENDED , derivType . getImageClass ( ) ) ; interpDY = FactoryInterpolation . createPixelS ( derivMin , derivMax , type , BorderType . EXTENDED , derivType . getImageClass ( ) ) ; } | Used to change interpolation method . Probably don t want to do this . |
26,748 | void setKeyFrame ( Planar < I > input , ImagePixelTo3D pixelTo3D ) { InputSanityCheck . checkSameShape ( derivX , input ) ; wrapI . wrap ( input ) ; keypixels . reset ( ) ; for ( int y = 0 ; y < input . height ; y ++ ) { for ( int x = 0 ; x < input . width ; x ++ ) { if ( ! pixelTo3D . process ( x , y ) ) { continue ; } float P_x = ( float ) pixelTo3D . getX ( ) ; float P_y = ( float ) pixelTo3D . getY ( ) ; float P_z = ( float ) pixelTo3D . getZ ( ) ; float P_w = ( float ) pixelTo3D . getW ( ) ; if ( P_w <= 0 ) continue ; Pixel p = keypixels . grow ( ) ; p . valid = true ; wrapI . get ( x , y , p . bands ) ; p . x = x ; p . y = y ; p . p3 . set ( P_x / P_w , P_y / P_w , P_z / P_w ) ; } } } | Set s the keyframe . This is the image which motion is estimated relative to . The 3D location of points in the keyframe must be known . |
26,749 | public double computeFeatureDiversity ( Se3_F32 keyToCurrent ) { diversity . reset ( ) ; for ( int i = 0 ; i < keypixels . size ( ) ; i ++ ) { Pixel p = keypixels . data [ i ] ; if ( ! p . valid ) continue ; SePointOps_F32 . transform ( keyToCurrent , p . p3 , S ) ; diversity . addPoint ( S . x , S . y , S . z ) ; } diversity . process ( ) ; return diversity . getSpread ( ) ; } | Computes the diversity of valid pixels in keyframe to the location in the current frame . |
26,750 | public boolean estimateMotion ( Planar < I > input , Se3_F32 hintKeyToInput ) { InputSanityCheck . checkSameShape ( derivX , input ) ; initMotion ( input ) ; keyToCurrent . set ( hintKeyToInput ) ; boolean foundSolution = false ; float previousError = Float . MAX_VALUE ; for ( int i = 0 ; i < maxIterations ; i ++ ) { constructLinearSystem ( input , keyToCurrent ) ; if ( ! solveSystem ( ) ) break ; if ( Math . abs ( previousError - errorOptical ) / previousError < convergeTol ) break ; else { previousError = errorOptical ; keyToCurrent . concat ( motionTwist , tmp ) ; keyToCurrent . set ( tmp ) ; foundSolution = true ; } } return foundSolution ; } | Estimates the motion relative to the key frame . |
26,751 | void initMotion ( Planar < I > input ) { if ( solver == null ) { solver = LinearSolverFactory_DDRM . qr ( input . width * input . height * input . getNumBands ( ) , 6 ) ; } computeD . process ( input , derivX , derivY ) ; } | Initialize motion related data structures |
26,752 | public boolean process ( List < AssociatedPair > points , FastQueue < DMatrixRMaj > solutions ) { if ( points . size ( ) != 5 ) throw new IllegalArgumentException ( "Exactly 5 points are required, not " + points . size ( ) ) ; solutions . reset ( ) ; computeSpan ( points ) ; helper . setNullSpace ( X , Y , Z , W ) ; helper . setupA1 ( A1 ) ; helper . setupA2 ( A2 ) ; solver . setA ( A1 ) ; solver . solve ( A2 , C ) ; helper . setDeterminantVectors ( C ) ; helper . extractPolynomial ( poly . getCoefficients ( ) ) ; if ( ! findRoots . process ( poly ) ) return false ; for ( Complex_F64 c : findRoots . getRoots ( ) ) { if ( ! c . isReal ( ) ) continue ; solveForXandY ( c . real ) ; DMatrixRMaj E = solutions . grow ( ) ; for ( int i = 0 ; i < 9 ; i ++ ) { E . data [ i ] = x * X [ i ] + y * Y [ i ] + z * Z [ i ] + W [ i ] ; } } return true ; } | Computes the essential matrix from point correspondences . |
26,753 | private void solveForXandY ( double z ) { this . z = z ; tmpA . data [ 0 ] = ( ( helper . K00 * z + helper . K01 ) * z + helper . K02 ) * z + helper . K03 ; tmpA . data [ 1 ] = ( ( helper . K04 * z + helper . K05 ) * z + helper . K06 ) * z + helper . K07 ; tmpY . data [ 0 ] = ( ( ( helper . K08 * z + helper . K09 ) * z + helper . K10 ) * z + helper . K11 ) * z + helper . K12 ; tmpA . data [ 2 ] = ( ( helper . L00 * z + helper . L01 ) * z + helper . L02 ) * z + helper . L03 ; tmpA . data [ 3 ] = ( ( helper . L04 * z + helper . L05 ) * z + helper . L06 ) * z + helper . L07 ; tmpY . data [ 1 ] = ( ( ( helper . L08 * z + helper . L09 ) * z + helper . L10 ) * z + helper . L11 ) * z + helper . L12 ; tmpA . data [ 4 ] = ( ( helper . M00 * z + helper . M01 ) * z + helper . M02 ) * z + helper . M03 ; tmpA . data [ 5 ] = ( ( helper . M04 * z + helper . M05 ) * z + helper . M06 ) * z + helper . M07 ; tmpY . data [ 2 ] = ( ( ( helper . M08 * z + helper . M09 ) * z + helper . M10 ) * z + helper . M11 ) * z + helper . M12 ; CommonOps_DDRM . scale ( - 1 , tmpY ) ; CommonOps_DDRM . solve ( tmpA , tmpY , tmpX ) ; this . x = tmpX . get ( 0 , 0 ) ; this . y = tmpX . get ( 1 , 0 ) ; } | Once z is known then x and y can be solved for using the B matrix |
26,754 | public boolean checkPixel ( Point2D_F64 left , Point2D_F64 right ) { leftImageToRect . compute ( left . x , left . y , rectLeft ) ; rightImageToRect . compute ( right . x , right . y , rectRight ) ; return checkRectified ( rectLeft , rectRight ) ; } | Checks to see if the observations from the left and right camera are consistent . Observations are assumed to be in the original image pixel coordinates . |
26,755 | public boolean checkRectified ( Point2D_F64 left , Point2D_F64 right ) { if ( Math . abs ( left . y - right . y ) > toleranceY ) return false ; return right . x <= left . x + toleranceX ; } | Checks to see if the observations from the left and right camera are consistent . Observations are assumed to be in the rectified image pixel coordinates . |
26,756 | public static < T extends ImageGray < T > > DescribePointBriefSO < T > briefso ( BinaryCompareDefinition_I32 definition , BlurFilter < T > filterBlur ) { Class < T > imageType = filterBlur . getInputType ( ) . getImageClass ( ) ; InterpolatePixelS < T > interp = FactoryInterpolation . bilinearPixelS ( imageType , BorderType . EXTENDED ) ; return new DescribePointBriefSO < > ( definition , filterBlur , interp ) ; } | todo remove filterBlur for all BRIEF change to radius sigma type |
26,757 | public boolean checkVariance ( ImageRectangle r ) { double sigma2 = computeVariance ( r . x0 , r . y0 , r . x1 , r . y1 ) ; return sigma2 >= thresholdLower ; } | Performs variance test at the specified rectangle |
26,758 | protected double computeVariance ( int x0 , int y0 , int x1 , int y1 ) { double square = GIntegralImageOps . block_unsafe ( integralSq , x0 - 1 , y0 - 1 , x1 - 1 , y1 - 1 ) ; double area = ( x1 - x0 ) * ( y1 - y0 ) ; double mean = GIntegralImageOps . block_unsafe ( integral , x0 - 1 , y0 - 1 , x1 - 1 , y1 - 1 ) / area ; return square / area - mean * mean ; } | Computes the variance inside the specified rectangle . x0 and y0 must be > ; 0 . |
26,759 | protected double computeVarianceSafe ( int x0 , int y0 , int x1 , int y1 ) { double square = GIntegralImageOps . block_zero ( integralSq , x0 - 1 , y0 - 1 , x1 - 1 , y1 - 1 ) ; double area = ( x1 - x0 ) * ( y1 - y0 ) ; double mean = GIntegralImageOps . block_zero ( integral , x0 - 1 , y0 - 1 , x1 - 1 , y1 - 1 ) / area ; return square / area - mean * mean ; } | Computes the variance inside the specified rectangle . |
26,760 | public static void transformSq ( final GrayU8 input , final GrayS64 transformed ) { int indexSrc = input . startIndex ; int indexDst = transformed . startIndex ; int end = indexSrc + input . width ; long total = 0 ; for ( ; indexSrc < end ; indexSrc ++ ) { int value = input . data [ indexSrc ] & 0xFF ; transformed . data [ indexDst ++ ] = total += value * value ; } for ( int y = 1 ; y < input . height ; y ++ ) { indexSrc = input . startIndex + input . stride * y ; indexDst = transformed . startIndex + transformed . stride * y ; int indexPrev = indexDst - transformed . stride ; end = indexSrc + input . width ; total = 0 ; for ( ; indexSrc < end ; indexSrc ++ ) { int value = input . data [ indexSrc ] & 0xFF ; total += value * value ; transformed . data [ indexDst ++ ] = transformed . data [ indexPrev ++ ] + total ; } } } | Integral image of pixel value squared . integer |
26,761 | public static void transformSq ( final GrayF32 input , final GrayF64 transformed ) { int indexSrc = input . startIndex ; int indexDst = transformed . startIndex ; int end = indexSrc + input . width ; double total = 0 ; for ( ; indexSrc < end ; indexSrc ++ ) { float value = input . data [ indexSrc ] ; transformed . data [ indexDst ++ ] = total += value * value ; } for ( int y = 1 ; y < input . height ; y ++ ) { indexSrc = input . startIndex + input . stride * y ; indexDst = transformed . startIndex + transformed . stride * y ; int indexPrev = indexDst - transformed . stride ; end = indexSrc + input . width ; total = 0 ; for ( ; indexSrc < end ; indexSrc ++ ) { float value = input . data [ indexSrc ] ; total += value * value ; transformed . data [ indexDst ++ ] = transformed . data [ indexPrev ++ ] + total ; } } } | Integral image of pixel value squared . floating point |
26,762 | private int addView ( DMatrixRMaj P , Point2D_F64 a , int index ) { final double sx = stats . stdX , sy = stats . stdY ; double r11 = P . data [ 0 ] , r12 = P . data [ 1 ] , r13 = P . data [ 2 ] , r14 = P . data [ 3 ] ; double r21 = P . data [ 4 ] , r22 = P . data [ 5 ] , r23 = P . data [ 6 ] , r24 = P . data [ 7 ] ; double r31 = P . data [ 8 ] , r32 = P . data [ 9 ] , r33 = P . data [ 10 ] , r34 = P . data [ 11 ] ; A . data [ index ++ ] = ( a . x * r31 - r11 ) / sx ; A . data [ index ++ ] = ( a . x * r32 - r12 ) / sx ; A . data [ index ++ ] = ( a . x * r33 - r13 ) / sx ; A . data [ index ++ ] = ( a . x * r34 - r14 ) / sx ; A . data [ index ++ ] = ( a . y * r31 - r21 ) / sy ; A . data [ index ++ ] = ( a . y * r32 - r22 ) / sy ; A . data [ index ++ ] = ( a . y * r33 - r23 ) / sy ; A . data [ index ++ ] = ( a . y * r34 - r24 ) / sy ; return index ; } | Adds a view to the A matrix . Computed using cross product . |
26,763 | protected void detectionCascade ( FastQueue < ImageRectangle > cascadeRegions ) { success = false ; ambiguous = false ; best = null ; candidateDetections . reset ( ) ; localMaximums . reset ( ) ; ambiguousRegions . clear ( ) ; storageMetric . reset ( ) ; storageIndexes . reset ( ) ; storageRect . clear ( ) ; fernRegions . clear ( ) ; fernInfo . reset ( ) ; int totalP = 0 ; int totalN = 0 ; TldRegionFernInfo info = fernInfo . grow ( ) ; for ( int i = 0 ; i < cascadeRegions . size ; i ++ ) { ImageRectangle region = cascadeRegions . get ( i ) ; if ( ! variance . checkVariance ( region ) ) { continue ; } info . r = region ; if ( fern . lookupFernPN ( info ) ) { totalP += info . sumP ; totalN += info . sumN ; info = fernInfo . grow ( ) ; } } fernInfo . removeTail ( ) ; if ( totalP > 0x0fffffff ) fern . renormalizeP ( ) ; if ( totalN > 0x0fffffff ) fern . renormalizeN ( ) ; selectBestRegionsFern ( totalP , totalN ) ; computeTemplateConfidence ( ) ; if ( candidateDetections . size == 0 ) { return ; } nonmax . process ( candidateDetections , localMaximums ) ; best = selectBest ( ) ; if ( best != null ) { ambiguous = checkAmbiguous ( best ) ; success = true ; } } | Detects the object inside the image . Eliminates candidate regions using a cascade of tests |
26,764 | protected void computeTemplateConfidence ( ) { double max = 0 ; for ( int i = 0 ; i < fernRegions . size ( ) ; i ++ ) { ImageRectangle region = fernRegions . get ( i ) ; double confidence = template . computeConfidence ( region ) ; max = Math . max ( max , confidence ) ; if ( confidence < config . confidenceThresholdUpper ) continue ; TldRegion r = candidateDetections . grow ( ) ; r . connections = 0 ; r . rect . set ( region ) ; r . confidence = confidence ; } } | Computes the confidence for all the regions which pass the fern test |
26,765 | protected void selectBestRegionsFern ( double totalP , double totalN ) { for ( int i = 0 ; i < fernInfo . size ; i ++ ) { TldRegionFernInfo info = fernInfo . get ( i ) ; double probP = info . sumP / totalP ; double probN = info . sumN / totalN ; if ( probP > probN ) { storageMetric . add ( - ( probP - probN ) ) ; storageRect . add ( info . r ) ; } } if ( config . maximumCascadeConsider < storageMetric . size ) { int N = Math . min ( config . maximumCascadeConsider , storageMetric . size ) ; storageIndexes . resize ( storageMetric . size ) ; QuickSelect . selectIndex ( storageMetric . data , N - 1 , storageMetric . size , storageIndexes . data ) ; for ( int i = 0 ; i < N ; i ++ ) { fernRegions . add ( storageRect . get ( storageIndexes . get ( i ) ) ) ; } } else { fernRegions . addAll ( storageRect ) ; } } | compute the probability that each region is the target conditional upon this image the sumP and sumN are needed for image conditional probability |
26,766 | public void setImage ( ImagePyramid < InputImage > image , DerivativeImage [ ] derivX , DerivativeImage [ ] derivY ) { if ( image . getNumLayers ( ) != derivX . length || image . getNumLayers ( ) != derivY . length ) throw new IllegalArgumentException ( "Number of layers does not match." ) ; this . image = image ; this . derivX = derivX ; this . derivY = derivY ; } | Sets the current input images for the tracker to use . |
26,767 | public void setImage ( ImagePyramid < InputImage > image ) { this . image = image ; this . derivX = null ; this . derivY = null ; } | Only sets the image pyramid . The derivatives are set to null . Only use this when tracking . |
26,768 | public static void equalize ( int histogram [ ] , int transform [ ] ) { int sum = 0 ; for ( int i = 0 ; i < histogram . length ; i ++ ) { transform [ i ] = sum += histogram [ i ] ; } int maxValue = histogram . length - 1 ; for ( int i = 0 ; i < histogram . length ; i ++ ) { transform [ i ] = ( transform [ i ] * maxValue ) / sum ; } } | Computes a transformation table which will equalize the provided histogram . An equalized histogram spreads the weight across the whole spectrum of values . Often used to make dim images easier for people to see . |
26,769 | public static void sharpen8 ( GrayU8 input , GrayU8 output ) { InputSanityCheck . checkSameShape ( input , output ) ; if ( BoofConcurrency . USE_CONCURRENT ) { ImplEnhanceFilter_MT . sharpenInner8 ( input , output , 0 , 255 ) ; ImplEnhanceFilter_MT . sharpenBorder8 ( input , output , 0 , 255 ) ; } else { ImplEnhanceFilter . sharpenInner8 ( input , output , 0 , 255 ) ; ImplEnhanceFilter . sharpenBorder8 ( input , output , 0 , 255 ) ; } } | Applies a Laplacian - 8 based sharpen filter to the image . |
26,770 | protected void updateTrackLocation ( SetTrackInfo < Desc > info , FastQueue < AssociatedIndex > matches ) { info . matches . resize ( matches . size ) ; for ( int i = 0 ; i < matches . size ; i ++ ) { info . matches . get ( i ) . set ( matches . get ( i ) ) ; } tracksActive . clear ( ) ; for ( int i = 0 ; i < info . matches . size ; i ++ ) { AssociatedIndex indexes = info . matches . data [ i ] ; PointTrack track = info . tracks . get ( indexes . src ) ; Point2D_F64 loc = info . locDst . data [ indexes . dst ] ; track . set ( loc . x , loc . y ) ; tracksActive . add ( track ) ; } } | Update each track s location only and not its description . Update the active list too |
26,771 | public static int hamming ( TupleDesc_B a , TupleDesc_B b ) { int score = 0 ; final int N = a . data . length ; for ( int i = 0 ; i < N ; i ++ ) { score += hamming ( a . data [ i ] ^ b . data [ i ] ) ; } return score ; } | Computes the hamming distance between two binary feature descriptors |
26,772 | public static void derivX_F32 ( GrayF32 orig , GrayF32 derivX ) { final float [ ] data = orig . data ; final float [ ] imgX = derivX . data ; final int width = orig . getWidth ( ) ; final int height = orig . getHeight ( ) ; for ( int y = 0 ; y < height ; y ++ ) { int index = width * y + 1 ; int endX = index + width - 2 ; int endXAlt = endX - ( width - 2 ) % 3 ; float x0 = data [ index - 1 ] ; float x1 = data [ index ] ; for ( ; index < endXAlt ; ) { float x2 = data [ index + 1 ] ; imgX [ index ++ ] = ( x2 - x0 ) * 0.5f ; x0 = data [ index + 1 ] ; imgX [ index ++ ] = ( x0 - x1 ) * 0.5f ; x1 = data [ index + 1 ] ; imgX [ index ++ ] = ( x1 - x2 ) * 0.5f ; } for ( ; index < endX ; index ++ ) { imgX [ index ] = ( data [ index + 1 ] - data [ index - 1 ] ) * 0.5f ; } } } | Can only be used with images that are NOT sub - images . |
26,773 | private void pruneTracks ( SetTrackInfo < Desc > info , GrowQueue_I32 unassociated ) { if ( unassociated . size > maxInactiveTracks ) { int numDrop = unassociated . size - maxInactiveTracks ; for ( int i = 0 ; i < numDrop ; i ++ ) { int selected = rand . nextInt ( unassociated . size - i ) + i ; int a = unassociated . get ( i ) ; unassociated . data [ i ] = unassociated . data [ selected ] ; unassociated . data [ selected ] = a ; } List < PointTrack > dropList = new ArrayList < > ( ) ; for ( int i = 0 ; i < numDrop ; i ++ ) { dropList . add ( info . tracks . get ( unassociated . get ( i ) ) ) ; } for ( int i = 0 ; i < dropList . size ( ) ; i ++ ) { dropTrack ( dropList . get ( i ) ) ; } } } | If there are too many unassociated tracks randomly select some of those tracks and drop them |
26,774 | protected void putIntoSrcList ( SetTrackInfo < Desc > info ) { if ( info . isAssociated . length < info . tracks . size ( ) ) { info . isAssociated = new boolean [ info . tracks . size ( ) ] ; } info . featSrc . reset ( ) ; info . locSrc . reset ( ) ; for ( int i = 0 ; i < info . tracks . size ( ) ; i ++ ) { PointTrack t = info . tracks . get ( i ) ; Desc desc = t . getDescription ( ) ; info . featSrc . add ( desc ) ; info . locSrc . add ( t ) ; info . isAssociated [ i ] = false ; } } | Put existing tracks into source list for association |
26,775 | public void spawnTracks ( ) { for ( int setIndex = 0 ; setIndex < sets . length ; setIndex ++ ) { SetTrackInfo < Desc > info = sets [ setIndex ] ; if ( info . isAssociated . length < info . featDst . size ) { info . isAssociated = new boolean [ info . featDst . size ] ; } for ( int i = 0 ; i < info . featDst . size ; i ++ ) { info . isAssociated [ i ] = false ; } for ( int i = 0 ; i < info . matches . size ; i ++ ) { info . isAssociated [ info . matches . data [ i ] . dst ] = true ; } for ( int i = 0 ; i < info . featDst . size ; i ++ ) { if ( info . isAssociated [ i ] ) continue ; Point2D_F64 loc = info . locDst . get ( i ) ; addNewTrack ( setIndex , loc . x , loc . y , info . featDst . get ( i ) ) ; } } } | Takes the current crop of detected features and makes them the keyframe |
26,776 | protected PointTrack addNewTrack ( int setIndex , double x , double y , Desc desc ) { PointTrack p = getUnused ( ) ; p . set ( x , y ) ; ( ( Desc ) p . getDescription ( ) ) . setTo ( desc ) ; if ( checkValidSpawn ( setIndex , p ) ) { p . setId = setIndex ; p . featureId = featureID ++ ; sets [ setIndex ] . tracks . add ( p ) ; tracksNew . add ( p ) ; tracksActive . add ( p ) ; tracksAll . add ( p ) ; return p ; } else { unused . add ( p ) ; return null ; } } | Adds a new track given its location and description |
26,777 | protected PointTrack getUnused ( ) { PointTrack p ; if ( unused . size ( ) > 0 ) { p = unused . remove ( unused . size ( ) - 1 ) ; } else { p = new PointTrack ( ) ; p . setDescription ( manager . createDescription ( ) ) ; } return p ; } | Returns an unused track . If there are no unused tracks then it creates a ne one . |
26,778 | public boolean dropTrack ( PointTrack track ) { if ( ! tracksAll . remove ( track ) ) return false ; if ( ! sets [ track . setId ] . tracks . remove ( track ) ) { return false ; } tracksActive . remove ( track ) ; tracksInactive . remove ( track ) ; unused . add ( track ) ; return true ; } | Remove from active list and mark so that it is dropped in the next cycle |
26,779 | private void addRodriguesJacobian ( DMatrixRMaj Rj , Point3D_F64 worldPt , Point3D_F64 cameraPt ) { double Rx = ( Rj . data [ 0 ] * worldPt . x + Rj . data [ 1 ] * worldPt . y + Rj . data [ 2 ] * worldPt . z ) / cameraPt . z ; double Ry = ( Rj . data [ 3 ] * worldPt . x + Rj . data [ 4 ] * worldPt . y + Rj . data [ 5 ] * worldPt . z ) / cameraPt . z ; double zDot_div_z2 = ( Rj . data [ 6 ] * worldPt . x + Rj . data [ 7 ] * worldPt . y + Rj . data [ 8 ] * worldPt . z ) / ( cameraPt . z * cameraPt . z ) ; output [ indexX ++ ] = - zDot_div_z2 * cameraPt . x + Rx ; output [ indexY ++ ] = - zDot_div_z2 * cameraPt . y + Ry ; } | Adds to the Jacobian matrix using the derivative from a Rodrigues parameter . |
26,780 | private void addTranslationJacobian ( Point3D_F64 cameraPt ) { double divZ = 1.0 / cameraPt . z ; double divZ2 = 1.0 / ( cameraPt . z * cameraPt . z ) ; output [ indexX ++ ] = divZ ; output [ indexY ++ ] = 0 ; output [ indexX ++ ] = 0 ; output [ indexY ++ ] = divZ ; output [ indexX ++ ] = - cameraPt . x * divZ2 ; output [ indexY ++ ] = - cameraPt . y * divZ2 ; } | Derivative for translation element |
26,781 | private void addTranslationJacobian ( DMatrixRMaj R , Point3D_F64 cameraPt ) { double z = cameraPt . z ; double z2 = z * z ; output [ indexX ++ ] = R . get ( 0 , 0 ) / cameraPt . z - R . get ( 2 , 0 ) / z2 * cameraPt . x ; output [ indexY ++ ] = R . get ( 1 , 0 ) / cameraPt . z - R . get ( 2 , 0 ) / z2 * cameraPt . y ; output [ indexX ++ ] = R . get ( 0 , 1 ) / cameraPt . z - R . get ( 2 , 1 ) / z2 * cameraPt . x ; output [ indexY ++ ] = R . get ( 1 , 1 ) / cameraPt . z - R . get ( 2 , 1 ) / z2 * cameraPt . y ; output [ indexX ++ ] = R . get ( 0 , 2 ) / cameraPt . z - R . get ( 2 , 2 ) / z2 * cameraPt . x ; output [ indexY ++ ] = R . get ( 1 , 2 ) / cameraPt . z - R . get ( 2 , 2 ) / z2 * cameraPt . y ; } | The translation vector is now multiplied by 3x3 matrix R . The components of T are no longer decoupled . |
26,782 | public static float [ ] subbandAbsVal ( GrayF32 subband , float [ ] coef ) { if ( coef == null ) { coef = new float [ subband . width * subband . height ] ; } int i = 0 ; for ( int y = 0 ; y < subband . height ; y ++ ) { int index = subband . startIndex + subband . stride * y ; int end = index + subband . width ; for ( ; index < end ; index ++ ) { coef [ i ++ ] = Math . abs ( subband . data [ index ] ) ; } } return coef ; } | Computes the absolute value of each element in the subband image are places it into coef |
26,783 | public static < T extends ImageBase < T > > BlurStorageFilter < T > median ( ImageType < T > type , int radius ) { return new BlurStorageFilter < > ( "median" , type , radius ) ; } | Creates a median filter for the specified image type . |
26,784 | public static < T extends ImageBase < T > > BlurStorageFilter < T > mean ( ImageType < T > type , int radius ) { return new BlurStorageFilter < > ( "mean" , type , radius ) ; } | Creates a mean filter for the specified image type . |
26,785 | public static < T extends ImageBase < T > > BlurStorageFilter < T > gaussian ( ImageType < T > type , double sigma , int radius ) { return new BlurStorageFilter < > ( "gaussian" , type , sigma , radius ) ; } | Creates a Gaussian filter for the specified image type . |
26,786 | public void initialize ( T image , int x0 , int y0 , int regionWidth , int regionHeight ) { this . imageWidth = image . width ; this . imageHeight = image . height ; setTrackLocation ( x0 , y0 , regionWidth , regionHeight ) ; initialLearning ( image ) ; } | Initializes tracking around the specified rectangle region |
26,787 | public void setTrackLocation ( int x0 , int y0 , int regionWidth , int regionHeight ) { if ( imageWidth < regionWidth || imageHeight < regionHeight ) throw new IllegalArgumentException ( "Track region is larger than input image: " + regionWidth + " " + regionHeight ) ; regionOut . width = regionWidth ; regionOut . height = regionHeight ; int w = ( int ) ( regionWidth * ( 1 + padding ) ) ; int h = ( int ) ( regionHeight * ( 1 + padding ) ) ; int cx = x0 + regionWidth / 2 ; int cy = y0 + regionHeight / 2 ; this . regionTrack . width = w ; this . regionTrack . height = h ; this . regionTrack . x0 = cx - w / 2 ; this . regionTrack . y0 = cy - h / 2 ; stepX = ( w - 1 ) / ( float ) ( workRegionSize - 1 ) ; stepY = ( h - 1 ) / ( float ) ( workRegionSize - 1 ) ; updateRegionOut ( ) ; } | Used to change the track s location . If this method is used it is assumed that tracking is active and that the appearance of the target has not changed |
26,788 | protected void initialLearning ( T image ) { get_subwindow ( image , template ) ; dense_gauss_kernel ( sigma , template , template , k ) ; fft . forward ( k , kf ) ; computeAlphas ( gaussianWeightDFT , kf , lambda , alphaf ) ; } | Learn the target s appearance . |
26,789 | protected static void computeCosineWindow ( GrayF64 cosine ) { double cosX [ ] = new double [ cosine . width ] ; for ( int x = 0 ; x < cosine . width ; x ++ ) { cosX [ x ] = 0.5 * ( 1 - Math . cos ( 2.0 * Math . PI * x / ( cosine . width - 1 ) ) ) ; } for ( int y = 0 ; y < cosine . height ; y ++ ) { int index = cosine . startIndex + y * cosine . stride ; double cosY = 0.5 * ( 1 - Math . cos ( 2.0 * Math . PI * y / ( cosine . height - 1 ) ) ) ; for ( int x = 0 ; x < cosine . width ; x ++ ) { cosine . data [ index ++ ] = cosX [ x ] * cosY ; } } } | Computes the cosine window |
26,790 | protected void computeGaussianWeights ( int width ) { double output_sigma = Math . sqrt ( width * width ) * output_sigma_factor ; double left = - 0.5 / ( output_sigma * output_sigma ) ; int radius = width / 2 ; for ( int y = 0 ; y < gaussianWeight . height ; y ++ ) { int index = gaussianWeight . startIndex + y * gaussianWeight . stride ; double ry = y - radius ; for ( int x = 0 ; x < width ; x ++ ) { double rx = x - radius ; gaussianWeight . data [ index ++ ] = Math . exp ( left * ( ry * ry + rx * rx ) ) ; } } fft . forward ( gaussianWeight , gaussianWeightDFT ) ; } | Computes the weights used in the gaussian kernel |
26,791 | public void performTracking ( T image ) { if ( image . width != imageWidth || image . height != imageHeight ) throw new IllegalArgumentException ( "Tracking image size is not the same as " + "input image. Expected " + imageWidth + " x " + imageHeight ) ; updateTrackLocation ( image ) ; if ( interp_factor != 0 ) performLearning ( image ) ; } | Search for the track in the image and |
26,792 | protected void updateTrackLocation ( T image ) { get_subwindow ( image , templateNew ) ; dense_gauss_kernel ( sigma , templateNew , template , k ) ; fft . forward ( k , kf ) ; DiscreteFourierTransformOps . multiplyComplex ( alphaf , kf , tmpFourier0 ) ; fft . inverse ( tmpFourier0 , response ) ; int N = response . width * response . height ; int indexBest = - 1 ; double valueBest = - 1 ; for ( int i = 0 ; i < N ; i ++ ) { double v = response . data [ i ] ; if ( v > valueBest ) { valueBest = v ; indexBest = i ; } } int peakX = indexBest % response . width ; int peakY = indexBest / response . width ; subpixelPeak ( peakX , peakY ) ; float deltaX = ( peakX + offX ) - templateNew . width / 2 ; float deltaY = ( peakY + offY ) - templateNew . height / 2 ; regionTrack . x0 = regionTrack . x0 + deltaX * stepX ; regionTrack . y0 = regionTrack . y0 + deltaY * stepY ; updateRegionOut ( ) ; } | Find the target inside the current image by searching around its last known location |
26,793 | protected void subpixelPeak ( int peakX , int peakY ) { int r = Math . min ( 2 , response . width / 25 ) ; if ( r < 0 ) return ; localPeak . setSearchRadius ( r ) ; localPeak . search ( peakX , peakY ) ; offX = localPeak . getPeakX ( ) - peakX ; offY = localPeak . getPeakY ( ) - peakY ; } | Refine the local - peak using a search algorithm for sub - pixel accuracy . |
26,794 | public void performLearning ( T image ) { get_subwindow ( image , templateNew ) ; dense_gauss_kernel ( sigma , templateNew , templateNew , k ) ; fft . forward ( k , kf ) ; computeAlphas ( gaussianWeightDFT , kf , lambda , newAlphaf ) ; int N = alphaf . width * alphaf . height * 2 ; for ( int i = 0 ; i < N ; i ++ ) { alphaf . data [ i ] = ( 1 - interp_factor ) * alphaf . data [ i ] + interp_factor * newAlphaf . data [ i ] ; } N = templateNew . width * templateNew . height ; for ( int i = 0 ; i < N ; i ++ ) { template . data [ i ] = ( 1 - interp_factor ) * template . data [ i ] + interp_factor * templateNew . data [ i ] ; } } | Update the alphas and the track s appearance |
26,795 | public static double imageDotProduct ( GrayF64 a ) { double total = 0 ; int N = a . width * a . height ; for ( int index = 0 ; index < N ; index ++ ) { double value = a . data [ index ] ; total += value * value ; } return total ; } | Computes the dot product of the image with itself |
26,796 | public static void elementMultConjB ( InterleavedF64 a , InterleavedF64 b , InterleavedF64 output ) { for ( int y = 0 ; y < a . height ; y ++ ) { int index = a . startIndex + y * a . stride ; for ( int x = 0 ; x < a . width ; x ++ , index += 2 ) { double realA = a . data [ index ] ; double imgA = a . data [ index + 1 ] ; double realB = b . data [ index ] ; double imgB = b . data [ index + 1 ] ; output . data [ index ] = realA * realB + imgA * imgB ; output . data [ index + 1 ] = - realA * imgB + imgA * realB ; } } } | Element - wise multiplication of a and the complex conjugate of b |
26,797 | protected static void gaussianKernel ( double xx , double yy , GrayF64 xy , double sigma , GrayF64 output ) { double sigma2 = sigma * sigma ; double N = xy . width * xy . height ; for ( int y = 0 ; y < xy . height ; y ++ ) { int index = xy . startIndex + y * xy . stride ; for ( int x = 0 ; x < xy . width ; x ++ , index ++ ) { double value = ( xx + yy - 2 * xy . data [ index ] ) / N ; double v = Math . exp ( - Math . max ( 0 , value ) / sigma2 ) ; output . data [ index ] = v ; } } } | Computes the output of the Gaussian kernel for each element in the target region |
26,798 | protected void get_subwindow ( T image , GrayF64 output ) { interp . setImage ( image ) ; int index = 0 ; for ( int y = 0 ; y < workRegionSize ; y ++ ) { float yy = regionTrack . y0 + y * stepY ; for ( int x = 0 ; x < workRegionSize ; x ++ ) { float xx = regionTrack . x0 + x * stepX ; if ( interp . isInFastBounds ( xx , yy ) ) output . data [ index ++ ] = interp . get_fast ( xx , yy ) ; else if ( BoofMiscOps . checkInside ( image , xx , yy ) ) output . data [ index ++ ] = interp . get ( xx , yy ) ; else { output . data [ index ++ ] = rand . nextFloat ( ) * maxPixelValue ; } } } PixelMath . divide ( output , maxPixelValue , output ) ; PixelMath . plus ( output , - 0.5f , output ) ; PixelMath . multiply ( output , cosine , output ) ; } | Copies the target into the output image and applies the cosine window to it . |
26,799 | void selectBlockSize ( int width , int height , int requestedBlockWidth ) { if ( height < requestedBlockWidth ) { blockHeight = height ; } else { int rows = height / requestedBlockWidth ; blockHeight = height / rows ; } if ( width < requestedBlockWidth ) { blockWidth = width ; } else { int cols = width / requestedBlockWidth ; blockWidth = width / cols ; } } | Selects a block size which is close to the requested block size by the user |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.