Package boofcv.misc

Class BoofMiscOps

java.lang.Object
boofcv.misc.BoofMiscOps

public class BoofMiscOps extends Object
Miscellaneous functions which have no better place to go.
  • Field Details

    • VERBOSE_PREFIX_LENGTH

      public static int VERBOSE_PREFIX_LENGTH
      Number of characters in the class name prefix in verbose printing
    • VERBOSE_PRINT_TABLE

      public static boolean VERBOSE_PRINT_TABLE
      Prints a table explaining what the prefixes are
  • Constructor Details

    • BoofMiscOps

      public BoofMiscOps()
  • Method Details

    • timeNano

      public static long timeNano(BoofLambdas.ProcessCall process)
      Computes the elapsed time in calling the provided function in nano seconds
    • profile

      public static void profile(BoofLambdas.ProcessCall process, String description)
    • timeStr

      public static String timeStr()
    • timeStr

      public static String timeStr(long systemTimeMS)
    • handlePathTilde

      public static String handlePathTilde(String path)
      Checks to see if the passed in string starts with a ~ and if so it will replace it with the users home directory.
    • bound

      public static float bound(float value, float min, float max)
    • bound

      public static double bound(double value, double min, double max)
    • offsetPixels

      public static void offsetPixels(List<Point2D_F64> list, double dx, double dy)
    • toStringArray

      public static String[] toStringArray(List<File> files)
    • copyAll

      public static <Point extends GeoTuple<Point>> void copyAll(FastAccess<Point> src, DogArray<Point> dst)
      Copies all of src into dst by appended it onto it
    • toFileList

      public static List<File> toFileList(String[] files)
    • asList

      public static <T> List<T> asList(T... objects)
    • toFileList

      public static List<File> toFileList(List<String> files)
    • bitsToWords

      public static int bitsToWords(int bits, int wordBits)
    • numBands

      public static int numBands(ImageBase img)
    • milliToHuman

      public static String milliToHuman(long milliseconds)
    • diffRatio

      public static double diffRatio(double a, double b)
    • numDigits

      public static int numDigits(int number)
      Returns the number of digits in a number. E.g. 345 = 3, -345 = 4, 0 = 1
    • pow2

      public static double pow2(double v)
    • pow2

      public static float pow2(float v)
    • sortFileNames

      public static void sortFileNames(List<String> images)
    • sortFilesByName

      public static void sortFilesByName(List<File> images)
    • printMethodInfo

      public static void printMethodInfo(Method target, PrintStream out)
    • parseDimension

      public static boolean parseDimension(String text, ImageDimension dimension)
      Parses the string into a dimension. The two numbers are seperated with a colon.
    • quadraticSolver

      public static int quadraticSolver(double a, double b, double c, double[] solutions)
      Carefully constructed quadratic equation solver that attempts to maximize numerical stability and gracefully handle zeros in coefficients.

      a*x*x + b*c + c = 0. Solve for x.

      Parameters:
      solutions - (Output) storage for up to two solutions.
      Returns:
      Number of valid solutions found
    • toString

      public static String toString(Reader r)
    • countNotZero

      public static int countNotZero(int[] a, int size)
    • convertTo_F64

      public static double[] convertTo_F64(int[] a)
    • convertTo_F32

      public static float[] convertTo_F32(double[] a, float[] ret)
    • convertTo_I32

      public static int[] convertTo_I32(double[] a, int[] ret)
    • boundRectangleInside

      public static void boundRectangleInside(ImageBase b, ImageRectangle r)
      Bounds the provided rectangle to be inside the image.
      Parameters:
      b - An image.
      r - Rectangle
    • min

      public static double min(double a, double b, double c)
    • min

      public static float min(float a, float b, float c)
    • min

      public static int min(int a, int b, int c)
    • isInside

      public static boolean isInside(ImageBase b, ImageRectangle r)
    • isInside

      public static boolean isInside(ImageBase b, int x, int y, int radius)
      Returns true if the point is contained inside the image and 'radius' away from the image border.
      Parameters:
      b - Image
      x - x-coordinate of point
      y - y-coordinate of point
      radius - How many pixels away from the border it needs to be to be considered inside
      Returns:
      true if the point is inside and false if it is outside
    • isInside

      public static boolean isInside(ImageBase b, float x, float y, float radius)
      Returns true if the point is contained inside the image and 'radius' away from the image border.
      Parameters:
      b - Image
      x - x-coordinate of point
      y - y-coordinate of point
      radius - How many pixels away from the border it needs to be to be considered inside
      Returns:
      true if the point is inside and false if it is outside
    • isInside

      public static boolean isInside(ImageBase b, double x, double y, double radius)
      Returns true if the point is contained inside the image and 'radius' away from the image border.
      Parameters:
      b - Image
      x - x-coordinate of point
      y - y-coordinate of point
      radius - How many pixels away from the border it needs to be to be considered inside
      Returns:
      true if the point is inside and false if it is outside
    • isInside

      public static boolean isInside(ImageBase b, int x, int y, int radiusWidth, int radiusHeight)
    • isInside

      public static boolean isInside(ImageBase b, int c_x, int c_y, int radius, double theta)
    • isInside

      public static boolean isInside(ImageBase b, float x, float y)
    • isInside

      public static boolean isInside(ImageBase b, double x, double y)
    • isInside

      public static boolean isInside(int width, int height, float x, float y)
    • isInside

      public static boolean isInside(int width, int height, double x, double y)
    • pause

      public static void pause(long milli)
      Invokes wait until the elapsed time has passed. In the thread is interrupted, the interrupt is ignored.
      Parameters:
      milli - Length of desired pause in milliseconds.
    • print

      public static void print(ImageGray a)
    • print

      public static void print(GrayF64 a)
    • print

      public static void print(GrayF32 a)
    • print

      public static void print(InterleavedF32 a)
    • print

      public static void print(GrayI a)
    • convertArray

      public static int[] convertArray(double[] input, @Nullable @org.jetbrains.annotations.Nullable int[] output)
    • convertArray

      public static long[] convertArray(double[] input, @Nullable @org.jetbrains.annotations.Nullable long[] output)
    • convertArray

      public static float[] convertArray(double[] input, @Nullable @org.jetbrains.annotations.Nullable float[] output)
    • convertArray

      public static double[] convertArray(float[] input, @Nullable @org.jetbrains.annotations.Nullable double[] output)
    • convertArray

      public static int[] convertArray(float[] input, @Nullable @org.jetbrains.annotations.Nullable int[] output)
    • convertArray

      public static float[] convertArray(int[] input, @Nullable @org.jetbrains.annotations.Nullable float[] output)
    • sleep

      public static void sleep(long milli)
    • checkTrue

      public static void checkTrue(boolean result)
    • checkTrue

      public static void checkTrue(boolean result, String message)
    • checkEq

      public static void checkEq(int valA, int valB)
    • checkEq

      public static void checkEq(int valA, int valB, String message)
    • checkSame

      public static void checkSame(Object a, Object b)
    • checkSame

      public static void checkSame(Object a, Object b, String message)
    • checkFraction

      public static void checkFraction(double fraction, String message)
      Checks to see if the passed in value is a fraction from 0 to 1.0, inclusive
    • forIdx

      public static <T> void forIdx(List<T> list, BoofLambdas.ProcessIndex<T> func)
    • indexOf

      public static <T> int indexOf(List<T> list, BoofLambdas.Filter<T> op)
      Searches the list for the first index where the operation returns true. When a match is found it returns the index. Otherwise it returns -1 if no match is found.
    • collectList

      public static <In, Out> List<Out> collectList(List<In> list, BoofLambdas.Extract<In,Out> func)
      Extracts elements from a list and returns a list
    • uniform

      public static double uniform(double min, double max, Random rand)
      Returns a random number from min to max, inclusive.
    • uniform

      public static float uniform(float min, float max, Random rand)
      Returns a random number from min to max, inclusive.
    • tail

      public static <T> T tail(List<T> list)
      Returns the last element in the list. Does not check if the list is empty
    • removeTail

      public static <T> T removeTail(List<T> list)
      Returns and removes the last element in the list. Does not check if the list is empty
    • toString

      public static <T> String toString(T o, BoofLambdas.ToString<T> op)
      Safe way to convert an object to string which checks to see if object is null
    • columnMaxAbsRow

      public static int columnMaxAbsRow(DMatrixRMaj A, int column)
      Finds the row at the specified column with the maximum absolute value
      Parameters:
      A - (input) matrix
      column - column to inspect
      Returns:
      The row index
    • createListFilled

      public static <T> List<T> createListFilled(int total, BoofLambdas.Factory<T> factory)
    • getOrThrow

      public static <V> V getOrThrow(Map map, Object key) throws IOException
      Throws:
      IOException
    • listToArrayDouble

      public static double[] listToArrayDouble(Object o)
      Converts List&#60double&#62 into double[]. If already an array it simply returns the original array
    • containsDuplicates

      public static <T> boolean containsDuplicates(List<T> list)
      Checks to see if the list contains duplicate items
    • checkDeclare

      public static boolean[] checkDeclare(@Nullable @Nullable DogArray_B queue, int length, boolean zero)
    • checkDeclare

      public static byte[] checkDeclare(@Nullable @Nullable DogArray_I8 queue, int length, boolean zero)
    • checkDeclare

      public static int[] checkDeclare(@Nullable @Nullable DogArray_I32 queue, int length, boolean zero)
    • checkDeclare

      public static float[] checkDeclare(@Nullable @Nullable DogArray_F32 queue, int length, boolean zero)
    • checkDeclare

      public static double[] checkDeclare(@Nullable @Nullable DogArray_F64 queue, int length, boolean zero)
    • checkDeclare

      public static <T> GrowArray<T> checkDeclare(@Nullable @Nullable GrowArray<T> growable, ConcurrencyOps.NewInstance<T> factory)
    • similarity

      public static double similarity(String s1, String s2)
      Calculates the similarity (a number within 0 and 1) between two strings. This is case insensitive. Taken from stack overflow, which was taken from some place else.
    • editDistance

      public static int editDistance(String s1, String s2)
    • copyConfig

      public static <C extends Configuration> C copyConfig(C src)
      Creates a copy of the passed in Configuration
    • verboseChildren

      public static void verboseChildren(@Nullable @Nullable PrintStream out, @Nullable @Nullable Set<String> configuration, @Nullable @Nullable VerbosePrint... children)
      Function which handles boilerplate for support recursive verbose print
    • toStringLine

      public static <T> String toStringLine(List<T> list)
    • addPrefix

      @Nullable public static @Nullable PrintStream addPrefix(VerbosePrint owner, @Nullable @Nullable PrintStream out)
    • addPrefix

      @Nullable public static @Nullable PrintStream addPrefix(VerbosePrint owner, int numIndents, @Nullable @Nullable PrintStream out)
    • nameToShort

      public static String nameToShort(String name, int length)
      Assumes names are camel case and that the capital letters are important. Same for numbers
    • hashSet

      public static <T> Set<T> hashSet(T... values)
    • convertMatrix

      public static void convertMatrix(FMatrix2x2 src, DMatrixRMaj dst)
      Convert matrix and work in auto generate F32 code
    • convertMatrix

      public static void convertMatrix(DMatrix2x2 src, DMatrixRMaj dst)
      Convert matrix and work in auto generate F32 code
    • copySmart

      public static double[] copySmart(double[] src, @Nullable @org.jetbrains.annotations.Nullable double[] dst)
      Copies src into dst. If dst is not the correct size then a new instance is created and that returned.
    • generateBitMask

      public static int generateBitMask(int numBits)
      Generates mask where the first N bits are filled in with 1
    • getJavaVersion

      public static int getJavaVersion()
      Returns the major version of java or -1 if it failed.
    • castStringToByteArray

      public static byte[] castStringToByteArray(String message)
      Converts a string into a byte array. No encoding is used and it is literally casting each character into a byte. This is useful when you have a marker that really just encodes binary data.
      Parameters:
      message - String with raw bytes encoded inside of it.
      Returns:
      byte array conversion of the string.
    • md5sum

      public static String md5sum(byte[] data)
      Computes MD5SUM of byte data as a string
    • byteArrayToHex

      public static String byteArrayToHex(byte[] array)
    • bitToByteCount

      public static int bitToByteCount(int numBits)
      Returns number of bytes that are needed to store the specified number of bits
    • thresholdByImageSize

      public static double thresholdByImageSize(ConfigLength config, int width, int height)
      Standard formula for computing a relative threshold based on the image size. Computed as the average of the width and height. This it will scale linearly with the perimeter and not the area.
    • thresholdByImageSizeI

      public static int thresholdByImageSizeI(ConfigLength config, int width, int height)
      Standard formula for computing a relative threshold based on the image size. Computed as the average of the width and height. This it will scale linearly with the perimeter and not the area.
    • blockUntilTrue

      public static boolean blockUntilTrue(long timeoutMS, BoofLambdas.CheckTrue func)
      Blocks until the provided function returns true.
      Parameters:
      timeoutMS - Timeout in milliseconds. If ≤ 0 then it will never time out
      func - Function
      Returns:
      true if the function return true or false if it timed out.