Package boofcv.misc
Class BoofMiscOps
java.lang.Object
boofcv.misc.BoofMiscOps
Miscellaneous functions which have no better place to go.
-
Field Summary
Modifier and TypeFieldDescriptionstatic int
Number of characters in the class name prefix in verbose printingstatic boolean
Prints a table explaining what the prefixes are -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable PrintStream
addPrefix
(VerbosePrint owner, int numIndents, @Nullable PrintStream out) static @Nullable PrintStream
addPrefix
(VerbosePrint owner, @Nullable PrintStream out) static <T> List<T>
asList
(T... objects) static int
bitsToWords
(int bits, int wordBits) static int
bitToByteCount
(int numBits) Returns number of bytes that are needed to store the specified number of bitsstatic boolean
blockUntilTrue
(long timeoutMS, BoofLambdas.CheckTrue func) Blocks until the provided function returns true.static double
bound
(double value, double min, double max) static float
bound
(float value, float min, float max) static void
Bounds the provided rectangle to be inside the image.static String
byteArrayToHex
(byte[] array) static byte[]
castStringToByteArray
(String message) Converts a string into a byte array.static boolean[]
checkDeclare
(@Nullable DogArray_B queue, int length, boolean zero) static float[]
checkDeclare
(@Nullable DogArray_F32 queue, int length, boolean zero) static double[]
checkDeclare
(@Nullable DogArray_F64 queue, int length, boolean zero) static int[]
checkDeclare
(@Nullable DogArray_I32 queue, int length, boolean zero) static byte[]
checkDeclare
(@Nullable DogArray_I8 queue, int length, boolean zero) static <T> GrowArray<T>
checkDeclare
(@Nullable GrowArray<T> growable, ConcurrencyOps.NewInstance<T> factory) static void
checkEq
(int valA, int valB) static void
static void
checkFraction
(double fraction, String message) Checks to see if the passed in value is a fraction from 0 to 1.0, inclusivestatic void
static void
static void
checkTrue
(boolean result) static void
static <In,
Out> List<Out> collectList
(List<In> list, BoofLambdas.Extract<In, Out> func) Extracts elements from a list and returns a liststatic int
columnMaxAbsRow
(DMatrixRMaj A, int column) Finds the row at the specified column with the maximum absolute valuestatic <T> boolean
containsDuplicates
(List<T> list) Checks to see if the list contains duplicate itemsstatic float[]
convertArray
(double[] input, @org.jetbrains.annotations.Nullable float[] output) static int[]
convertArray
(double[] input, @org.jetbrains.annotations.Nullable int[] output) static long[]
convertArray
(double[] input, @org.jetbrains.annotations.Nullable long[] output) static double[]
convertArray
(float[] input, @org.jetbrains.annotations.Nullable double[] output) static int[]
convertArray
(float[] input, @org.jetbrains.annotations.Nullable int[] output) static float[]
convertArray
(int[] input, @org.jetbrains.annotations.Nullable float[] output) static void
convertMatrix
(DMatrix2x2 src, DMatrixRMaj dst) Convert matrix and work in auto generate F32 codestatic void
convertMatrix
(FMatrix2x2 src, DMatrixRMaj dst) Convert matrix and work in auto generate F32 codestatic float[]
convertTo_F32
(double[] a, float[] ret) static double[]
convertTo_F64
(int[] a) static int[]
convertTo_I32
(double[] a, int[] ret) static <Point extends GeoTuple<Point>>
voidcopyAll
(FastAccess<Point> src, DogArray<Point> dst) Copies all of src into dst by appended it onto itstatic <C extends Configuration>
CcopyConfig
(C src) Creates a copy of the passed inConfiguration
static double[]
copySmart
(double[] src, @org.jetbrains.annotations.Nullable double[] dst) Copies src into dst.static int
countNotZero
(int[] a, int size) static <T> List<T>
createListFilled
(int total, BoofLambdas.Factory<T> factory) static double
diffRatio
(double a, double b) static int
editDistance
(String s1, String s2) static <T> void
forIdx
(List<T> list, BoofLambdas.ProcessIndex<T> func) static int
generateBitMask
(int numBits) Generates mask where the first N bits are filled in with 1static int
Returns the major version of java or -1 if it failed.static <V> V
getOrThrow
(Map map, Object key) 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.static <T> Set<T>
hashSet
(T... values) static <T> int
indexOf
(List<T> list, BoofLambdas.Filter<T> op) Searches the list for the first index where the operation returns true.static boolean
isInside
(int width, int height, double x, double y) static boolean
isInside
(int width, int height, float x, float y) static boolean
static boolean
Returns true if the point is contained inside the image and 'radius' away from the image border.static boolean
static boolean
Returns true if the point is contained inside the image and 'radius' away from the image border.static boolean
Returns true if the point is contained inside the image and 'radius' away from the image border.static boolean
static boolean
static boolean
isInside
(ImageBase b, ImageRectangle r) static double[]
ConvertsList<double>
into double[].static String
md5sum
(byte[] data) Computes MD5SUM of byte data as a stringstatic String
milliToHuman
(long milliseconds) static double
min
(double a, double b, double c) static float
min
(float a, float b, float c) static int
min
(int a, int b, int c) static String
nameToShort
(String name, int length) Assumes names are camel case and that the capital letters are important.static int
static int
numDigits
(int number) Returns the number of digits in a number.static void
offsetPixels
(List<Point2D_F64> list, double dx, double dy) static boolean
parseDimension
(String text, ImageDimension dimension) Parses the string into a dimension.static void
pause
(long milli) Invokes wait until the elapsed time has passed.static double
pow2
(double v) static float
pow2
(float v) static void
static void
static void
static void
static void
static void
printMethodInfo
(Method target, PrintStream out) static void
profile
(BoofLambdas.ProcessCall process, String description) 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.static <T> T
removeTail
(List<T> list) Returns and removes the last element in the list.static double
similarity
(String s1, String s2) Calculates the similarity (a number within 0 and 1) between two strings.static void
sleep
(long milli) static void
sortFileNames
(List<String> images) static void
sortFilesByName
(List<File> images) static <T> T
Returns the last element in the list.static double
thresholdByImageSize
(ConfigLength config, int width, int height) Standard formula for computing a relative threshold based on the image size.static int
thresholdByImageSizeI
(ConfigLength config, int width, int height) Standard formula for computing a relative threshold based on the image size.static long
timeNano
(BoofLambdas.ProcessCall process) Computes the elapsed time in calling the provided function in nano secondsstatic String
timeStr()
static String
timeStr
(long systemTimeMS) toFileList
(String[] files) toFileList
(List<String> files) static String
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 nullstatic String[]
toStringArray
(List<File> files) static <T> String
toStringLine
(List<T> list) static double
Returns a random number from min to max, inclusive.static float
Returns a random number from min to max, inclusive.static void
verboseChildren
(@Nullable PrintStream out, @Nullable Set<String> configuration, @Nullable VerbosePrint... children) Function which handles boilerplate for support recursive verbose print
-
Field Details
-
VERBOSE_PREFIX_LENGTH
public static int VERBOSE_PREFIX_LENGTHNumber of characters in the class name prefix in verbose printing -
VERBOSE_PRINT_TABLE
public static boolean VERBOSE_PRINT_TABLEPrints a table explaining what the prefixes are
-
-
Constructor Details
-
BoofMiscOps
public BoofMiscOps()
-
-
Method Details
-
timeNano
Computes the elapsed time in calling the provided function in nano seconds -
profile
-
timeStr
-
timeStr
-
handlePathTilde
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
-
toStringArray
-
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
-
asList
-
toFileList
-
bitsToWords
public static int bitsToWords(int bits, int wordBits) -
numBands
-
milliToHuman
-
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
-
sortFilesByName
-
printMethodInfo
-
parseDimension
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
-
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
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
-
isInside
Returns true if the point is contained inside the image and 'radius' away from the image border.- Parameters:
b
- Imagex
- x-coordinate of pointy
- y-coordinate of pointradius
- 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
Returns true if the point is contained inside the image and 'radius' away from the image border.- Parameters:
b
- Imagex
- x-coordinate of pointy
- y-coordinate of pointradius
- 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
Returns true if the point is contained inside the image and 'radius' away from the image border.- Parameters:
b
- Imagex
- x-coordinate of pointy
- y-coordinate of pointradius
- 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
-
isInside
-
isInside
-
isInside
-
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
-
print
-
print
-
print
-
print
-
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
-
checkEq
public static void checkEq(int valA, int valB) -
checkEq
-
checkSame
-
checkSame
-
checkFraction
Checks to see if the passed in value is a fraction from 0 to 1.0, inclusive -
forIdx
-
indexOf
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
Extracts elements from a list and returns a list -
uniform
Returns a random number from min to max, inclusive. -
uniform
Returns a random number from min to max, inclusive. -
tail
Returns the last element in the list. Does not check if the list is empty -
removeTail
Returns and removes the last element in the list. Does not check if the list is empty -
toString
Safe way to convert an object to string which checks to see if object is null -
columnMaxAbsRow
Finds the row at the specified column with the maximum absolute value- Parameters:
A
- (input) matrixcolumn
- column to inspect- Returns:
- The row index
-
createListFilled
-
getOrThrow
- Throws:
IOException
-
listToArrayDouble
ConvertsList<double>
into double[]. If already an array it simply returns the original array -
containsDuplicates
Checks to see if the list contains duplicate items -
checkDeclare
public static boolean[] checkDeclare(@Nullable @Nullable DogArray_B queue, int length, boolean zero) -
checkDeclare
-
checkDeclare
-
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
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
-
copyConfig
Creates a copy of the passed inConfiguration
-
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
-
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
Assumes names are camel case and that the capital letters are important. Same for numbers -
hashSet
-
convertMatrix
Convert matrix and work in auto generate F32 code -
convertMatrix
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
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
Computes MD5SUM of byte data as a string -
byteArrayToHex
-
bitToByteCount
public static int bitToByteCount(int numBits) Returns number of bytes that are needed to store the specified number of bits -
thresholdByImageSize
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
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
Blocks until the provided function returns true.- Parameters:
timeoutMS
- Timeout in milliseconds. If ≤ 0 then it will never time outfunc
- Function- Returns:
- true if the function return true or false if it timed out.
-