idx
int64
0
41.2k
question
stringlengths
74
4.04k
target
stringlengths
7
750
27,500
private void requestCameraPermission ( ) { int permissionCheck = ContextCompat . checkSelfPermission ( this , Manifest . permission . CAMERA ) ; if ( permissionCheck != android . content . pm . PackageManager . PERMISSION_GRANTED ) { ActivityCompat . requestPermissions ( this , new String [ ] { Manifest . permission . CAMERA } , 0 ) ; } }
Newer versions of Android require explicit permission from the user
27,501
public static < T extends ImageGray < T > > T bitmapToGray ( Bitmap input , T output , Class < T > imageType , byte [ ] storage ) { if ( imageType == GrayF32 . class ) return ( T ) bitmapToGray ( input , ( GrayF32 ) output , storage ) ; else if ( imageType == GrayU8 . class ) return ( T ) bitmapToGray ( input , ( GrayU8 ) output , storage ) ; else throw new IllegalArgumentException ( "Unsupported BoofCV Image Type" ) ; }
Converts Bitmap image into a single band image of arbitrary type .
27,502
public static GrayU8 bitmapToGray ( Bitmap input , GrayU8 output , byte [ ] storage ) { if ( output == null ) { output = new GrayU8 ( input . getWidth ( ) , input . getHeight ( ) ) ; } else { output . reshape ( input . getWidth ( ) , input . getHeight ( ) ) ; } if ( storage == null ) storage = declareStorage ( input , null ) ; input . copyPixelsToBuffer ( ByteBuffer . wrap ( storage ) ) ; ImplConvertBitmap . arrayToGray ( storage , input . getConfig ( ) , output ) ; return output ; }
Converts Bitmap image into GrayU8 .
27,503
public static < T extends ImageGray < T > > Planar < T > bitmapToPlanar ( Bitmap input , Planar < T > output , Class < T > type , byte [ ] storage ) { if ( output == null ) { output = new Planar < > ( type , input . getWidth ( ) , input . getHeight ( ) , 3 ) ; } else { int numBands = Math . min ( 4 , Math . max ( 3 , output . getNumBands ( ) ) ) ; output . reshape ( input . getWidth ( ) , input . getHeight ( ) , numBands ) ; } if ( storage == null ) storage = declareStorage ( input , null ) ; input . copyPixelsToBuffer ( ByteBuffer . wrap ( storage ) ) ; if ( type == GrayU8 . class ) ImplConvertBitmap . arrayToPlanar_U8 ( storage , input . getConfig ( ) , ( Planar ) output ) ; else if ( type == GrayF32 . class ) ImplConvertBitmap . arrayToPlanar_F32 ( storage , input . getConfig ( ) , ( Planar ) output ) ; else throw new IllegalArgumentException ( "Unsupported BoofCV Type" ) ; return output ; }
Converts Bitmap image into Planar image of the appropriate type .
27,504
public static void boofToBitmap ( ImageBase input , Bitmap output , byte [ ] storage ) { if ( BOverrideConvertAndroid . invokeBoofToBitmap ( ColorFormat . RGB , input , output , storage ) ) return ; if ( input instanceof Planar ) { planarToBitmap ( ( Planar ) input , output , storage ) ; } else if ( input instanceof ImageGray ) { grayToBitmap ( ( ImageGray ) input , output , storage ) ; } else if ( input instanceof ImageInterleaved ) { interleavedToBitmap ( ( ImageInterleaved ) input , output , storage ) ; } else { throw new IllegalArgumentException ( "Unsupported input image type" ) ; } }
Converts many BoofCV image types into a Bitmap .
27,505
public static < T extends ImageGray < T > > void planarToBitmap ( Planar < T > input , Bitmap output , byte [ ] storage ) { if ( output . getWidth ( ) != input . getWidth ( ) || output . getHeight ( ) != input . getHeight ( ) ) { throw new IllegalArgumentException ( "Image shapes are not the same" ) ; } if ( storage == null ) storage = declareStorage ( output , null ) ; if ( input . getBandType ( ) == GrayU8 . class ) ImplConvertBitmap . planarToArray_U8 ( ( Planar ) input , storage , output . getConfig ( ) ) ; else if ( input . getBandType ( ) == GrayF32 . class ) ImplConvertBitmap . planarToArray_F32 ( ( Planar ) input , storage , output . getConfig ( ) ) ; else throw new IllegalArgumentException ( "Unsupported BoofCV Type" ) ; output . copyPixelsFromBuffer ( ByteBuffer . wrap ( storage ) ) ; }
Converts Planar image into Bitmap .
27,506
public static Bitmap grayToBitmap ( GrayU8 input , Bitmap . Config config ) { Bitmap output = Bitmap . createBitmap ( input . width , input . height , config ) ; grayToBitmap ( input , output , null ) ; return output ; }
Converts GrayU8 into a new Bitmap .
27,507
public void process ( FastQueue < AssociatedIndex > matches , int numSource , int numDestination ) { if ( checkSource ) { if ( checkDestination ) { processSource ( matches , numSource , firstPass ) ; processDestination ( firstPass , numDestination , pruned ) ; } else { processSource ( matches , numSource , pruned ) ; } } else if ( checkDestination ) { processDestination ( matches , numDestination , pruned ) ; } else { pruned = matches ; } }
Given a set of matches enforce the uniqueness rules it was configured to .
27,508
private void processSource ( FastQueue < AssociatedIndex > matches , int numSource , FastQueue < AssociatedIndex > output ) { scores . resize ( numSource ) ; solutions . resize ( numSource ) ; for ( int i = 0 ; i < numSource ; i ++ ) { solutions . data [ i ] = - 1 ; } for ( int i = 0 ; i < matches . size ( ) ; i ++ ) { AssociatedIndex a = matches . get ( i ) ; int found = solutions . data [ a . src ] ; if ( found != - 1 ) { if ( found == - 2 ) { double bestScore = scores . data [ a . src ] ; int result = type . compareTo ( bestScore , a . fitScore ) ; if ( result < 0 ) { solutions . data [ a . src ] = i ; scores . data [ a . src ] = a . fitScore ; } } else { AssociatedIndex currentBest = matches . get ( found ) ; int result = type . compareTo ( currentBest . fitScore , a . fitScore ) ; if ( result < 0 ) { solutions . data [ a . src ] = i ; scores . data [ a . src ] = a . fitScore ; } else if ( result == 0 ) { solutions . data [ a . src ] = - 2 ; } } } else { solutions . data [ a . src ] = i ; scores . data [ a . src ] = a . fitScore ; } } output . reset ( ) ; for ( int i = 0 ; i < numSource ; i ++ ) { int index = solutions . data [ i ] ; if ( index >= 0 ) { output . add ( matches . get ( index ) ) ; } } }
Selects a subset of matches that have at most one association for each source feature .
27,509
private void processDestination ( FastQueue < AssociatedIndex > matches , int numDestination , FastQueue < AssociatedIndex > output ) { scores . resize ( numDestination ) ; solutions . resize ( numDestination ) ; for ( int i = 0 ; i < numDestination ; i ++ ) { solutions . data [ i ] = - 1 ; } for ( int i = 0 ; i < matches . size ( ) ; i ++ ) { AssociatedIndex a = matches . get ( i ) ; int found = solutions . data [ a . dst ] ; if ( found != - 1 ) { if ( found == - 2 ) { double bestScore = scores . data [ a . dst ] ; int result = type . compareTo ( bestScore , a . fitScore ) ; if ( result < 0 ) { solutions . data [ a . dst ] = i ; scores . data [ a . dst ] = a . fitScore ; } } else { AssociatedIndex currentBest = matches . get ( found ) ; int result = type . compareTo ( currentBest . fitScore , a . fitScore ) ; if ( result < 0 ) { solutions . data [ a . dst ] = i ; scores . data [ a . dst ] = a . fitScore ; } else if ( result == 0 ) { solutions . data [ a . dst ] = - 2 ; } } } else { solutions . data [ a . dst ] = i ; scores . data [ a . dst ] = i ; } } output . reset ( ) ; for ( int i = 0 ; i < numDestination ; i ++ ) { int index = solutions . data [ i ] ; if ( index >= 0 ) { output . add ( matches . get ( index ) ) ; } } }
Selects a subset of matches that have at most one association for each destination feature .
27,510
private int applyFog ( int rgb , float fraction ) { int adjustment = ( int ) ( 1000 * fraction ) ; int r = ( rgb >> 16 ) & 0xFF ; int g = ( rgb >> 8 ) & 0xFF ; int b = rgb & 0xFF ; r = ( r * adjustment + ( ( backgroundColor >> 16 ) & 0xFF ) * ( 1000 - adjustment ) ) / 1000 ; g = ( g * adjustment + ( ( backgroundColor >> 8 ) & 0xFF ) * ( 1000 - adjustment ) ) / 1000 ; b = ( b * adjustment + ( backgroundColor & 0xFF ) * ( 1000 - adjustment ) ) / 1000 ; return ( r << 16 ) | ( g << 8 ) | b ; }
Fades color into background as a function of distance
27,511
private void renderDot ( int cx , int cy , float Z , int rgb ) { for ( int i = - dotRadius ; i <= dotRadius ; i ++ ) { int y = cy + i ; if ( y < 0 || y >= imageRgb . height ) continue ; for ( int j = - dotRadius ; j <= dotRadius ; j ++ ) { int x = cx + j ; if ( x < 0 || x >= imageRgb . width ) continue ; int pixelIndex = imageDepth . getIndex ( x , y ) ; float depth = imageDepth . data [ pixelIndex ] ; if ( depth > Z ) { imageDepth . data [ pixelIndex ] = Z ; imageRgb . data [ pixelIndex ] = rgb ; } } } }
Renders a dot as a square sprite with the specified color
27,512
protected void imageToOutput ( double x , double y , Point2D_F64 pt ) { pt . x = x / scale - tranX / scale ; pt . y = y / scale - tranY / scale ; }
Converts a coordinate from pixel to the output image coordinates
27,513
protected void outputToImage ( double x , double y , Point2D_F64 pt ) { pt . x = x * scale + tranX ; pt . y = y * scale + tranY ; }
Converts a coordinate from output image coordinates to input image
27,514
public static void RGB_to_PLU8 ( Picture input , Planar < GrayU8 > output ) { if ( input . getColor ( ) != ColorSpace . RGB ) throw new RuntimeException ( "Unexpected input color space!" ) ; if ( output . getNumBands ( ) != 3 ) throw new RuntimeException ( "Unexpected number of bands in output image!" ) ; output . reshape ( input . getWidth ( ) , input . getHeight ( ) ) ; int dataIn [ ] = input . getData ( ) [ 0 ] ; GrayU8 out0 = output . getBand ( 0 ) ; GrayU8 out1 = output . getBand ( 1 ) ; GrayU8 out2 = output . getBand ( 2 ) ; int indexIn = 0 ; int indexOut = 0 ; for ( int i = 0 ; i < output . height ; i ++ ) { for ( int j = 0 ; j < output . width ; j ++ , indexOut ++ ) { int r = dataIn [ indexIn ++ ] ; int g = dataIn [ indexIn ++ ] ; int b = dataIn [ indexIn ++ ] ; out2 . data [ indexOut ] = ( byte ) r ; out1 . data [ indexOut ] = ( byte ) g ; out0 . data [ indexOut ] = ( byte ) b ; } } }
Converts a picture in JCodec RGB into RGB BoofCV
27,515
static void backsubstitution0134 ( DMatrixRMaj P_plus , DMatrixRMaj P , DMatrixRMaj X , double H [ ] ) { final int N = P . numRows ; DMatrixRMaj tmp = new DMatrixRMaj ( N * 2 , 1 ) ; double H6 = H [ 6 ] ; double H7 = H [ 7 ] ; double H8 = H [ 8 ] ; for ( int i = 0 , index = 0 ; i < N ; i ++ ) { double x = - X . data [ index ] , y = - X . data [ index + 1 ] ; double sum = P . data [ index ++ ] * H6 + P . data [ index ++ ] * H7 + H8 ; tmp . data [ i ] = x * sum ; tmp . data [ i + N ] = y * sum ; } double h0 = 0 , h1 = 0 , h3 = 0 , h4 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { double P_pls_0 = P_plus . data [ i ] ; double P_pls_1 = P_plus . data [ i + N ] ; double tmp_i = tmp . data [ i ] ; double tmp_j = tmp . data [ i + N ] ; h0 += P_pls_0 * tmp_i ; h1 += P_pls_1 * tmp_i ; h3 += P_pls_0 * tmp_j ; h4 += P_pls_1 * tmp_j ; } H [ 0 ] = - h0 ; H [ 1 ] = - h1 ; H [ 3 ] = - h3 ; H [ 4 ] = - h4 ; }
Backsubstitution for solving for 0 1 and 3 4 using solution for 6 7 8
27,516
void constructA678 ( ) { final int N = X1 . numRows ; computePseudo ( X1 , P_plus ) ; DMatrixRMaj PPpXP = new DMatrixRMaj ( 1 , 1 ) ; DMatrixRMaj PPpYP = new DMatrixRMaj ( 1 , 1 ) ; computePPXP ( X1 , P_plus , X2 , 0 , PPpXP ) ; computePPXP ( X1 , P_plus , X2 , 1 , PPpYP ) ; DMatrixRMaj PPpX = new DMatrixRMaj ( 1 , 1 ) ; DMatrixRMaj PPpY = new DMatrixRMaj ( 1 , 1 ) ; computePPpX ( X1 , P_plus , X2 , 0 , PPpX ) ; computePPpX ( X1 , P_plus , X2 , 1 , PPpY ) ; computeEq20 ( X2 , X1 , XP_bar ) ; A . reshape ( N * 2 , 3 ) ; double XP_bar_x = XP_bar [ 0 ] ; double XP_bar_y = XP_bar [ 1 ] ; double YP_bar_x = XP_bar [ 2 ] ; double YP_bar_y = XP_bar [ 3 ] ; for ( int i = 0 , index = 0 , indexA = 0 ; i < N ; i ++ , index += 2 ) { double x = - X2 . data [ i * 2 ] ; double P_hat_x = X1 . data [ index ] ; double P_hat_y = X1 . data [ index + 1 ] ; A . data [ indexA ++ ] = x * P_hat_x - XP_bar_x - PPpXP . data [ index ] ; A . data [ indexA ++ ] = x * P_hat_y - XP_bar_y - PPpXP . data [ index + 1 ] ; A . data [ indexA ++ ] = x - PPpX . data [ i ] ; } for ( int i = 0 , index = 0 , indexA = N * 3 ; i < N ; i ++ , index += 2 ) { double x = - X2 . data [ i * 2 + 1 ] ; double P_hat_x = X1 . data [ index ] ; double P_hat_y = X1 . data [ index + 1 ] ; A . data [ indexA ++ ] = x * P_hat_x - YP_bar_x - PPpYP . data [ index ] ; A . data [ indexA ++ ] = x * P_hat_y - YP_bar_y - PPpYP . data [ index + 1 ] ; A . data [ indexA ++ ] = x - PPpY . data [ i ] ; } }
Constructs equation for elements 6 to 8 in H
27,517
public void sanityCheck ( ) { for ( View v : nodes ) { for ( Motion m : v . connections ) { if ( m . viewDst != v && m . viewSrc != v ) throw new RuntimeException ( "Not member of connection" ) ; } } for ( Motion m : edges ) { if ( m . viewDst != m . destination ( m . viewSrc ) ) throw new RuntimeException ( "Unexpected result" ) ; } }
Performs simple checks to see if the data structure is avlid
27,518
public boolean process ( FastQueue < AssociatedPair > pairs , Rectangle2D_F64 targetRectangle ) { if ( ! estimateMotion . process ( pairs . toList ( ) ) ) return false ; ScaleTranslate2D motion = estimateMotion . getModelParameters ( ) ; adjustRectangle ( targetRectangle , motion ) ; if ( targetRectangle . p0 . x < 0 || targetRectangle . p0 . y < 0 ) return false ; if ( targetRectangle . p1 . x >= imageWidth || targetRectangle . p1 . y >= imageHeight ) return false ; return true ; }
Adjusts target rectangle using track information
27,519
protected void adjustRectangle ( Rectangle2D_F64 rect , ScaleTranslate2D motion ) { rect . p0 . x = rect . p0 . x * motion . scale + motion . transX ; rect . p0 . y = rect . p0 . y * motion . scale + motion . transY ; rect . p1 . x = rect . p1 . x * motion . scale + motion . transX ; rect . p1 . y = rect . p1 . y * motion . scale + motion . transY ; }
Estimate motion of points inside the rectangle and updates the rectangle using the found motion .
27,520
public void associate ( BufferedImage imageA , BufferedImage imageB ) { T inputA = ConvertBufferedImage . convertFromSingle ( imageA , null , imageType ) ; T inputB = ConvertBufferedImage . convertFromSingle ( imageB , null , imageType ) ; pointsA = new ArrayList < > ( ) ; pointsB = new ArrayList < > ( ) ; FastQueue < TD > descA = UtilFeature . createQueue ( detDesc , 100 ) ; FastQueue < TD > descB = UtilFeature . createQueue ( detDesc , 100 ) ; describeImage ( inputA , pointsA , descA ) ; describeImage ( inputB , pointsB , descB ) ; associate . setSource ( descA ) ; associate . setDestination ( descB ) ; associate . associate ( ) ; AssociationPanel panel = new AssociationPanel ( 20 ) ; panel . setAssociation ( pointsA , pointsB , associate . getMatches ( ) ) ; panel . setImages ( imageA , imageB ) ; ShowImages . showWindow ( panel , "Associated Features" , true ) ; }
Detect and associate point features in the two images . Display the results .
27,521
public static < T extends ImageGray < T > > WaveletDenoiseFilter < T > waveletVisu ( Class < T > imageType , int numLevels , double minPixelValue , double maxPixelValue ) { ImageDataType info = ImageDataType . classToType ( imageType ) ; WaveletTransform descTran = createDefaultShrinkTransform ( info , numLevels , minPixelValue , maxPixelValue ) ; DenoiseWavelet denoiser = FactoryDenoiseWaveletAlg . visu ( imageType ) ; return new WaveletDenoiseFilter < > ( descTran , denoiser ) ; }
Denoises an image using VISU Shrink wavelet denoiser .
27,522
public static < T extends ImageGray < T > > WaveletDenoiseFilter < T > waveletBayes ( Class < T > imageType , int numLevels , double minPixelValue , double maxPixelValue ) { ImageDataType info = ImageDataType . classToType ( imageType ) ; WaveletTransform descTran = createDefaultShrinkTransform ( info , numLevels , minPixelValue , maxPixelValue ) ; DenoiseWavelet denoiser = FactoryDenoiseWaveletAlg . bayes ( null , imageType ) ; return new WaveletDenoiseFilter < > ( descTran , denoiser ) ; }
Denoises an image using BayesShrink wavelet denoiser .
27,523
private static WaveletTransform createDefaultShrinkTransform ( ImageDataType imageType , int numLevels , double minPixelValue , double maxPixelValue ) { WaveletTransform descTran ; if ( ! imageType . isInteger ( ) ) { WaveletDescription < WlCoef_F32 > waveletDesc_F32 = FactoryWaveletDaub . daubJ_F32 ( 4 ) ; descTran = FactoryWaveletTransform . create_F32 ( waveletDesc_F32 , numLevels , ( float ) minPixelValue , ( float ) maxPixelValue ) ; } else { WaveletDescription < WlCoef_I32 > waveletDesc_I32 = FactoryWaveletDaub . biorthogonal_I32 ( 5 , BorderType . REFLECT ) ; descTran = FactoryWaveletTransform . create_I ( waveletDesc_I32 , numLevels , ( int ) minPixelValue , ( int ) maxPixelValue , ImageType . getImageClass ( ImageType . Family . GRAY , imageType ) ) ; } return descTran ; }
Default wavelet transform used for denoising images .
27,524
public static int minusPOffset ( int index , int offset , int size ) { index -= offset ; if ( index < 0 ) { return size + index ; } else { return index ; } }
Subtracts a positive offset to index in a circular buffer .
27,525
public static int distanceP ( int index0 , int index1 , int size ) { int difference = index1 - index0 ; if ( difference < 0 ) { difference = size + difference ; } return difference ; }
Returns how many elements away in the positive direction you need to travel to get from index0 to index1 .
27,526
public static int subtract ( int index0 , int index1 , int size ) { int distance = distanceP ( index0 , index1 , size ) ; if ( distance >= size / 2 + size % 2 ) { return distance - size ; } else { return distance ; } }
Subtracts index1 from index0 . positive number if its closer in the positive direction or negative if closer in the negative direction . if equal distance then it will return a negative number .
27,527
protected static void removeChildInsidePanel ( JComponent root , JComponent target ) { int N = root . getComponentCount ( ) ; for ( int i = 0 ; i < N ; i ++ ) { try { JPanel p = ( JPanel ) root . getComponent ( i ) ; Component [ ] children = p . getComponents ( ) ; for ( int j = 0 ; j < children . length ; j ++ ) { if ( children [ j ] == target ) { root . remove ( i ) ; return ; } } } catch ( ClassCastException ignore ) { } } }
Searches inside the children of root for a component that s a JPanel . Then inside the JPanel it looks for the target . If the target is inside the JPanel the JPanel is removed from root .
27,528
protected static void removeChildAndPrevious ( JComponent root , JComponent target ) { int N = root . getComponentCount ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( root . getComponent ( i ) == target ) { root . remove ( i ) ; root . remove ( i - 1 ) ; return ; } } throw new RuntimeException ( "Can't find component" ) ; }
Searches inside the children of root for target . If found it is removed and the previous component .
27,529
public static float distanceSq ( float [ ] a , float [ ] b ) { float ret = 0 ; for ( int i = 0 ; i < a . length ; i ++ ) { float d = a [ i ] - b [ i ] ; ret += d * d ; } return ret ; }
Returns the Euclidean distance squared between the two vectors
27,530
protected float weight ( float distance ) { float findex = distance * 100f ; int index = ( int ) findex ; if ( index >= 99 ) return weightTable [ 99 ] ; float sample0 = weightTable [ index ] ; float sample1 = weightTable [ index + 1 ] ; float w = findex - index ; return sample0 * ( 1f - w ) + sample1 * w ; }
Returns the weight given the normalized distance . Instead of computing the kernel distance every time a lookup table with linear interpolation is used . The distance has a domain from 0 to 1 inclusive
27,531
public void process ( ) { processed = true ; for ( int i = 0 ; i < histogram . length ; i ++ ) { histogram [ i ] /= total ; } }
No more features are being added . Normalized the computed histogram .
27,532
public void transform ( GrayU8 binary ) { ImageMiscOps . fill ( transform , 0 ) ; originX = binary . width / 2 ; originY = binary . height / 2 ; r_max = Math . sqrt ( originX * originX + originY * originY ) ; for ( int y = 0 ; y < binary . height ; y ++ ) { int start = binary . startIndex + y * binary . stride ; int stop = start + binary . width ; for ( int index = start ; index < stop ; index ++ ) { if ( binary . data [ index ] != 0 ) { parameterize ( index - start , y ) ; } } } }
Computes the Hough transform of the image .
27,533
public void lineToCoordinate ( LineParametric2D_F32 line , Point2D_F64 coordinate ) { line = line . copy ( ) ; line . p . x -= originX ; line . p . y -= originY ; LinePolar2D_F32 polar = new LinePolar2D_F32 ( ) ; UtilLine2D_F32 . convert ( line , polar ) ; if ( polar . angle < 0 ) { polar . distance = - polar . distance ; polar . angle = UtilAngle . toHalfCircle ( polar . angle ) ; } int w2 = transform . width / 2 ; coordinate . x = ( int ) Math . floor ( polar . distance * w2 / r_max ) + w2 ; coordinate . y = polar . angle * transform . height / Math . PI ; }
Compute the parameterized coordinate for the line
27,534
public void parameterize ( int x , int y ) { x -= originX ; y -= originY ; int w2 = transform . width / 2 ; for ( int i = 0 ; i < transform . height ; i ++ ) { double p = x * tableTrig . c [ i ] + y * tableTrig . s [ i ] ; int col = ( int ) Math . floor ( p * w2 / r_max ) + w2 ; int index = transform . startIndex + i * transform . stride + col ; transform . data [ index ] ++ ; } }
Converts the pixel coordinate into a line in parameter space
27,535
public void set ( Vector3D_F64 l1 , Vector3D_F64 l2 ) { this . l1 . set ( l1 ) ; this . l2 . set ( l2 ) ; }
Sets the value of p1 and p2 to be equal to the values of the passed in objects
27,536
public void setClassificationData ( List < HistogramScene > memory , int numScenes ) { nn . setPoints ( memory , false ) ; scenes = new double [ numScenes ] ; }
Provides a set of labeled word histograms to use to classify a new image
27,537
public int classify ( T image ) { if ( numNeighbors == 0 ) throw new IllegalArgumentException ( "Must specify number of neighbors!" ) ; describe . process ( image ) ; featureToHistogram . reset ( ) ; List < Desc > imageFeatures = describe . getDescriptions ( ) ; for ( int i = 0 ; i < imageFeatures . size ( ) ; i ++ ) { Desc d = imageFeatures . get ( i ) ; featureToHistogram . addFeature ( d ) ; } featureToHistogram . process ( ) ; temp . histogram = featureToHistogram . getHistogram ( ) ; resultsNN . reset ( ) ; search . findNearest ( temp , - 1 , numNeighbors , resultsNN ) ; Arrays . fill ( scenes , 0 ) ; for ( int i = 0 ; i < resultsNN . size ; i ++ ) { NnData < HistogramScene > data = resultsNN . get ( i ) ; HistogramScene n = data . point ; scenes [ n . type ] += 1.0 / ( data . distance + 0.005 ) ; } int bestIndex = 0 ; double bestCount = 0 ; for ( int i = 0 ; i < scenes . length ; i ++ ) { if ( scenes [ i ] > bestCount ) { bestCount = scenes [ i ] ; bestIndex = i ; } } return bestIndex ; }
Finds the scene which most resembles the provided image
27,538
public void unusual ( ) { pyramid = FactoryPyramid . discreteGaussian ( new int [ ] { 2 , 6 } , - 1 , 2 , true , ImageType . single ( imageType ) ) ; Kernel1D kernel ; if ( GeneralizedImageOps . isFloatingPoint ( imageType ) ) { kernel = FactoryKernel . table1D_F32 ( 2 , true ) ; } else { kernel = FactoryKernel . table1D_I32 ( 2 ) ; } }
Creates a more unusual pyramid and updater .
27,539
public void process ( BufferedImage image ) { T input = ConvertBufferedImage . convertFromSingle ( image , null , imageType ) ; pyramid . process ( input ) ; DiscretePyramidPanel gui = new DiscretePyramidPanel ( ) ; gui . setPyramid ( pyramid ) ; gui . render ( ) ; ShowImages . showWindow ( gui , "Image Pyramid" ) ; T imageAtScale = pyramid . getLayer ( 1 ) ; ShowImages . showWindow ( ConvertBufferedImage . convertTo ( imageAtScale , null , true ) , "Image at layer 1" ) ; }
Updates and displays the pyramid .
27,540
public static < T extends ImageGray < T > > ImageFunctionSparse < T > createLaplacian ( Class < T > imageType , ImageBorder < T > border ) { if ( border == null ) { border = FactoryImageBorder . single ( imageType , BorderType . EXTENDED ) ; } if ( GeneralizedImageOps . isFloatingPoint ( imageType ) ) { ImageConvolveSparse < GrayF32 , Kernel2D_F32 > r = FactoryConvolveSparse . convolve2D ( GrayF32 . class , DerivativeLaplacian . kernel_F32 ) ; r . setImageBorder ( ( ImageBorder_F32 ) border ) ; return ( ImageFunctionSparse < T > ) r ; } else { ImageConvolveSparse r = FactoryConvolveSparse . convolve2D ( GrayI . class , DerivativeLaplacian . kernel_I32 ) ; r . setImageBorder ( border ) ; return ( ImageFunctionSparse < T > ) r ; } }
Creates a sparse Laplacian filter .
27,541
public static < T extends ImageGray < T > , G extends GradientValue > SparseImageGradient < T , G > createSobel ( Class < T > imageType , ImageBorder < T > border ) { if ( imageType == GrayF32 . class ) { return ( SparseImageGradient ) new GradientSparseSobel_F32 ( ( ImageBorder_F32 ) border ) ; } else if ( imageType == GrayU8 . class ) { return ( SparseImageGradient ) new GradientSparseSobel_U8 ( ( ImageBorder_S32 ) border ) ; } else { throw new IllegalArgumentException ( "Unsupported image type " + imageType . getSimpleName ( ) ) ; } }
Creates a sparse sobel gradient operator .
27,542
public static < T extends ImageGray < T > , G extends GradientValue > SparseImageGradient < T , G > createPrewitt ( Class < T > imageType , ImageBorder < T > border ) { if ( imageType == GrayF32 . class ) { return ( SparseImageGradient ) new GradientSparsePrewitt_F32 ( ( ImageBorder_F32 ) border ) ; } else if ( imageType == GrayU8 . class ) { return ( SparseImageGradient ) new GradientSparsePrewitt_U8 ( ( ImageBorder_S32 ) border ) ; } else { throw new IllegalArgumentException ( "Unsupported image type " + imageType . getSimpleName ( ) ) ; } }
Creates a sparse prewitt gradient operator .
27,543
public static < T extends ImageGray < T > , G extends GradientValue > SparseImageGradient < T , G > createThree ( Class < T > imageType , ImageBorder < T > border ) { if ( imageType == GrayF32 . class ) { return ( SparseImageGradient ) new GradientSparseThree_F32 ( ( ImageBorder_F32 ) border ) ; } else if ( imageType == GrayU8 . class ) { return ( SparseImageGradient ) new GradientSparseThree_U8 ( ( ImageBorder_S32 ) border ) ; } else { throw new IllegalArgumentException ( "Unsupported image type " + imageType . getSimpleName ( ) ) ; } }
Creates a sparse three gradient operator .
27,544
public static < T extends ImageGray < T > , G extends GradientValue > SparseImageGradient < T , G > createTwo0 ( Class < T > imageType , ImageBorder < T > border ) { if ( imageType == GrayF32 . class ) { return ( SparseImageGradient ) new GradientSparseTwo0_F32 ( ( ImageBorder_F32 ) border ) ; } else if ( imageType == GrayU8 . class ) { return ( SparseImageGradient ) new GradientSparseTwo0_U8 ( ( ImageBorder_S32 ) border ) ; } else { throw new IllegalArgumentException ( "Unsupported image type " + imageType . getSimpleName ( ) ) ; } }
Creates a sparse two - 0 gradient operator .
27,545
public static < T extends ImageGray < T > , G extends GradientValue > SparseImageGradient < T , G > createTwo1 ( Class < T > imageType , ImageBorder < T > border ) { if ( imageType == GrayF32 . class ) { return ( SparseImageGradient ) new GradientSparseTwo1_F32 ( ( ImageBorder_F32 ) border ) ; } else if ( imageType == GrayU8 . class ) { return ( SparseImageGradient ) new GradientSparseTwo1_U8 ( ( ImageBorder_S32 ) border ) ; } else { throw new IllegalArgumentException ( "Unsupported image type " + imageType . getSimpleName ( ) ) ; } }
Creates a sparse two - 1 gradient operator .
27,546
public void process ( T image1 , T image2 ) { if ( pyr1 == null || pyr1 . getInputWidth ( ) != image1 . width || pyr1 . getInputHeight ( ) != image1 . height ) { pyr1 = UtilDenseOpticalFlow . standardPyramid ( image1 . width , image1 . height , scale , sigma , 5 , maxLayers , GrayF32 . class ) ; pyr2 = UtilDenseOpticalFlow . standardPyramid ( image1 . width , image1 . height , scale , sigma , 5 , maxLayers , GrayF32 . class ) ; pyr1 . initialize ( image1 . width , image1 . height ) ; pyr2 . initialize ( image1 . width , image1 . height ) ; } norm1 . reshape ( image1 . width , image1 . height ) ; norm2 . reshape ( image1 . width , image1 . height ) ; imageNormalization ( image1 , image2 , norm1 , norm2 ) ; pyr1 . process ( norm1 ) ; pyr2 . process ( norm2 ) ; process ( pyr1 , pyr2 ) ; }
Processes the raw input images . Normalizes them and creates image pyramids from them .
27,547
protected static < T extends ImageGray < T > > void imageNormalization ( T image1 , T image2 , GrayF32 normalized1 , GrayF32 normalized2 ) { float max1 = ( float ) GImageStatistics . max ( image1 ) ; float max2 = ( float ) GImageStatistics . max ( image2 ) ; float min1 = ( float ) GImageStatistics . min ( image1 ) ; float min2 = ( float ) GImageStatistics . min ( image2 ) ; float max = max1 > max2 ? max1 : max2 ; float min = min1 < min2 ? min1 : min2 ; float range = max - min ; if ( range > 0 ) { int indexN = 0 ; for ( int y = 0 ; y < image1 . height ; y ++ ) { for ( int x = 0 ; x < image1 . width ; x ++ , indexN ++ ) { float pv1 = ( float ) GeneralizedImageOps . get ( image1 , x , y ) ; float pv2 = ( float ) GeneralizedImageOps . get ( image2 , x , y ) ; normalized1 . data [ indexN ] = ( pv1 - min ) / range ; normalized2 . data [ indexN ] = ( pv2 - min ) / range ; } } } else { GConvertImage . convert ( image1 , normalized1 ) ; GConvertImage . convert ( image2 , normalized2 ) ; } }
Function to normalize the images between 0 and 255 .
27,548
public boolean process ( AssociatedPair p1 , AssociatedPair p2 , AssociatedPair p3 ) { fillM ( p1 . p1 , p2 . p1 , p3 . p1 ) ; b . x = computeB ( p1 . p2 ) ; b . y = computeB ( p2 . p2 ) ; b . z = computeB ( p3 . p2 ) ; if ( ! solver . setA ( M ) ) return false ; GeometryMath_F64 . toMatrix ( b , temp0 ) ; solver . solve ( temp0 , temp1 ) ; GeometryMath_F64 . toTuple3D ( temp1 , A_inv_b ) ; GeometryMath_F64 . addOuterProd ( A , - 1 , e2 , A_inv_b , H ) ; adjust . adjust ( H , p1 ) ; return true ; }
Estimates the homography from view 1 to view 2 induced by a plane from 3 point associations . Each pair must pass the epipolar constraint . This can fail if the points are colinear .
27,549
private void fillM ( Point2D_F64 x1 , Point2D_F64 x2 , Point2D_F64 x3 ) { M . data [ 0 ] = x1 . x ; M . data [ 1 ] = x1 . y ; M . data [ 2 ] = 1 ; M . data [ 3 ] = x2 . x ; M . data [ 4 ] = x2 . y ; M . data [ 5 ] = 1 ; M . data [ 6 ] = x3 . x ; M . data [ 7 ] = x3 . y ; M . data [ 8 ] = 1 ; }
Fill rows of M with observations from image 1
27,550
public boolean decompose ( DMatrix4x4 Q ) { CommonOps_DDF4 . scale ( 1.0 / Q . a33 , Q ) ; k . a11 = Q . a11 ; k . a12 = Q . a12 ; k . a13 = Q . a13 ; k . a21 = Q . a21 ; k . a22 = Q . a22 ; k . a23 = Q . a23 ; k . a31 = Q . a31 ; k . a32 = Q . a32 ; k . a33 = Q . a33 ; if ( ! CommonOps_DDF3 . invert ( k , w_inv ) ) return false ; k . set ( w_inv ) ; k . a11 = Math . abs ( k . a11 ) ; k . a22 = Math . abs ( k . a22 ) ; k . a33 = Math . abs ( k . a33 ) ; if ( ! CommonOps_DDF3 . cholU ( k ) ) return false ; if ( ! CommonOps_DDF3 . invert ( k , k ) ) return false ; CommonOps_DDF3 . divide ( k , k . a33 ) ; t . a1 = Q . a14 ; t . a2 = Q . a24 ; t . a3 = Q . a34 ; CommonOps_DDF3 . mult ( w_inv , t , p ) ; CommonOps_DDF3 . scale ( - 1 , p ) ; CommonOps_DDF3 . multTransB ( k , k , w ) ; return true ; }
Decomposes the passed in absolute quadratic
27,551
public void recomputeQ ( DMatrix4x4 Q ) { CommonOps_DDF3 . multTransB ( k , k , w ) ; Q . a11 = w . a11 ; Q . a12 = w . a12 ; Q . a13 = w . a13 ; Q . a21 = w . a21 ; Q . a22 = w . a22 ; Q . a23 = w . a23 ; Q . a31 = w . a31 ; Q . a32 = w . a32 ; Q . a33 = w . a33 ; CommonOps_DDF3 . mult ( w , p , t ) ; CommonOps_DDF3 . scale ( - 1 , t ) ; Q . a14 = t . a1 ; Q . a24 = t . a2 ; Q . a34 = t . a3 ; Q . a41 = t . a1 ; Q . a42 = t . a2 ; Q . a43 = t . a3 ; Q . a44 = - CommonOps_DDF3 . dot ( t , p ) ; }
Recomputes Q from w and p .
27,552
public boolean computeRectifyingHomography ( DMatrixRMaj H ) { H . reshape ( 4 , 4 ) ; H . zero ( ) ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = i ; j < 3 ; j ++ ) { H . set ( i , j , k . get ( i , j ) ) ; } } H . set ( 3 , 0 , - ( p . a1 * k . a11 + p . a2 * k . a21 + p . a3 * k . a31 ) ) ; H . set ( 3 , 1 , - ( p . a1 * k . a12 + p . a2 * k . a22 + p . a3 * k . a32 ) ) ; H . set ( 3 , 2 , - ( p . a1 * k . a13 + p . a2 * k . a23 + p . a3 * k . a33 ) ) ; H . set ( 3 , 3 , 1 ) ; return true ; }
Computes the rectifying homography from the decomposed Q
27,553
public void process ( ) { Webcam webcam = UtilWebcamCapture . openDefault ( desiredWidth , desiredHeight ) ; Dimension actualSize = webcam . getViewSize ( ) ; setPreferredSize ( actualSize ) ; setMinimumSize ( actualSize ) ; window . setMinimumSize ( actualSize ) ; window . setPreferredSize ( actualSize ) ; window . setVisible ( true ) ; T input = tracker . getImageType ( ) . createImage ( actualSize . width , actualSize . height ) ; workImage = new BufferedImage ( input . getWidth ( ) , input . getHeight ( ) , BufferedImage . TYPE_INT_RGB ) ; while ( true ) { BufferedImage buffered = webcam . getImage ( ) ; if ( buffered == null ) break ; ConvertBufferedImage . convertFrom ( webcam . getImage ( ) , input , true ) ; int mode = this . mode ; boolean success = false ; if ( mode == 2 ) { Rectangle2D_F64 rect = new Rectangle2D_F64 ( ) ; rect . set ( point0 . x , point0 . y , point1 . x , point1 . y ) ; UtilPolygons2D_F64 . convert ( rect , target ) ; success = tracker . initialize ( input , target ) ; this . mode = success ? 3 : 0 ; } else if ( mode == 3 ) { success = tracker . process ( input , target ) ; } synchronized ( workImage ) { Graphics2D g2 = workImage . createGraphics ( ) ; g2 . drawImage ( buffered , 0 , 0 , null ) ; if ( mode == 1 ) { drawSelected ( g2 ) ; } else if ( mode == 3 ) { if ( success ) { drawTrack ( g2 ) ; } } } repaint ( ) ; } }
Invoke to start the main processing loop .
27,554
public static void easy ( GrayF32 image ) { DetectDescribePoint < GrayF32 , BrightFeature > surf = FactoryDetectDescribe . surfStable ( new ConfigFastHessian ( 0 , 2 , 200 , 2 , 9 , 4 , 4 ) , null , null , GrayF32 . class ) ; surf . detect ( image ) ; System . out . println ( "Found Features: " + surf . getNumberOfFeatures ( ) ) ; System . out . println ( "First descriptor's first value: " + surf . getDescription ( 0 ) . value [ 0 ] ) ; }
Use generalized interfaces for working with SURF . This removes much of the drudgery but also reduces flexibility and slightly increases memory and computational requirements .
27,555
public static < II extends ImageGray < II > > void harder ( GrayF32 image ) { Class < II > integralType = GIntegralImageOps . getIntegralType ( GrayF32 . class ) ; NonMaxSuppression extractor = FactoryFeatureExtractor . nonmax ( new ConfigExtract ( 2 , 0 , 5 , true ) ) ; FastHessianFeatureDetector < II > detector = new FastHessianFeatureDetector < > ( extractor , 200 , 2 , 9 , 4 , 4 , 6 ) ; OrientationIntegral < II > orientation = FactoryOrientationAlgs . sliding_ii ( null , integralType ) ; DescribePointSurf < II > descriptor = FactoryDescribePointAlgs . < II > surfStability ( null , integralType ) ; II integral = GeneralizedImageOps . createSingleBand ( integralType , image . width , image . height ) ; GIntegralImageOps . transform ( image , integral ) ; detector . detect ( integral ) ; orientation . setImage ( integral ) ; descriptor . setImage ( integral ) ; List < ScalePoint > points = detector . getFoundPoints ( ) ; List < BrightFeature > descriptions = new ArrayList < > ( ) ; for ( ScalePoint p : points ) { orientation . setObjectRadius ( p . scale * BoofDefaults . SURF_SCALE_TO_RADIUS ) ; double angle = orientation . compute ( p . x , p . y ) ; BrightFeature desc = descriptor . createDescription ( ) ; descriptor . describe ( p . x , p . y , angle , p . scale , desc ) ; descriptions . add ( desc ) ; } System . out . println ( "Found Features: " + points . size ( ) ) ; System . out . println ( "First descriptor's first value: " + descriptions . get ( 0 ) . value [ 0 ] ) ; }
Configured exactly the same as the easy example above but require a lot more code and a more in depth understanding of how SURF works and is configured . Instead of TupleDesc_F64 SurfFeature are computed in this case . They are almost the same as TupleDesc_F64 but contain the Laplacian s sign which can be used to speed up association . That is an example of how using less generalized interfaces can improve performance .
27,556
public void updateBackground ( MotionModel homeToCurrent , T frame ) { worldToHome . concat ( homeToCurrent , worldToCurrent ) ; worldToCurrent . invert ( currentToWorld ) ; transform . setModel ( currentToWorld ) ; transform . compute ( 0 , 0 , corners [ 0 ] ) ; transform . compute ( frame . width - 1 , 0 , corners [ 1 ] ) ; transform . compute ( frame . width - 1 , frame . height - 1 , corners [ 2 ] ) ; transform . compute ( 0 , frame . height - 1 , corners [ 3 ] ) ; int x0 = Integer . MAX_VALUE ; int y0 = Integer . MAX_VALUE ; int x1 = - Integer . MAX_VALUE ; int y1 = - Integer . MAX_VALUE ; for ( int i = 0 ; i < 4 ; i ++ ) { Point2D_F32 p = corners [ i ] ; int x = ( int ) p . x ; int y = ( int ) p . y ; if ( x0 > x ) x0 = x ; if ( y0 > y ) y0 = y ; if ( x1 < x ) x1 = x ; if ( y1 < y ) y1 = y ; } x1 ++ ; y1 ++ ; if ( x0 < 0 ) x0 = 0 ; if ( x1 > backgroundWidth ) x1 = backgroundWidth ; if ( y0 < 0 ) y0 = 0 ; if ( y1 > backgroundHeight ) y1 = backgroundHeight ; updateBackground ( x0 , y0 , x1 , y1 , frame ) ; }
Updates the background with new image information .
27,557
public void segment ( MotionModel homeToCurrent , T frame , GrayU8 segmented ) { InputSanityCheck . checkSameShape ( frame , segmented ) ; worldToHome . concat ( homeToCurrent , worldToCurrent ) ; worldToCurrent . invert ( currentToWorld ) ; _segment ( currentToWorld , frame , segmented ) ; }
Invoke to use the background image to segment the current frame into background and foreground pixels
27,558
public void process ( Polygon2D_F64 polygon , boolean clockwise ) { int N = polygon . size ( ) ; segments . resize ( N ) ; for ( int i = N - 1 , j = 0 ; j < N ; i = j , j ++ ) { int ii , jj ; if ( clockwise ) { ii = i ; jj = j ; } else { ii = j ; jj = i ; } Point2D_F64 a = polygon . get ( ii ) , b = polygon . get ( jj ) ; double dx = b . x - a . x ; double dy = b . y - a . y ; double l = Math . sqrt ( dx * dx + dy * dy ) ; if ( l == 0 ) { throw new RuntimeException ( "Two identical corners!" ) ; } if ( dx < 0 ) dx = 0 ; if ( dy > 0 ) dy = 0 ; LineSegment2D_F64 s = segments . get ( ii ) ; s . a . x = a . x - dy / l ; s . a . y = a . y + dx / l ; s . b . x = b . x - dy / l ; s . b . y = b . y + dx / l ; } for ( int i = N - 1 , j = 0 ; j < N ; i = j , j ++ ) { int ii , jj ; if ( clockwise ) { ii = i ; jj = j ; } else { ii = j ; jj = i ; } UtilLine2D_F64 . convert ( segments . get ( ii ) , ga ) ; UtilLine2D_F64 . convert ( segments . get ( jj ) , gb ) ; if ( null != Intersection2D_F64 . intersection ( ga , gb , intersection ) ) { if ( intersection . distance2 ( polygon . get ( jj ) ) < 20 ) { polygon . get ( jj ) . set ( intersection ) ; } } } UtilPolygons2D_F64 . removeAdjacentDuplicates ( polygon , 1e-8 ) ; }
Processes and adjusts the polygon . If after adjustment a corner needs to be removed because two sides are parallel then the size of the polygon can be changed .
27,559
static int closestCorner4 ( Grid g ) { double bestDistance = g . get ( 0 , 0 ) . center . normSq ( ) ; int bestIdx = 0 ; double d = g . get ( 0 , g . columns - 1 ) . center . normSq ( ) ; if ( d < bestDistance ) { bestDistance = d ; bestIdx = 3 ; } d = g . get ( g . rows - 1 , g . columns - 1 ) . center . normSq ( ) ; if ( d < bestDistance ) { bestDistance = d ; bestIdx = 2 ; } d = g . get ( g . rows - 1 , 0 ) . center . normSq ( ) ; if ( d < bestDistance ) { bestIdx = 1 ; } return bestIdx ; }
Number of CCW rotations to put selected corner into the canonical location . Only works when there are 4 possible solutions
27,560
void rotateGridCCW ( Grid g ) { work . clear ( ) ; for ( int i = 0 ; i < g . rows * g . columns ; i ++ ) { work . add ( null ) ; } for ( int row = 0 ; row < g . rows ; row ++ ) { for ( int col = 0 ; col < g . columns ; col ++ ) { work . set ( col * g . rows + row , g . get ( g . rows - row - 1 , col ) ) ; } } g . ellipses . clear ( ) ; g . ellipses . addAll ( work ) ; int tmp = g . columns ; g . columns = g . rows ; g . rows = tmp ; }
performs a counter - clockwise rotation
27,561
void reverse ( Grid g ) { work . clear ( ) ; int N = g . rows * g . columns ; for ( int i = 0 ; i < N ; i ++ ) { work . add ( g . ellipses . get ( N - i - 1 ) ) ; } g . ellipses . clear ( ) ; g . ellipses . addAll ( work ) ; }
Reverse the order of elements inside the grid
27,562
static void pruneIncorrectShape ( FastQueue < Grid > grids , int numRows , int numCols ) { for ( int i = grids . size ( ) - 1 ; i >= 0 ; i -- ) { Grid g = grids . get ( i ) ; if ( ( g . rows != numRows || g . columns != numCols ) && ( g . rows != numCols || g . columns != numRows ) ) { grids . remove ( i ) ; } } }
Remove grids which cannot possible match the expected shape
27,563
static void pruneIncorrectSize ( List < List < EllipsesIntoClusters . Node > > clusters , int N ) { for ( int i = clusters . size ( ) - 1 ; i >= 0 ; i -- ) { if ( clusters . get ( i ) . size ( ) != N ) { clusters . remove ( i ) ; } } }
Prune clusters which do not have the expected number of elements
27,564
public boolean process ( T input , GrayU8 binary ) { double maxCornerDistancePixels = maxCornerDistance . computeI ( Math . min ( input . width , input . height ) ) ; s2c . setMaxCornerDistance ( maxCornerDistancePixels ) ; configureContourDetector ( input ) ; boundPolygon . vertexes . reset ( ) ; detectorSquare . process ( input , binary ) ; detectorSquare . refineAll ( ) ; List < DetectPolygonFromContour . Info > found = detectorSquare . getPolygonInfo ( ) ; clusters = s2c . process ( found ) ; c2g . process ( clusters ) ; List < SquareGrid > grids = c2g . getGrids ( ) . toList ( ) ; for ( int i = 0 ; i < grids . size ( ) ; i ++ ) { SquareGrid grid = grids . get ( i ) ; if ( grid . rows == numCols && grid . columns == numRows ) { tools . transpose ( grid ) ; } if ( grid . rows == numRows && grid . columns == numCols ) { if ( grid . get ( 0 , 0 ) == null ) { if ( grid . get ( 0 , - 1 ) != null ) { tools . flipColumns ( grid ) ; } else if ( grid . get ( - 1 , 0 ) != null ) { tools . flipRows ( grid ) ; } else { continue ; } } if ( ! ensureCCW ( grid ) ) continue ; putIntoCanonical ( grid ) ; return computeCalibrationPoints ( grid ) ; } } return false ; }
Detects chessboard in the binary image . Square corners must be disconnected . Returns true if a chessboard was found false otherwise .
27,565
public void adjustBeforeOptimize ( Polygon2D_F64 polygon , GrowQueue_B touchesBorder , boolean clockwise ) { int N = polygon . size ( ) ; work . vertexes . resize ( N ) ; for ( int i = 0 ; i < N ; i ++ ) { work . get ( i ) . set ( 0 , 0 ) ; } for ( int i = N - 1 , j = 0 ; j < N ; i = j , j ++ ) { int ii , jj , kk , mm ; if ( clockwise ) { mm = CircularIndex . addOffset ( - 1 , i , N ) ; ii = i ; jj = j ; kk = CircularIndex . addOffset ( 1 , j , N ) ; } else { mm = CircularIndex . addOffset ( 1 , j , N ) ; ii = j ; jj = i ; kk = CircularIndex . addOffset ( - 1 , i , N ) ; } Point2D_F64 a = polygon . get ( ii ) , b = polygon . get ( jj ) ; double dx = b . x - a . x ; double dy = b . y - a . y ; double l = Math . sqrt ( dx * dx + dy * dy ) ; if ( l == 0 ) { throw new RuntimeException ( "Input polygon has two identical corners. You need to fix that." ) ; } dx *= 1.5 / l ; dy *= 1.5 / l ; Point2D_F64 _a = work . get ( ii ) ; Point2D_F64 _b = work . get ( jj ) ; if ( touchesBorder . size > 0 && touchesBorder . get ( ii ) ) { if ( ! touchesBorder . get ( mm ) ) { _a . x -= dx ; _a . y -= dy ; } } else { _a . x += - dy ; _a . y += dx ; } if ( touchesBorder . size > 0 && touchesBorder . get ( jj ) ) { if ( ! touchesBorder . get ( kk ) ) { _b . x += dx ; _b . y += dy ; } } else { _b . x += - dy ; _b . y += dx ; } } for ( int i = 0 ; i < N ; i ++ ) { Point2D_F64 a = polygon . get ( i ) ; Point2D_F64 b = work . get ( i ) ; a . x += b . x ; a . y += b . y ; } }
The polygon detected from the contour is too small because the binary image was eroded . This expand the size of the polygon so that it fits the image edge better
27,566
boolean computeCalibrationPoints ( SquareGrid grid ) { calibrationPoints . reset ( ) ; for ( int row = 0 ; row < grid . rows - 1 ; row ++ ) { int offset = row % 2 ; for ( int col = offset ; col < grid . columns ; col += 2 ) { SquareNode a = grid . get ( row , col ) ; if ( col > 0 ) { SquareNode b = grid . get ( row + 1 , col - 1 ) ; if ( ! setIntersection ( a , b , calibrationPoints . grow ( ) ) ) return false ; } if ( col < grid . columns - 1 ) { SquareNode b = grid . get ( row + 1 , col + 1 ) ; if ( ! setIntersection ( a , b , calibrationPoints . grow ( ) ) ) return false ; } } } return true ; }
Find inner corner points across the grid . Start from the top row and work its way down . Corners are found by finding the average point between two adjacent corners on adjacent squares .
27,567
public static void process ( GrayI input , GrayI output , int radius , int [ ] storage ) { int w = 2 * radius + 1 ; if ( storage == null ) { storage = new int [ w * w ] ; } else if ( storage . length < w * w ) { throw new IllegalArgumentException ( "'storage' must be at least of length " + ( w * w ) ) ; } for ( int y = 0 ; y < input . height ; y ++ ) { int minI = y - radius ; int maxI = y + radius + 1 ; if ( minI < 0 ) minI = 0 ; if ( maxI > input . height ) maxI = input . height ; for ( int x = 0 ; x < input . width ; x ++ ) { int minJ = x - radius ; int maxJ = x + radius + 1 ; if ( minJ < 0 ) minJ = 0 ; if ( maxJ > input . width ) maxJ = input . width ; int index = 0 ; for ( int i = minI ; i < maxI ; i ++ ) { for ( int j = minJ ; j < maxJ ; j ++ ) { storage [ index ++ ] = input . get ( j , i ) ; } } int median = QuickSelect . select ( storage , index / 2 , index ) ; output . set ( x , y , median ) ; } } }
Performs a median filter .
27,568
public static < I extends ImageGray < I > , D extends ImageGray < D > > PointTracker < I > dda_ST_BRIEF ( int maxAssociationError , ConfigGeneralDetector configExtract , Class < I > imageType , Class < D > derivType ) { if ( derivType == null ) derivType = GImageDerivativeOps . getDerivativeType ( imageType ) ; DescribePointBrief < I > brief = FactoryDescribePointAlgs . brief ( FactoryBriefDefinition . gaussian2 ( new Random ( 123 ) , 16 , 512 ) , FactoryBlurFilter . gaussian ( ImageType . single ( imageType ) , 0 , 4 ) ) ; GeneralFeatureDetector < I , D > detectPoint = createShiTomasi ( configExtract , derivType ) ; EasyGeneralFeatureDetector < I , D > easy = new EasyGeneralFeatureDetector < > ( detectPoint , imageType , derivType ) ; ScoreAssociateHamming_B score = new ScoreAssociateHamming_B ( ) ; AssociateDescription2D < TupleDesc_B > association = new AssociateDescTo2D < > ( FactoryAssociation . greedy ( score , maxAssociationError , true ) ) ; DdaManagerGeneralPoint < I , D , TupleDesc_B > manager = new DdaManagerGeneralPoint < > ( easy , new WrapDescribeBrief < > ( brief , imageType ) , 1.0 ) ; return new DetectDescribeAssociate < > ( manager , association , new ConfigTrackerDda ( ) ) ; }
Creates a tracker which detects Shi - Tomasi corner features and describes them with BRIEF .
27,569
public static < I extends ImageGray < I > , D extends ImageGray < D > > PointTracker < I > dda_FAST_BRIEF ( ConfigFastCorner configFast , ConfigGeneralDetector configExtract , int maxAssociationError , Class < I > imageType ) { DescribePointBrief < I > brief = FactoryDescribePointAlgs . brief ( FactoryBriefDefinition . gaussian2 ( new Random ( 123 ) , 16 , 512 ) , FactoryBlurFilter . gaussian ( ImageType . single ( imageType ) , 0 , 4 ) ) ; GeneralFeatureDetector < I , D > corner = FactoryDetectPoint . createFast ( configFast , configExtract , imageType ) ; EasyGeneralFeatureDetector < I , D > easy = new EasyGeneralFeatureDetector < > ( corner , imageType , null ) ; ScoreAssociateHamming_B score = new ScoreAssociateHamming_B ( ) ; AssociateDescription2D < TupleDesc_B > association = new AssociateDescTo2D < > ( FactoryAssociation . greedy ( score , maxAssociationError , true ) ) ; DdaManagerGeneralPoint < I , D , TupleDesc_B > manager = new DdaManagerGeneralPoint < > ( easy , new WrapDescribeBrief < > ( brief , imageType ) , 1.0 ) ; return new DetectDescribeAssociate < > ( manager , association , new ConfigTrackerDda ( ) ) ; }
Creates a tracker which detects FAST corner features and describes them with BRIEF .
27,570
public static < I extends ImageGray < I > , Desc extends TupleDesc > DetectDescribeAssociate < I , Desc > dda ( InterestPointDetector < I > detector , OrientationImage < I > orientation , DescribeRegionPoint < I , Desc > describe , AssociateDescription2D < Desc > associate , ConfigTrackerDda config ) { DetectDescribeFusion < I , Desc > fused = new DetectDescribeFusion < > ( detector , orientation , describe ) ; DdaManagerDetectDescribePoint < I , Desc > manager = new DdaManagerDetectDescribePoint < > ( fused ) ; DetectDescribeAssociate < I , Desc > dat = new DetectDescribeAssociate < > ( manager , associate , config ) ; return dat ; }
Creates a tracker which uses the detect describe associate architecture .
27,571
public static < I extends ImageGray < I > > PointTracker < I > combined_FH_SURF_KLT ( PkltConfig kltConfig , int reactivateThreshold , ConfigFastHessian configDetector , ConfigSurfDescribe . Stability configDescribe , ConfigSlidingIntegral configOrientation , Class < I > imageType ) { ScoreAssociation < TupleDesc_F64 > score = FactoryAssociation . defaultScore ( TupleDesc_F64 . class ) ; AssociateSurfBasic assoc = new AssociateSurfBasic ( FactoryAssociation . greedy ( score , 100000 , true ) ) ; AssociateDescription < BrightFeature > generalAssoc = new WrapAssociateSurfBasic ( assoc ) ; DetectDescribePoint < I , BrightFeature > fused = FactoryDetectDescribe . surfStable ( configDetector , configDescribe , configOrientation , imageType ) ; return combined ( fused , generalAssoc , kltConfig , reactivateThreshold , imageType ) ; }
Creates a tracker which detects Fast - Hessian features describes them with SURF nominally tracks them using KLT .
27,572
public static < I extends ImageGray < I > , D extends ImageGray < D > > GeneralFeatureDetector < I , D > createShiTomasi ( ConfigGeneralDetector config , Class < D > derivType ) { GradientCornerIntensity < D > cornerIntensity = FactoryIntensityPointAlg . shiTomasi ( 1 , false , derivType ) ; return FactoryDetectPoint . createGeneral ( cornerIntensity , config ) ; }
Creates a Shi - Tomasi corner detector specifically designed for SFM . Smaller feature radius work better . Variable detectRadius to control the number of features . When larger features are used weighting should be set to true but because this is so small it is set to false
27,573
public void handleWebcam ( ) { final Webcam webcam = openSelectedCamera ( ) ; if ( desiredWidth > 0 && desiredHeight > 0 ) UtilWebcamCapture . adjustResolution ( webcam , desiredWidth , desiredHeight ) ; webcam . open ( ) ; Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( ) { public void run ( ) { if ( webcam . isOpen ( ) ) { System . out . println ( "Closing webcam" ) ; webcam . close ( ) ; } } } ) ; ComputeGeometryScore quality = new ComputeGeometryScore ( zeroSkew , detector . getLayout ( ) ) ; AssistedCalibrationGui gui = new AssistedCalibrationGui ( webcam . getViewSize ( ) ) ; JFrame frame = ShowImages . showWindow ( gui , "Webcam Calibration" , true ) ; GrayF32 gray = new GrayF32 ( webcam . getViewSize ( ) . width , webcam . getViewSize ( ) . height ) ; if ( desiredWidth > 0 && desiredHeight > 0 ) { if ( gray . width != desiredWidth || gray . height != desiredHeight ) System . err . println ( "Actual camera resolution does not match desired. Actual: " + gray . width + " " + gray . height + " Desired: " + desiredWidth + " " + desiredHeight ) ; } AssistedCalibration assisted = new AssistedCalibration ( detector , quality , gui , OUTPUT_DIRECTORY , IMAGE_DIRECTORY ) ; assisted . init ( gray . width , gray . height ) ; BufferedImage image ; while ( ( image = webcam . getImage ( ) ) != null && ! assisted . isFinished ( ) ) { ConvertBufferedImage . convertFrom ( image , gray ) ; try { assisted . process ( gray , image ) ; } catch ( RuntimeException e ) { System . err . println ( "BUG!!! saving image to crash_image.png" ) ; UtilImageIO . saveImage ( image , "crash_image.png" ) ; throw e ; } } webcam . close ( ) ; if ( assisted . isFinished ( ) ) { frame . setVisible ( false ) ; inputDirectory = new File ( OUTPUT_DIRECTORY , IMAGE_DIRECTORY ) . getPath ( ) ; outputFileName = new File ( OUTPUT_DIRECTORY , "intrinsic.yaml" ) . getPath ( ) ; handleDirectory ( ) ; } }
Captures calibration data live using a webcam and a GUI to assist the user
27,574
public void setTemplate ( GrayF32 image , List < Point2D_F64 > sides ) { if ( sides . size ( ) != 4 ) throw new IllegalArgumentException ( "Expected 4 sidesCollision" ) ; removePerspective . apply ( image , sides . get ( 0 ) , sides . get ( 1 ) , sides . get ( 2 ) , sides . get ( 3 ) ) ; templateOriginal . setTo ( removePerspective . getOutput ( ) ) ; GrayF32 blurred = new GrayF32 ( LENGTH , LENGTH ) ; BlurImageOps . gaussian ( templateOriginal , blurred , - 1 , 2 , null ) ; GrayF32 derivX = new GrayF32 ( LENGTH , LENGTH ) ; GrayF32 derivY = new GrayF32 ( LENGTH , LENGTH ) ; GImageDerivativeOps . gradient ( DerivativeType . SOBEL , blurred , derivX , derivY , BorderType . EXTENDED ) ; GGradientToEdgeFeatures . intensityE ( derivX , derivY , weights ) ; float max = ImageStatistics . max ( weights ) ; PixelMath . divide ( weights , max , weights ) ; totalWeight = ImageStatistics . sum ( weights ) ; template . setTo ( removePerspective . getOutput ( ) ) ; float mean = ( float ) ImageStatistics . mean ( template ) ; PixelMath . divide ( template , mean , template ) ; }
Creates a template of the fiducial and this is then used to determine how blurred the image is
27,575
public synchronized void process ( GrayF32 image , List < Point2D_F64 > sides ) { if ( sides . size ( ) != 4 ) throw new IllegalArgumentException ( "Expected 4 sidesCollision" ) ; updateScore ( image , sides ) ; if ( currentScore < bestScore ) { bestScore = currentScore ; if ( bestImage == null ) { bestImage = new BufferedImage ( image . getWidth ( ) , image . getHeight ( ) , BufferedImage . TYPE_INT_RGB ) ; } ConvertBufferedImage . convertTo ( image , bestImage ) ; } }
Computes the sharpness score for the current image if better than the current best image it s then saved .
27,576
public synchronized void updateScore ( GrayF32 image , List < Point2D_F64 > sides ) { removePerspective . apply ( image , sides . get ( 0 ) , sides . get ( 1 ) , sides . get ( 2 ) , sides . get ( 3 ) ) ; GrayF32 current = removePerspective . getOutput ( ) ; float mean = ( float ) ImageStatistics . mean ( current ) ; PixelMath . divide ( current , mean , tempImage ) ; PixelMath . diffAbs ( tempImage , template , difference ) ; PixelMath . multiply ( difference , weights , difference ) ; currentScore = ImageStatistics . sum ( difference ) / totalWeight ; }
Used when you just want to update the score for visualization purposes but not update the best image .
27,577
public synchronized void save ( ) { if ( bestImage != null ) { File path = new File ( outputDirectory , String . format ( "image%04d.png" , imageNumber ) ) ; UtilImageIO . saveImage ( bestImage , path . getAbsolutePath ( ) ) ; imageNumber ++ ; } clearHistory ( ) ; }
Saves the image to a file
27,578
public void setImageRepaint ( BufferedImage image ) { ScaleOffset workspace ; if ( SwingUtilities . isEventDispatchThread ( ) ) { workspace = adjustmentGUI ; } else { workspace = new ScaleOffset ( ) ; } repaintJustImage ( img , workspace ) ; this . img = image ; if ( image != null ) { repaintJustImage ( img , workspace ) ; } else { repaint ( ) ; } }
Changes the buffered image and calls repaint . Does not need to be called in the UI thread .
27,579
private void computeContainment ( int imageArea ) { contRect . x0 = contRect . y0 = Double . MAX_VALUE ; contRect . x1 = contRect . y1 = - Double . MAX_VALUE ; for ( AssociatedPair p : motion . getModelMatcher ( ) . getMatchSet ( ) ) { Point2D_F64 t = p . p2 ; if ( t . x > contRect . x1 ) contRect . x1 = t . x ; if ( t . y > contRect . y1 ) contRect . y1 = t . y ; if ( t . x < contRect . x0 ) contRect . x0 = t . x ; if ( t . y < contRect . y0 ) contRect . y0 = t . y ; } containment = contRect . area ( ) / imageArea ; }
Computes an axis - aligned rectangle that contains all the inliers . It then computes the area contained in that rectangle to the total area of the image
27,580
public boolean pruneViews ( int count ) { List < SceneStructureProjective . View > remainingS = new ArrayList < > ( ) ; List < SceneObservations . View > remainingO = new ArrayList < > ( ) ; int counts [ ] = new int [ structure . views . length ] ; for ( int pointIdx = 0 ; pointIdx < structure . points . length ; pointIdx ++ ) { GrowQueue_I32 viewsIn = structure . points [ pointIdx ] . views ; for ( int i = 0 ; i < viewsIn . size ; i ++ ) { counts [ viewsIn . get ( i ) ] ++ ; } } for ( int viewIdx = 0 ; viewIdx < structure . views . length ; viewIdx ++ ) { if ( counts [ viewIdx ] > count ) { remainingS . add ( structure . views [ viewIdx ] ) ; remainingO . add ( observations . views [ viewIdx ] ) ; } else { structure . views [ viewIdx ] . width = - 2 ; } } for ( int pointIdx = 0 ; pointIdx < structure . points . length ; pointIdx ++ ) { GrowQueue_I32 viewsIn = structure . points [ pointIdx ] . views ; for ( int i = viewsIn . size - 1 ; i >= 0 ; i -- ) { SceneStructureProjective . View v = structure . views [ viewsIn . get ( i ) ] ; if ( v . width == - 2 ) { viewsIn . remove ( i ) ; } } } if ( structure . views . length == remainingS . size ( ) ) { return false ; } structure . views = new SceneStructureProjective . View [ remainingS . size ( ) ] ; observations . views = new SceneObservations . View [ remainingO . size ( ) ] ; for ( int i = 0 ; i < structure . views . length ; i ++ ) { structure . views [ i ] = remainingS . get ( i ) ; observations . views [ i ] = remainingO . get ( i ) ; } return true ; }
Removes views with less than count features visible . Observations of features in removed views are also removed . Features are not automatically removed even if there are zero observations of them .
27,581
public void process ( Input left , Input right , Disparity disparity ) { InputSanityCheck . checkSameShape ( left , right , disparity ) ; if ( maxDisparity > left . width - 2 * radiusX ) throw new RuntimeException ( "The maximum disparity is too large for this image size: max size " + ( left . width - 2 * radiusX ) ) ; lengthHorizontal = left . width * rangeDisparity ; _process ( left , right , disparity ) ; }
Computes disparity between two stereo images
27,582
public GeometricResult solve ( ) { if ( cameras . size < minimumProjectives ) throw new IllegalArgumentException ( "You need at least " + minimumProjectives + " motions" ) ; int N = cameras . size ; DMatrixRMaj L = new DMatrixRMaj ( N * eqs , 10 ) ; constructMatrix ( L ) ; if ( ! svd . decompose ( L ) ) { return GeometricResult . SOLVE_FAILED ; } extractSolutionForQ ( Q ) ; double sv [ ] = svd . getSingularValues ( ) ; Arrays . sort ( sv ) ; if ( singularThreshold * sv [ 1 ] <= sv [ 0 ] ) { return GeometricResult . GEOMETRY_POOR ; } if ( ! MultiViewOps . enforceAbsoluteQuadraticConstraints ( Q , true , zeroSkew ) ) { return GeometricResult . SOLVE_FAILED ; } computeSolutions ( Q ) ; if ( solutions . size ( ) != N ) { return GeometricResult . SOLUTION_NAN ; } else { return GeometricResult . SUCCESS ; } }
Solve for camera calibration . A sanity check is performed to ensure that a valid calibration is found . All values must be countable numbers and the focal lengths must be positive numbers .
27,583
private void extractSolutionForQ ( DMatrix4x4 Q ) { DMatrixRMaj nv = new DMatrixRMaj ( 10 , 1 ) ; SingularOps_DDRM . nullVector ( svd , true , nv ) ; encodeQ ( Q , nv . data ) ; if ( Q . a11 < 0 || Q . a22 < 0 || Q . a33 < 0 ) { CommonOps_DDF4 . scale ( - 1 , Q ) ; } }
Extracts the null space and converts it into the Q matrix
27,584
private void computeSolutions ( DMatrix4x4 Q ) { DMatrixRMaj w_i = new DMatrixRMaj ( 3 , 3 ) ; for ( int i = 0 ; i < cameras . size ; i ++ ) { computeW ( cameras . get ( i ) , Q , w_i ) ; Intrinsic calib = solveForCalibration ( w_i ) ; if ( sanityCheck ( calib ) ) { solutions . add ( calib ) ; } } }
Computes the calibration for each view ..
27,585
private Intrinsic solveForCalibration ( DMatrixRMaj w ) { Intrinsic calib = new Intrinsic ( ) ; if ( zeroSkew ) { calib . skew = 0 ; calib . fy = Math . sqrt ( w . get ( 1 , 1 ) ) ; if ( knownAspect ) { calib . fx = calib . fy / aspectRatio ; } else { calib . fx = Math . sqrt ( w . get ( 0 , 0 ) ) ; } } else if ( knownAspect ) { calib . fy = Math . sqrt ( w . get ( 1 , 1 ) ) ; calib . fx = calib . fy / aspectRatio ; calib . skew = w . get ( 0 , 1 ) / calib . fy ; } else { calib . fy = Math . sqrt ( w . get ( 1 , 1 ) ) ; calib . skew = w . get ( 0 , 1 ) / calib . fy ; calib . fx = Math . sqrt ( w . get ( 0 , 0 ) - calib . skew * calib . skew ) ; } return calib ; }
Given the solution for w and the constraints solve for the remaining parameters
27,586
boolean sanityCheck ( Intrinsic calib ) { if ( UtilEjml . isUncountable ( calib . fx ) ) return false ; if ( UtilEjml . isUncountable ( calib . fy ) ) return false ; if ( UtilEjml . isUncountable ( calib . skew ) ) return false ; if ( calib . fx < 0 ) return false ; if ( calib . fy < 0 ) return false ; return true ; }
Makes sure that the found solution is valid and physically possible
27,587
private int selectRightToLeft ( int col , int [ ] scores ) { int localMax = Math . min ( imageWidth - regionWidth , col + maxDisparity ) - col - minDisparity ; int indexBest = 0 ; int indexScore = col ; int scoreBest = scores [ col ] ; indexScore += imageWidth + 1 ; for ( int i = 1 ; i < localMax ; i ++ , indexScore += imageWidth + 1 ) { int s = scores [ indexScore ] ; if ( s < scoreBest ) { scoreBest = s ; indexBest = i ; } } return indexBest ; }
Finds the best disparity going from right to left image .
27,588
public void process ( FastQueue < TldRegion > regions , FastQueue < TldRegion > output ) { final int N = regions . size ; conn . growArray ( N ) ; for ( int i = 0 ; i < N ; i ++ ) { conn . data [ i ] . reset ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { TldRegion ra = regions . get ( i ) ; Connections ca = conn . data [ i ] ; for ( int j = i + 1 ; j < N ; j ++ ) { TldRegion rb = regions . get ( j ) ; Connections cb = conn . data [ j ] ; double overlap = helper . computeOverlap ( ra . rect , rb . rect ) ; if ( overlap < connectionThreshold ) { continue ; } ca . maximum &= ra . confidence > rb . confidence ; cb . maximum &= rb . confidence > ra . confidence ; ra . connections ++ ; rb . connections ++ ; } } for ( int i = 0 ; i < N ; i ++ ) { TldRegion ra = regions . get ( i ) ; Connections ca = conn . data [ i ] ; if ( ca . maximum ) { TldRegion o = output . grow ( ) ; o . connections = ra . connections ; o . confidence = ra . confidence ; o . rect . set ( ra . rect ) ; } else if ( ra . connections == 0 ) { System . out . println ( "Not a maximum but has zero connections?" ) ; } } }
Finds local maximums from the set of provided regions
27,589
public T createImage ( int width , int height ) { switch ( family ) { case GRAY : return ( T ) GeneralizedImageOps . createSingleBand ( getImageClass ( ) , width , height ) ; case INTERLEAVED : return ( T ) GeneralizedImageOps . createInterleaved ( getImageClass ( ) , width , height , numBands ) ; case PLANAR : return ( T ) new Planar ( getImageClass ( ) , width , height , numBands ) ; default : throw new IllegalArgumentException ( "Type not yet supported" ) ; } }
Creates a new image .
27,590
public T [ ] createArray ( int length ) { switch ( family ) { case GRAY : case INTERLEAVED : return ( T [ ] ) Array . newInstance ( getImageClass ( ) , length ) ; case PLANAR : return ( T [ ] ) new Planar [ length ] ; default : throw new IllegalArgumentException ( "Type not yet supported" ) ; } }
Creates an array of the specified iamge type
27,591
public boolean isSameType ( ImageType o ) { if ( family != o . family ) return false ; if ( dataType != o . dataType ) return false ; if ( numBands != o . numBands ) return false ; return true ; }
Returns true if the passed in ImageType is the same as this image type
27,592
public void setTo ( ImageType o ) { this . family = o . family ; this . dataType = o . dataType ; this . numBands = o . numBands ; }
Sets this to be identical to o
27,593
void growCellArray ( int imageWidth , int imageHeight ) { cellCols = imageWidth / pixelsPerCell ; cellRows = imageHeight / pixelsPerCell ; if ( cellRows * cellCols > cells . length ) { Cell [ ] a = new Cell [ cellCols * cellRows ] ; System . arraycopy ( cells , 0 , a , 0 , cells . length ) ; for ( int i = cells . length ; i < a . length ; i ++ ) { a [ i ] = new Cell ( ) ; a [ i ] . histogram = new float [ orientationBins ] ; } cells = a ; } }
Determines if the cell array needs to grow . If it does a new array is declared . Old data is recycled when possible
27,594
public void getDescriptorsInRegion ( int pixelX0 , int pixelY0 , int pixelX1 , int pixelY1 , List < TupleDesc_F64 > output ) { int gridX0 = ( int ) Math . ceil ( pixelX0 / ( double ) pixelsPerCell ) ; int gridY0 = ( int ) Math . ceil ( pixelY0 / ( double ) pixelsPerCell ) ; int gridX1 = pixelX1 / pixelsPerCell - cellsPerBlockX ; int gridY1 = pixelY1 / pixelsPerCell - cellsPerBlockY ; for ( int y = gridY0 ; y <= gridY1 ; y ++ ) { int index = y * cellCols + gridX0 ; for ( int x = gridX0 ; x <= gridX1 ; x ++ ) { output . add ( descriptions . get ( index ++ ) ) ; } } }
Convenience function which returns a list of all the descriptors computed inside the specified region in the image
27,595
void computeCellHistograms ( ) { int width = cellCols * pixelsPerCell ; int height = cellRows * pixelsPerCell ; float angleBinSize = GrlConstants . F_PI / orientationBins ; int indexCell = 0 ; for ( int i = 0 ; i < height ; i += pixelsPerCell ) { for ( int j = 0 ; j < width ; j += pixelsPerCell , indexCell ++ ) { Cell c = cells [ indexCell ] ; c . reset ( ) ; for ( int k = 0 ; k < pixelsPerCell ; k ++ ) { int indexPixel = ( i + k ) * derivX . width + j ; for ( int l = 0 ; l < pixelsPerCell ; l ++ , indexPixel ++ ) { float pixelDX = this . derivX . data [ indexPixel ] ; float pixelDY = this . derivY . data [ indexPixel ] ; float angle = UtilAngle . atanSafe ( pixelDY , pixelDX ) + GrlConstants . F_PId2 ; float magnitude = ( float ) Math . sqrt ( pixelDX * pixelDX + pixelDY * pixelDY ) ; float findex0 = angle / angleBinSize ; int index0 = ( int ) findex0 ; float weight1 = findex0 - index0 ; index0 %= orientationBins ; int index1 = ( index0 + 1 ) % orientationBins ; c . histogram [ index0 ] += magnitude * ( 1.0f - weight1 ) ; c . histogram [ index1 ] += magnitude * weight1 ; } } } } }
Compute histograms for all the cells inside the image using precomputed derivative .
27,596
public void detect ( II grayII , Planar < II > colorII ) { descriptions . reset ( ) ; featureAngles . reset ( ) ; detector . detect ( grayII ) ; foundPoints = detector . getFoundPoints ( ) ; descriptions . resize ( foundPoints . size ( ) ) ; featureAngles . resize ( foundPoints . size ( ) ) ; describe ( grayII , colorII ) ; }
Detects and describes features inside provide images . All images are integral images .
27,597
public List < Point3D_F64 > getLandmark3D ( int version ) { int N = QrCode . totalModules ( version ) ; set3D ( 0 , 0 , N , point3D . get ( 0 ) ) ; set3D ( 0 , 7 , N , point3D . get ( 1 ) ) ; set3D ( 7 , 7 , N , point3D . get ( 2 ) ) ; set3D ( 7 , 0 , N , point3D . get ( 3 ) ) ; set3D ( 0 , N - 7 , N , point3D . get ( 4 ) ) ; set3D ( 0 , N , N , point3D . get ( 5 ) ) ; set3D ( 7 , N , N , point3D . get ( 6 ) ) ; set3D ( 7 , N - 7 , N , point3D . get ( 7 ) ) ; set3D ( N - 7 , 0 , N , point3D . get ( 8 ) ) ; set3D ( N - 7 , 7 , N , point3D . get ( 9 ) ) ; set3D ( N , 7 , N , point3D . get ( 10 ) ) ; set3D ( N , 0 , N , point3D . get ( 11 ) ) ; return point3D ; }
Location of each corner in the QR Code s reference frame in 3D
27,598
private void setPair ( int which , int row , int col , int N , Point2D_F64 pixel ) { set3D ( row , col , N , point23 . get ( which ) . location ) ; pixelToNorm . compute ( pixel . x , pixel . y , point23 . get ( which ) . observation ) ; }
Specifies PNP parameters for a single feature
27,599
private void set3D ( int row , int col , int N , Point3D_F64 location ) { double _N = N ; double gridX = 2.0 * ( col / _N - 0.5 ) ; double gridY = 2.0 * ( 0.5 - row / _N ) ; location . set ( gridX , gridY , 0 ) ; }
Specifies 3D location of landmark in marker coordinate system