repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1
value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/QrCodeAlignmentPatternLocator.java | QrCodeAlignmentPatternLocator.centerOnSquare | boolean centerOnSquare(QrCode.Alignment pattern, float guessY, float guessX) {
float step = 1;
float bestMag = Float.MAX_VALUE;
float bestX = guessX;
float bestY = guessY;
for (int i = 0; i < 10; i++) {
for (int row = 0; row < 3; row++) {
float gridy = guessY - 1f + row;
for (int col = 0; col < 3; col++) {
float gridx = guessX - 1f + col;
samples[row*3+col] = reader.read(gridy,gridx);
}
}
float dx = (samples[2]+samples[5]+samples[8])-(samples[0]+samples[3]+samples[6]);
float dy = (samples[6]+samples[7]+samples[8])-(samples[0]+samples[1]+samples[2]);
float r = (float)Math.sqrt(dx*dx + dy*dy);
if( bestMag > r ) {
// System.out.println("good step at "+i);
bestMag = r;
bestX = guessX;
bestY = guessY;
} else {
// System.out.println("bad step at "+i);
step *= 0.75f;
}
if( r > 0 ) {
guessX = bestX + step * dx / r;
guessY = bestY + step * dy / r;
} else {
break;
}
}
pattern.moduleFound.x = bestX;
pattern.moduleFound.y = bestY;
reader.gridToImage((float)pattern.moduleFound.y,(float)pattern.moduleFound.x,pattern.pixel);
return true;
} | java | boolean centerOnSquare(QrCode.Alignment pattern, float guessY, float guessX) {
float step = 1;
float bestMag = Float.MAX_VALUE;
float bestX = guessX;
float bestY = guessY;
for (int i = 0; i < 10; i++) {
for (int row = 0; row < 3; row++) {
float gridy = guessY - 1f + row;
for (int col = 0; col < 3; col++) {
float gridx = guessX - 1f + col;
samples[row*3+col] = reader.read(gridy,gridx);
}
}
float dx = (samples[2]+samples[5]+samples[8])-(samples[0]+samples[3]+samples[6]);
float dy = (samples[6]+samples[7]+samples[8])-(samples[0]+samples[1]+samples[2]);
float r = (float)Math.sqrt(dx*dx + dy*dy);
if( bestMag > r ) {
// System.out.println("good step at "+i);
bestMag = r;
bestX = guessX;
bestY = guessY;
} else {
// System.out.println("bad step at "+i);
step *= 0.75f;
}
if( r > 0 ) {
guessX = bestX + step * dx / r;
guessY = bestY + step * dy / r;
} else {
break;
}
}
pattern.moduleFound.x = bestX;
pattern.moduleFound.y = bestY;
reader.gridToImage((float)pattern.moduleFound.y,(float)pattern.moduleFound.x,pattern.pixel);
return true;
} | [
"boolean",
"centerOnSquare",
"(",
"QrCode",
".",
"Alignment",
"pattern",
",",
"float",
"guessY",
",",
"float",
"guessX",
")",
"{",
"float",
"step",
"=",
"1",
";",
"float",
"bestMag",
"=",
"Float",
".",
"MAX_VALUE",
";",
"float",
"bestX",
"=",
"guessX",
"... | If the initial guess is within the inner white circle or black dot this will ensure that it is centered
on the black dot | [
"If",
"the",
"initial",
"guess",
"is",
"within",
"the",
"inner",
"white",
"circle",
"or",
"black",
"dot",
"this",
"will",
"ensure",
"that",
"it",
"is",
"centered",
"on",
"the",
"black",
"dot"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/QrCodeAlignmentPatternLocator.java#L153-L198 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/QrCodeAlignmentPatternLocator.java | QrCodeAlignmentPatternLocator.localize | boolean localize(QrCode.Alignment pattern, float guessY, float guessX)
{
// sample along the middle. Try to not sample the outside edges which could confuse it
for (int i = 0; i < arrayY.length; i++) {
float x = guessX - 1.5f + i*3f/12.0f;
float y = guessY - 1.5f + i*3f/12.0f;
arrayX[i] = reader.read(guessY,x);
arrayY[i] = reader.read(y,guessX);
}
// TODO turn this into an exhaustive search of the array for best up and down point?
int downX = greatestDown(arrayX);
if( downX == -1) return false;
int upX = greatestUp(arrayX,downX);
if( upX == -1) return false;
int downY = greatestDown(arrayY);
if( downY == -1 ) return false;
int upY = greatestUp(arrayY,downY);
if( upY == -1 ) return false;
pattern.moduleFound.x = guessX - 1.5f + (downX+upX)*3f/24.0f;
pattern.moduleFound.y = guessY - 1.5f + (downY+upY)*3f/24.0f;
reader.gridToImage((float)pattern.moduleFound.y,(float)pattern.moduleFound.x,pattern.pixel);
return true;
} | java | boolean localize(QrCode.Alignment pattern, float guessY, float guessX)
{
// sample along the middle. Try to not sample the outside edges which could confuse it
for (int i = 0; i < arrayY.length; i++) {
float x = guessX - 1.5f + i*3f/12.0f;
float y = guessY - 1.5f + i*3f/12.0f;
arrayX[i] = reader.read(guessY,x);
arrayY[i] = reader.read(y,guessX);
}
// TODO turn this into an exhaustive search of the array for best up and down point?
int downX = greatestDown(arrayX);
if( downX == -1) return false;
int upX = greatestUp(arrayX,downX);
if( upX == -1) return false;
int downY = greatestDown(arrayY);
if( downY == -1 ) return false;
int upY = greatestUp(arrayY,downY);
if( upY == -1 ) return false;
pattern.moduleFound.x = guessX - 1.5f + (downX+upX)*3f/24.0f;
pattern.moduleFound.y = guessY - 1.5f + (downY+upY)*3f/24.0f;
reader.gridToImage((float)pattern.moduleFound.y,(float)pattern.moduleFound.x,pattern.pixel);
return true;
} | [
"boolean",
"localize",
"(",
"QrCode",
".",
"Alignment",
"pattern",
",",
"float",
"guessY",
",",
"float",
"guessX",
")",
"{",
"// sample along the middle. Try to not sample the outside edges which could confuse it",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"a... | Localizizes the alignment pattern crudely by searching for the black box in the center by looking
for its edges in the gray scale image
@return true if success or false if it doesn't resemble an alignment pattern | [
"Localizizes",
"the",
"alignment",
"pattern",
"crudely",
"by",
"searching",
"for",
"the",
"black",
"box",
"in",
"the",
"center",
"by",
"looking",
"for",
"its",
"edges",
"in",
"the",
"gray",
"scale",
"image"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/QrCodeAlignmentPatternLocator.java#L206-L234 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/descriptor/ConvertDescriptors.java | ConvertDescriptors.positive | public static void positive( TupleDesc_F64 input , TupleDesc_U8 output ) {
double max = 0;
for( int i = 0; i < input.size(); i++ ) {
double v = input.value[i];
if( v > max )
max = v;
}
if( max == 0 )
max = 1.0;
for( int i = 0; i < input.size(); i++ ) {
output.value[i] = (byte)(255.0*input.value[i]/max);
}
} | java | public static void positive( TupleDesc_F64 input , TupleDesc_U8 output ) {
double max = 0;
for( int i = 0; i < input.size(); i++ ) {
double v = input.value[i];
if( v > max )
max = v;
}
if( max == 0 )
max = 1.0;
for( int i = 0; i < input.size(); i++ ) {
output.value[i] = (byte)(255.0*input.value[i]/max);
}
} | [
"public",
"static",
"void",
"positive",
"(",
"TupleDesc_F64",
"input",
",",
"TupleDesc_U8",
"output",
")",
"{",
"double",
"max",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"input",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
... | Converts a floating point description with all positive values into the 8-bit integer descriptor by
dividing each element in the input by the element maximum value and multiplying by 255.
@param input Description with elements that are all positive
@param output Unsigned 8-bit output | [
"Converts",
"a",
"floating",
"point",
"description",
"with",
"all",
"positive",
"values",
"into",
"the",
"8",
"-",
"bit",
"integer",
"descriptor",
"by",
"dividing",
"each",
"element",
"in",
"the",
"input",
"by",
"the",
"element",
"maximum",
"value",
"and",
"... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/descriptor/ConvertDescriptors.java#L39-L53 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/descriptor/ConvertDescriptors.java | ConvertDescriptors.real | public static void real( TupleDesc_F64 input , TupleDesc_S8 output ) {
double max = 0;
for( int i = 0; i < input.size(); i++ ) {
double v = Math.abs(input.value[i]);
if( v > max )
max = v;
}
for( int i = 0; i < input.size(); i++ ) {
output.value[i] = (byte)(127.0*input.value[i]/max);
}
} | java | public static void real( TupleDesc_F64 input , TupleDesc_S8 output ) {
double max = 0;
for( int i = 0; i < input.size(); i++ ) {
double v = Math.abs(input.value[i]);
if( v > max )
max = v;
}
for( int i = 0; i < input.size(); i++ ) {
output.value[i] = (byte)(127.0*input.value[i]/max);
}
} | [
"public",
"static",
"void",
"real",
"(",
"TupleDesc_F64",
"input",
",",
"TupleDesc_S8",
"output",
")",
"{",
"double",
"max",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"input",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",... | Converts a floating point description with real values into the 8-bit integer descriptor by
dividing each element in the input by the element maximum absolute value and multiplying by 127.
@param input Description with elements that are all positive
@param output Unsigned 8-bit output | [
"Converts",
"a",
"floating",
"point",
"description",
"with",
"real",
"values",
"into",
"the",
"8",
"-",
"bit",
"integer",
"descriptor",
"by",
"dividing",
"each",
"element",
"in",
"the",
"input",
"by",
"the",
"element",
"maximum",
"absolute",
"value",
"and",
... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/descriptor/ConvertDescriptors.java#L62-L73 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/descriptor/ConvertDescriptors.java | ConvertDescriptors.convertNcc | public static void convertNcc( TupleDesc_F64 input , NccFeature output ) {
if( input.size() != output.size() )
throw new IllegalArgumentException("Feature lengths do not match.");
double mean = 0;
for (int i = 0; i < input.value.length; i++) {
mean += input.value[i];
}
mean /= input.value.length;
double variance = 0;
for( int i = 0; i < input.value.length; i++ ) {
double d = output.value[i] = input.value[i] - mean;
variance += d*d;
}
variance /= output.size();
output.mean = mean;
output.sigma = Math.sqrt(variance);
} | java | public static void convertNcc( TupleDesc_F64 input , NccFeature output ) {
if( input.size() != output.size() )
throw new IllegalArgumentException("Feature lengths do not match.");
double mean = 0;
for (int i = 0; i < input.value.length; i++) {
mean += input.value[i];
}
mean /= input.value.length;
double variance = 0;
for( int i = 0; i < input.value.length; i++ ) {
double d = output.value[i] = input.value[i] - mean;
variance += d*d;
}
variance /= output.size();
output.mean = mean;
output.sigma = Math.sqrt(variance);
} | [
"public",
"static",
"void",
"convertNcc",
"(",
"TupleDesc_F64",
"input",
",",
"NccFeature",
"output",
")",
"{",
"if",
"(",
"input",
".",
"size",
"(",
")",
"!=",
"output",
".",
"size",
"(",
")",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Featu... | Converts a regular feature description into a NCC feature description
@param input Tuple descriptor. (not modified)
@param output The equivalent NCC feature. (modified) | [
"Converts",
"a",
"regular",
"feature",
"description",
"into",
"a",
"NCC",
"feature",
"description"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/descriptor/ConvertDescriptors.java#L80-L100 | train |
lessthanoptimal/BoofCV | examples/src/main/java/boofcv/examples/imageprocessing/ExampleConvolution.java | ExampleConvolution.convolve1D | private static void convolve1D(GrayU8 gray) {
ImageBorder<GrayU8> border = FactoryImageBorder.wrap(BorderType.EXTENDED, gray);
Kernel1D_S32 kernel = new Kernel1D_S32(2);
kernel.offset = 1; // specify the kernel's origin
kernel.data[0] = 1;
kernel.data[1] = -1;
GrayS16 output = new GrayS16(gray.width,gray.height);
GConvolveImageOps.horizontal(kernel, gray, output, border);
panel.addImage(VisualizeImageData.standard(output, null), "1D Horizontal");
GConvolveImageOps.vertical(kernel, gray, output, border);
panel.addImage(VisualizeImageData.standard(output, null), "1D Vertical");
} | java | private static void convolve1D(GrayU8 gray) {
ImageBorder<GrayU8> border = FactoryImageBorder.wrap(BorderType.EXTENDED, gray);
Kernel1D_S32 kernel = new Kernel1D_S32(2);
kernel.offset = 1; // specify the kernel's origin
kernel.data[0] = 1;
kernel.data[1] = -1;
GrayS16 output = new GrayS16(gray.width,gray.height);
GConvolveImageOps.horizontal(kernel, gray, output, border);
panel.addImage(VisualizeImageData.standard(output, null), "1D Horizontal");
GConvolveImageOps.vertical(kernel, gray, output, border);
panel.addImage(VisualizeImageData.standard(output, null), "1D Vertical");
} | [
"private",
"static",
"void",
"convolve1D",
"(",
"GrayU8",
"gray",
")",
"{",
"ImageBorder",
"<",
"GrayU8",
">",
"border",
"=",
"FactoryImageBorder",
".",
"wrap",
"(",
"BorderType",
".",
"EXTENDED",
",",
"gray",
")",
";",
"Kernel1D_S32",
"kernel",
"=",
"new",
... | Convolves a 1D kernel horizontally and vertically | [
"Convolves",
"a",
"1D",
"kernel",
"horizontally",
"and",
"vertically"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/examples/src/main/java/boofcv/examples/imageprocessing/ExampleConvolution.java#L63-L77 | train |
lessthanoptimal/BoofCV | examples/src/main/java/boofcv/examples/imageprocessing/ExampleConvolution.java | ExampleConvolution.convolve2D | private static void convolve2D(GrayU8 gray) {
// By default 2D kernels will be centered around width/2
Kernel2D_S32 kernel = new Kernel2D_S32(3);
kernel.set(1,0,2);
kernel.set(2,1,2);
kernel.set(0,1,-2);
kernel.set(1,2,-2);
// Output needs to handle the increased domain after convolution. Can't be 8bit
GrayS16 output = new GrayS16(gray.width,gray.height);
ImageBorder<GrayU8> border = FactoryImageBorder.wrap( BorderType.EXTENDED,gray);
GConvolveImageOps.convolve(kernel, gray, output, border);
panel.addImage(VisualizeImageData.standard(output, null), "2D Kernel");
} | java | private static void convolve2D(GrayU8 gray) {
// By default 2D kernels will be centered around width/2
Kernel2D_S32 kernel = new Kernel2D_S32(3);
kernel.set(1,0,2);
kernel.set(2,1,2);
kernel.set(0,1,-2);
kernel.set(1,2,-2);
// Output needs to handle the increased domain after convolution. Can't be 8bit
GrayS16 output = new GrayS16(gray.width,gray.height);
ImageBorder<GrayU8> border = FactoryImageBorder.wrap( BorderType.EXTENDED,gray);
GConvolveImageOps.convolve(kernel, gray, output, border);
panel.addImage(VisualizeImageData.standard(output, null), "2D Kernel");
} | [
"private",
"static",
"void",
"convolve2D",
"(",
"GrayU8",
"gray",
")",
"{",
"// By default 2D kernels will be centered around width/2",
"Kernel2D_S32",
"kernel",
"=",
"new",
"Kernel2D_S32",
"(",
"3",
")",
";",
"kernel",
".",
"set",
"(",
"1",
",",
"0",
",",
"2",
... | Convolves a 2D kernel | [
"Convolves",
"a",
"2D",
"kernel"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/examples/src/main/java/boofcv/examples/imageprocessing/ExampleConvolution.java#L82-L96 | train |
lessthanoptimal/BoofCV | examples/src/main/java/boofcv/examples/imageprocessing/ExampleConvolution.java | ExampleConvolution.normalize2D | private static void normalize2D(GrayU8 gray) {
// Create a Gaussian kernel with radius of 3
Kernel2D_S32 kernel = FactoryKernelGaussian.gaussian2D(GrayU8.class, -1, 3);
// Note that there is a more efficient way to compute this convolution since it is a separable kernel
// just use BlurImageOps instead.
// Since it's normalized it can be saved inside an 8bit image
GrayU8 output = new GrayU8(gray.width,gray.height);
GConvolveImageOps.convolveNormalized(kernel, gray, output);
panel.addImage(VisualizeImageData.standard(output, null), "2D Normalized Kernel");
} | java | private static void normalize2D(GrayU8 gray) {
// Create a Gaussian kernel with radius of 3
Kernel2D_S32 kernel = FactoryKernelGaussian.gaussian2D(GrayU8.class, -1, 3);
// Note that there is a more efficient way to compute this convolution since it is a separable kernel
// just use BlurImageOps instead.
// Since it's normalized it can be saved inside an 8bit image
GrayU8 output = new GrayU8(gray.width,gray.height);
GConvolveImageOps.convolveNormalized(kernel, gray, output);
panel.addImage(VisualizeImageData.standard(output, null), "2D Normalized Kernel");
} | [
"private",
"static",
"void",
"normalize2D",
"(",
"GrayU8",
"gray",
")",
"{",
"// Create a Gaussian kernel with radius of 3",
"Kernel2D_S32",
"kernel",
"=",
"FactoryKernelGaussian",
".",
"gaussian2D",
"(",
"GrayU8",
".",
"class",
",",
"-",
"1",
",",
"3",
")",
";",
... | Convolves a 2D normalized kernel. This kernel is divided by its sum after computation. | [
"Convolves",
"a",
"2D",
"normalized",
"kernel",
".",
"This",
"kernel",
"is",
"divided",
"by",
"its",
"sum",
"after",
"computation",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/examples/src/main/java/boofcv/examples/imageprocessing/ExampleConvolution.java#L101-L112 | train |
lessthanoptimal/BoofCV | main/boofcv-calibration/src/main/java/boofcv/alg/geo/calibration/Zhang99CalibrationMatrixFromHomographies.java | Zhang99CalibrationMatrixFromHomographies.process | public void process( List<DMatrixRMaj> homographies ) {
if( assumeZeroSkew ) {
if( homographies.size() < 2 )
throw new IllegalArgumentException("At least two homographies are required. Found "+homographies.size());
} else if( homographies.size() < 3 ) {
throw new IllegalArgumentException("At least three homographies are required. Found "+homographies.size());
}
if( assumeZeroSkew ) {
setupA_NoSkew(homographies);
if( !solverNull.process(A,1,b) )
throw new RuntimeException("SVD failed");
computeParam_ZeroSkew();
} else {
setupA(homographies);
if( !solverNull.process(A,1,b) )
throw new RuntimeException("SVD failed");
computeParam();
}
if(MatrixFeatures_DDRM.hasUncountable(K)) {
throw new RuntimeException("Failed!");
}
} | java | public void process( List<DMatrixRMaj> homographies ) {
if( assumeZeroSkew ) {
if( homographies.size() < 2 )
throw new IllegalArgumentException("At least two homographies are required. Found "+homographies.size());
} else if( homographies.size() < 3 ) {
throw new IllegalArgumentException("At least three homographies are required. Found "+homographies.size());
}
if( assumeZeroSkew ) {
setupA_NoSkew(homographies);
if( !solverNull.process(A,1,b) )
throw new RuntimeException("SVD failed");
computeParam_ZeroSkew();
} else {
setupA(homographies);
if( !solverNull.process(A,1,b) )
throw new RuntimeException("SVD failed");
computeParam();
}
if(MatrixFeatures_DDRM.hasUncountable(K)) {
throw new RuntimeException("Failed!");
}
} | [
"public",
"void",
"process",
"(",
"List",
"<",
"DMatrixRMaj",
">",
"homographies",
")",
"{",
"if",
"(",
"assumeZeroSkew",
")",
"{",
"if",
"(",
"homographies",
".",
"size",
"(",
")",
"<",
"2",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"At leas... | Given a set of homographies computed from a sequence of images that observe the same
plane it estimates the camera's calibration.
@param homographies Homographies computed from observations of the calibration grid. | [
"Given",
"a",
"set",
"of",
"homographies",
"computed",
"from",
"a",
"sequence",
"of",
"images",
"that",
"observe",
"the",
"same",
"plane",
"it",
"estimates",
"the",
"camera",
"s",
"calibration",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-calibration/src/main/java/boofcv/alg/geo/calibration/Zhang99CalibrationMatrixFromHomographies.java#L93-L115 | train |
lessthanoptimal/BoofCV | main/boofcv-calibration/src/main/java/boofcv/alg/geo/calibration/Zhang99CalibrationMatrixFromHomographies.java | Zhang99CalibrationMatrixFromHomographies.computeV | private void computeV( DMatrixRMaj h1 ,DMatrixRMaj h2 , DMatrixRMaj v )
{
double h1x = h1.get(0,0);
double h1y = h1.get(1,0);
double h1z = h1.get(2,0);
double h2x = h2.get(0,0);
double h2y = h2.get(1,0);
double h2z = h2.get(2,0);
v.set(0,0,h1x*h2x);
v.set(0,1,h1x*h2y+h1y*h2x);
v.set(0,2,h1y*h2y);
v.set(0,3,h1z*h2x+h1x*h2z);
v.set(0,4,h1z*h2y+h1y*h2z);
v.set(0,5,h1z*h2z);
} | java | private void computeV( DMatrixRMaj h1 ,DMatrixRMaj h2 , DMatrixRMaj v )
{
double h1x = h1.get(0,0);
double h1y = h1.get(1,0);
double h1z = h1.get(2,0);
double h2x = h2.get(0,0);
double h2y = h2.get(1,0);
double h2z = h2.get(2,0);
v.set(0,0,h1x*h2x);
v.set(0,1,h1x*h2y+h1y*h2x);
v.set(0,2,h1y*h2y);
v.set(0,3,h1z*h2x+h1x*h2z);
v.set(0,4,h1z*h2y+h1y*h2z);
v.set(0,5,h1z*h2z);
} | [
"private",
"void",
"computeV",
"(",
"DMatrixRMaj",
"h1",
",",
"DMatrixRMaj",
"h2",
",",
"DMatrixRMaj",
"v",
")",
"{",
"double",
"h1x",
"=",
"h1",
".",
"get",
"(",
"0",
",",
"0",
")",
";",
"double",
"h1y",
"=",
"h1",
".",
"get",
"(",
"1",
",",
"0"... | This computes the v_ij vector found in the paper. | [
"This",
"computes",
"the",
"v_ij",
"vector",
"found",
"in",
"the",
"paper",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-calibration/src/main/java/boofcv/alg/geo/calibration/Zhang99CalibrationMatrixFromHomographies.java#L210-L226 | train |
lessthanoptimal/BoofCV | main/boofcv-calibration/src/main/java/boofcv/alg/geo/calibration/Zhang99CalibrationMatrixFromHomographies.java | Zhang99CalibrationMatrixFromHomographies.computeParam | private void computeParam() {
// reduce overflow/underflow
CommonOps_DDRM.divide(b,CommonOps_DDRM.elementMaxAbs(b));
double B11 = b.get(0,0);
double B12 = b.get(1,0);
double B22 = b.get(2,0);
double B13 = b.get(3,0);
double B23 = b.get(4,0);
double B33 = b.get(5,0);
double temp0 = B12*B13 - B11*B23;
double temp1 = B11*B22 - B12*B12;
double v0 = temp0/temp1;
double lambda = B33-(B13*B13 + v0*temp0)/B11;
// Using abs() inside is an adhoc modification to make it more stable
// If there is any good theoretical reason for it, that's a pure accident. Seems
// to work well in practice
double a = Math.sqrt(Math.abs(lambda / B11));
double b = Math.sqrt(Math.abs(lambda * B11 / temp1));
double c = -B12*b/B11;
double u0 = c*v0/a - B13/B11;
K.set(0,0,a);
K.set(0,1,c);
K.set(0,2,u0);
K.set(1,1,b);
K.set(1,2,v0);
K.set(2,2,1);
} | java | private void computeParam() {
// reduce overflow/underflow
CommonOps_DDRM.divide(b,CommonOps_DDRM.elementMaxAbs(b));
double B11 = b.get(0,0);
double B12 = b.get(1,0);
double B22 = b.get(2,0);
double B13 = b.get(3,0);
double B23 = b.get(4,0);
double B33 = b.get(5,0);
double temp0 = B12*B13 - B11*B23;
double temp1 = B11*B22 - B12*B12;
double v0 = temp0/temp1;
double lambda = B33-(B13*B13 + v0*temp0)/B11;
// Using abs() inside is an adhoc modification to make it more stable
// If there is any good theoretical reason for it, that's a pure accident. Seems
// to work well in practice
double a = Math.sqrt(Math.abs(lambda / B11));
double b = Math.sqrt(Math.abs(lambda * B11 / temp1));
double c = -B12*b/B11;
double u0 = c*v0/a - B13/B11;
K.set(0,0,a);
K.set(0,1,c);
K.set(0,2,u0);
K.set(1,1,b);
K.set(1,2,v0);
K.set(2,2,1);
} | [
"private",
"void",
"computeParam",
"(",
")",
"{",
"// reduce overflow/underflow",
"CommonOps_DDRM",
".",
"divide",
"(",
"b",
",",
"CommonOps_DDRM",
".",
"elementMaxAbs",
"(",
"b",
")",
")",
";",
"double",
"B11",
"=",
"b",
".",
"get",
"(",
"0",
",",
"0",
... | Compute the calibration parameters from the b matrix. | [
"Compute",
"the",
"calibration",
"parameters",
"from",
"the",
"b",
"matrix",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-calibration/src/main/java/boofcv/alg/geo/calibration/Zhang99CalibrationMatrixFromHomographies.java#L252-L282 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/intensity/impl/ImplIntegralImageFeatureIntensity.java | ImplIntegralImageFeatureIntensity.hessianNaive | public static void hessianNaive(GrayF32 integral, int skip , int size ,
GrayF32 intensity)
{
final int w = intensity.width;
final int h = intensity.height;
// get convolution kernels for the second order derivatives
IntegralKernel kerXX = DerivativeIntegralImage.kernelDerivXX(size,null);
IntegralKernel kerYY = DerivativeIntegralImage.kernelDerivYY(size,null);
IntegralKernel kerXY = DerivativeIntegralImage.kernelDerivXY(size,null);
float norm = 1.0f/(size*size);
for( int y = 0; y < h; y++ ) {
for( int x = 0; x < w; x++ ) {
int xx = x*skip;
int yy = y*skip;
computeHessian(integral, intensity, kerXX, kerYY, kerXY, norm, y, yy, x, xx);
}
}
} | java | public static void hessianNaive(GrayF32 integral, int skip , int size ,
GrayF32 intensity)
{
final int w = intensity.width;
final int h = intensity.height;
// get convolution kernels for the second order derivatives
IntegralKernel kerXX = DerivativeIntegralImage.kernelDerivXX(size,null);
IntegralKernel kerYY = DerivativeIntegralImage.kernelDerivYY(size,null);
IntegralKernel kerXY = DerivativeIntegralImage.kernelDerivXY(size,null);
float norm = 1.0f/(size*size);
for( int y = 0; y < h; y++ ) {
for( int x = 0; x < w; x++ ) {
int xx = x*skip;
int yy = y*skip;
computeHessian(integral, intensity, kerXX, kerYY, kerXY, norm, y, yy, x, xx);
}
}
} | [
"public",
"static",
"void",
"hessianNaive",
"(",
"GrayF32",
"integral",
",",
"int",
"skip",
",",
"int",
"size",
",",
"GrayF32",
"intensity",
")",
"{",
"final",
"int",
"w",
"=",
"intensity",
".",
"width",
";",
"final",
"int",
"h",
"=",
"intensity",
".",
... | Brute force approach which is easy to validate through visual inspection. | [
"Brute",
"force",
"approach",
"which",
"is",
"easy",
"to",
"validate",
"through",
"visual",
"inspection",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/intensity/impl/ImplIntegralImageFeatureIntensity.java#L45-L67 | train |
lessthanoptimal/BoofCV | demonstrations/src/main/java/boofcv/demonstrations/sfm/multiview/DemoThreeViewStereoApp.java | DemoThreeViewStereoApp.openImageSet | @Override
public void openImageSet(String ...files ) {
synchronized (lockProcessing) {
if( processing ) {
JOptionPane.showMessageDialog(this, "Still processing");
return;
}
}
// disable the menu until it finish processing the images
setMenuBarEnabled(false);
super.openImageSet(files);
} | java | @Override
public void openImageSet(String ...files ) {
synchronized (lockProcessing) {
if( processing ) {
JOptionPane.showMessageDialog(this, "Still processing");
return;
}
}
// disable the menu until it finish processing the images
setMenuBarEnabled(false);
super.openImageSet(files);
} | [
"@",
"Override",
"public",
"void",
"openImageSet",
"(",
"String",
"...",
"files",
")",
"{",
"synchronized",
"(",
"lockProcessing",
")",
"{",
"if",
"(",
"processing",
")",
"{",
"JOptionPane",
".",
"showMessageDialog",
"(",
"this",
",",
"\"Still processing\"",
"... | Prevent the user from tring to process more than one image at once | [
"Prevent",
"the",
"user",
"from",
"tring",
"to",
"process",
"more",
"than",
"one",
"image",
"at",
"once"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/demonstrations/src/main/java/boofcv/demonstrations/sfm/multiview/DemoThreeViewStereoApp.java#L203-L214 | train |
lessthanoptimal/BoofCV | demonstrations/src/main/java/boofcv/demonstrations/sfm/multiview/DemoThreeViewStereoApp.java | DemoThreeViewStereoApp.scaleBuffered | private BufferedImage scaleBuffered( BufferedImage input ) {
int m = Math.max(input.getWidth(),input.getHeight());
if( m <= controls.maxImageSize )
return input;
else {
double scale = controls.maxImageSize/(double)m;
int w = (int)(scale*input.getWidth()+0.5);
int h = (int)(scale*input.getHeight()+0.5);
// Use BoofCV to down sample since Graphics2D introduced too many aliasing artifacts
BufferedImage output = new BufferedImage(w,h,input.getType());
Planar<GrayU8> a = new Planar<>(GrayU8.class,input.getWidth(),input.getHeight(),3);
Planar<GrayU8> b = new Planar<>(GrayU8.class,w,h,3);
ConvertBufferedImage.convertFrom(input,a,true);
AverageDownSampleOps.down(a,b);
ConvertBufferedImage.convertTo(b,output,true);
return output;
}
} | java | private BufferedImage scaleBuffered( BufferedImage input ) {
int m = Math.max(input.getWidth(),input.getHeight());
if( m <= controls.maxImageSize )
return input;
else {
double scale = controls.maxImageSize/(double)m;
int w = (int)(scale*input.getWidth()+0.5);
int h = (int)(scale*input.getHeight()+0.5);
// Use BoofCV to down sample since Graphics2D introduced too many aliasing artifacts
BufferedImage output = new BufferedImage(w,h,input.getType());
Planar<GrayU8> a = new Planar<>(GrayU8.class,input.getWidth(),input.getHeight(),3);
Planar<GrayU8> b = new Planar<>(GrayU8.class,w,h,3);
ConvertBufferedImage.convertFrom(input,a,true);
AverageDownSampleOps.down(a,b);
ConvertBufferedImage.convertTo(b,output,true);
return output;
}
} | [
"private",
"BufferedImage",
"scaleBuffered",
"(",
"BufferedImage",
"input",
")",
"{",
"int",
"m",
"=",
"Math",
".",
"max",
"(",
"input",
".",
"getWidth",
"(",
")",
",",
"input",
".",
"getHeight",
"(",
")",
")",
";",
"if",
"(",
"m",
"<=",
"controls",
... | Scale buffered image so that it meets the image size restrictions | [
"Scale",
"buffered",
"image",
"so",
"that",
"it",
"meets",
"the",
"image",
"size",
"restrictions"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/demonstrations/src/main/java/boofcv/demonstrations/sfm/multiview/DemoThreeViewStereoApp.java#L309-L327 | train |
lessthanoptimal/BoofCV | demonstrations/src/main/java/boofcv/demonstrations/sfm/multiview/DemoThreeViewStereoApp.java | DemoThreeViewStereoApp.selectBestPair | private int[] selectBestPair( SceneStructureMetric structure ) {
Se3_F64 w_to_0 = structure.views[0].worldToView;
Se3_F64 w_to_1 = structure.views[1].worldToView;
Se3_F64 w_to_2 = structure.views[2].worldToView;
Se3_F64 view0_to_1 = w_to_0.invert(null).concat(w_to_1,null);
Se3_F64 view0_to_2 = w_to_0.invert(null).concat(w_to_2,null);
Se3_F64 view1_to_2 = w_to_1.invert(null).concat(w_to_2,null);
Se3_F64 candidates[] = new Se3_F64[]{view0_to_1,view0_to_2,view1_to_2};
int best = -1;
double bestScore = Double.MAX_VALUE;
for (int i = 0; i < candidates.length; i++) {
double s = score(candidates[i]);
System.out.println("stereo score["+i+"] = "+s);
if( s < bestScore ) {
bestScore = s;
best = i;
}
}
switch (best) {
case 0: return new int[]{0,1};
case 1: return new int[]{0,2};
case 2: return new int[]{1,2};
}
throw new RuntimeException("BUG!");
} | java | private int[] selectBestPair( SceneStructureMetric structure ) {
Se3_F64 w_to_0 = structure.views[0].worldToView;
Se3_F64 w_to_1 = structure.views[1].worldToView;
Se3_F64 w_to_2 = structure.views[2].worldToView;
Se3_F64 view0_to_1 = w_to_0.invert(null).concat(w_to_1,null);
Se3_F64 view0_to_2 = w_to_0.invert(null).concat(w_to_2,null);
Se3_F64 view1_to_2 = w_to_1.invert(null).concat(w_to_2,null);
Se3_F64 candidates[] = new Se3_F64[]{view0_to_1,view0_to_2,view1_to_2};
int best = -1;
double bestScore = Double.MAX_VALUE;
for (int i = 0; i < candidates.length; i++) {
double s = score(candidates[i]);
System.out.println("stereo score["+i+"] = "+s);
if( s < bestScore ) {
bestScore = s;
best = i;
}
}
switch (best) {
case 0: return new int[]{0,1};
case 1: return new int[]{0,2};
case 2: return new int[]{1,2};
}
throw new RuntimeException("BUG!");
} | [
"private",
"int",
"[",
"]",
"selectBestPair",
"(",
"SceneStructureMetric",
"structure",
")",
"{",
"Se3_F64",
"w_to_0",
"=",
"structure",
".",
"views",
"[",
"0",
"]",
".",
"worldToView",
";",
"Se3_F64",
"w_to_1",
"=",
"structure",
".",
"views",
"[",
"1",
"]... | Select two views which are the closest to an idea stereo pair. Little rotation and little translation along
z-axis | [
"Select",
"two",
"views",
"which",
"are",
"the",
"closest",
"to",
"an",
"idea",
"stereo",
"pair",
".",
"Little",
"rotation",
"and",
"little",
"translation",
"along",
"z",
"-",
"axis"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/demonstrations/src/main/java/boofcv/demonstrations/sfm/multiview/DemoThreeViewStereoApp.java#L516-L544 | train |
lessthanoptimal/BoofCV | demonstrations/src/main/java/boofcv/demonstrations/sfm/multiview/DemoThreeViewStereoApp.java | DemoThreeViewStereoApp.score | private double score( Se3_F64 se ) {
// Rodrigues_F64 rod = new Rodrigues_F64();
// ConvertRotation3D_F64.matrixToRodrigues(se.R,rod);
double x = Math.abs(se.T.x);
double y = Math.abs(se.T.y);
double z = Math.abs(se.T.z)+1e-8;
double r = Math.max(x/(y+z),y/(x+z));
// System.out.println(se.T+" angle="+rod.theta);
// return (Math.abs(rod.theta)+1e-3)/r;
return 1.0/r; // ignoring rotation seems to work better <shrug>
} | java | private double score( Se3_F64 se ) {
// Rodrigues_F64 rod = new Rodrigues_F64();
// ConvertRotation3D_F64.matrixToRodrigues(se.R,rod);
double x = Math.abs(se.T.x);
double y = Math.abs(se.T.y);
double z = Math.abs(se.T.z)+1e-8;
double r = Math.max(x/(y+z),y/(x+z));
// System.out.println(se.T+" angle="+rod.theta);
// return (Math.abs(rod.theta)+1e-3)/r;
return 1.0/r; // ignoring rotation seems to work better <shrug>
} | [
"private",
"double",
"score",
"(",
"Se3_F64",
"se",
")",
"{",
"//\t\tRodrigues_F64 rod = new Rodrigues_F64();",
"//\t\tConvertRotation3D_F64.matrixToRodrigues(se.R,rod);",
"double",
"x",
"=",
"Math",
".",
"abs",
"(",
"se",
".",
"T",
".",
"x",
")",
";",
"double",
"y"... | Give lower scores to transforms with no rotation and translations along x or y axis. | [
"Give",
"lower",
"scores",
"to",
"transforms",
"with",
"no",
"rotation",
"and",
"translations",
"along",
"x",
"or",
"y",
"axis",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/demonstrations/src/main/java/boofcv/demonstrations/sfm/multiview/DemoThreeViewStereoApp.java#L549-L563 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polygon/RefinePolygonToContour.java | RefinePolygonToContour.process | public void process(List<Point2D_I32> contour , GrowQueue_I32 vertexes , Polygon2D_F64 output ) {
int numDecreasing = 0;
for (int i = vertexes.size-1,j=0; j < vertexes.size; i=j,j++) {
if( vertexes.get(i) > vertexes.get(j ) )
numDecreasing++;
}
boolean decreasing = numDecreasing > 1;
output.vertexes.resize(vertexes.size);
lines.resize(vertexes.size);
// fit lines to each size
for (int i = vertexes.size-1,j=0; j < vertexes.size; i=j,j++) {
int idx0 = vertexes.get(i);
int idx1 = vertexes.get(j);
if( decreasing ) {
int tmp = idx0;idx0 = idx1;idx1=tmp;
}
if( idx0 > idx1 ) {
// handle special case where it wraps around
work.clear();
for (int k = idx0; k < contour.size(); k++) {
work.add( contour.get(k));
}
for (int k = 0; k < idx1; k++) {
work.add( contour.get(k));
}
FitLine_I32.polar(work,0,work.size(),polar);
} else {
FitLine_I32.polar(contour,idx0,idx1-idx0,polar);
}
UtilLine2D_F64.convert(polar,lines.get(i));
}
// find the corners by intersecting the side
for (int i = vertexes.size-1,j=0; j < vertexes.size; i=j,j++) {
LineGeneral2D_F64 lineA = lines.get(i);
LineGeneral2D_F64 lineB = lines.get(j);
Intersection2D_F64.intersection(lineA,lineB,output.get(j));
}
} | java | public void process(List<Point2D_I32> contour , GrowQueue_I32 vertexes , Polygon2D_F64 output ) {
int numDecreasing = 0;
for (int i = vertexes.size-1,j=0; j < vertexes.size; i=j,j++) {
if( vertexes.get(i) > vertexes.get(j ) )
numDecreasing++;
}
boolean decreasing = numDecreasing > 1;
output.vertexes.resize(vertexes.size);
lines.resize(vertexes.size);
// fit lines to each size
for (int i = vertexes.size-1,j=0; j < vertexes.size; i=j,j++) {
int idx0 = vertexes.get(i);
int idx1 = vertexes.get(j);
if( decreasing ) {
int tmp = idx0;idx0 = idx1;idx1=tmp;
}
if( idx0 > idx1 ) {
// handle special case where it wraps around
work.clear();
for (int k = idx0; k < contour.size(); k++) {
work.add( contour.get(k));
}
for (int k = 0; k < idx1; k++) {
work.add( contour.get(k));
}
FitLine_I32.polar(work,0,work.size(),polar);
} else {
FitLine_I32.polar(contour,idx0,idx1-idx0,polar);
}
UtilLine2D_F64.convert(polar,lines.get(i));
}
// find the corners by intersecting the side
for (int i = vertexes.size-1,j=0; j < vertexes.size; i=j,j++) {
LineGeneral2D_F64 lineA = lines.get(i);
LineGeneral2D_F64 lineB = lines.get(j);
Intersection2D_F64.intersection(lineA,lineB,output.get(j));
}
} | [
"public",
"void",
"process",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
",",
"GrowQueue_I32",
"vertexes",
",",
"Polygon2D_F64",
"output",
")",
"{",
"int",
"numDecreasing",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"vertexes",
".",
"size",
"-",
"1... | Refines the estimate using all the points in the contour
@param contour (Input) The shape's contour
@param vertexes (Input) List of indexes that are vertexes in the contour
@param output (Output) Storage for where the found polygon is saved to | [
"Refines",
"the",
"estimate",
"using",
"all",
"the",
"points",
"in",
"the",
"contour"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polygon/RefinePolygonToContour.java#L54-L100 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraPinholeBrown.java | CameraPinholeBrown.isDistorted | public boolean isDistorted() {
if( radial != null && radial.length > 0 ) {
for (int i = 0; i < radial.length; i++) {
if( radial[i] != 0 )
return true;
}
}
return t1 != 0 || t2 != 0;
} | java | public boolean isDistorted() {
if( radial != null && radial.length > 0 ) {
for (int i = 0; i < radial.length; i++) {
if( radial[i] != 0 )
return true;
}
}
return t1 != 0 || t2 != 0;
} | [
"public",
"boolean",
"isDistorted",
"(",
")",
"{",
"if",
"(",
"radial",
"!=",
"null",
"&&",
"radial",
".",
"length",
">",
"0",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"radial",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
... | If true then distortion parameters are specified. | [
"If",
"true",
"then",
"distortion",
"parameters",
"are",
"specified",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraPinholeBrown.java#L110-L118 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquareRegularClustersIntoGrids.java | SquareRegularClustersIntoGrids.process | public void process( List<List<SquareNode>> clusters ) {
valid.reset();
for( int i = 0; i < clusters.size(); i++ ) {
List<SquareNode> graph = clusters.get(i);
if( graph.size() < minimumElements )
continue;
switch( checkNumberOfConnections(graph) ) {
case 1:orderIntoLine(graph); break;
case 2:orderIntoGrid(graph); break;
// default: System.out.println("Failed number of connections. size = "+graph.size());
}
}
} | java | public void process( List<List<SquareNode>> clusters ) {
valid.reset();
for( int i = 0; i < clusters.size(); i++ ) {
List<SquareNode> graph = clusters.get(i);
if( graph.size() < minimumElements )
continue;
switch( checkNumberOfConnections(graph) ) {
case 1:orderIntoLine(graph); break;
case 2:orderIntoGrid(graph); break;
// default: System.out.println("Failed number of connections. size = "+graph.size());
}
}
} | [
"public",
"void",
"process",
"(",
"List",
"<",
"List",
"<",
"SquareNode",
">",
">",
"clusters",
")",
"{",
"valid",
".",
"reset",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"clusters",
".",
"size",
"(",
")",
";",
"i",
"++",
... | Converts the set of provided clusters into ordered grids.
@param clusters List of clustered nodes | [
"Converts",
"the",
"set",
"of",
"provided",
"clusters",
"into",
"ordered",
"grids",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquareRegularClustersIntoGrids.java#L58-L73 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquareRegularClustersIntoGrids.java | SquareRegularClustersIntoGrids.checkNumberOfConnections | int checkNumberOfConnections( List<SquareNode> graph ) {
int histogram[] = new int[5];
for (int i = 0; i < graph.size(); i++) {
histogram[ graph.get(i).getNumberOfConnections() ]++;
}
if( graph.size() == 1 ) {
if( histogram[0] != 1 )
return 0;
return 1;
} else if( histogram[1] == 2 ) {
// line
if( histogram[0] != 0 )
return 0;
if( histogram[2] != graph.size()-2 )
return 0;
if( histogram[3] != 0 )
return 0;
if( histogram[4] != 0 )
return 0;
return 1;
} else {
// grid
if (histogram[0] != 0)
return 0;
if (histogram[1] != 0)
return 0;
if (histogram[2] != 4)
return 0;
return 2;
}
} | java | int checkNumberOfConnections( List<SquareNode> graph ) {
int histogram[] = new int[5];
for (int i = 0; i < graph.size(); i++) {
histogram[ graph.get(i).getNumberOfConnections() ]++;
}
if( graph.size() == 1 ) {
if( histogram[0] != 1 )
return 0;
return 1;
} else if( histogram[1] == 2 ) {
// line
if( histogram[0] != 0 )
return 0;
if( histogram[2] != graph.size()-2 )
return 0;
if( histogram[3] != 0 )
return 0;
if( histogram[4] != 0 )
return 0;
return 1;
} else {
// grid
if (histogram[0] != 0)
return 0;
if (histogram[1] != 0)
return 0;
if (histogram[2] != 4)
return 0;
return 2;
}
} | [
"int",
"checkNumberOfConnections",
"(",
"List",
"<",
"SquareNode",
">",
"graph",
")",
"{",
"int",
"histogram",
"[",
"]",
"=",
"new",
"int",
"[",
"5",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"graph",
".",
"size",
"(",
")",
";",
... | Does a weak check on the number of edges in the graph. Since the structure isn't known it can't make
harder checks
@return 0 = not a grid. 1 = line, 2 = grud | [
"Does",
"a",
"weak",
"check",
"on",
"the",
"number",
"of",
"edges",
"in",
"the",
"graph",
".",
"Since",
"the",
"structure",
"isn",
"t",
"known",
"it",
"can",
"t",
"make",
"harder",
"checks"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquareRegularClustersIntoGrids.java#L81-L115 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquareRegularClustersIntoGrids.java | SquareRegularClustersIntoGrids.addRowsToGrid | boolean addRowsToGrid(List<SquareNode> column, List<SquareNode> ordered) {
for (int i = 0; i < column.size(); i++) {
column.get(i).graph = 0;
}
// now add the rows by traversing down the column
int numFirsRow = 0;
for (int j = 0; j < column.size(); j++) {
SquareNode n = column.get(j);
n.graph = SEARCHED;
ordered.add(n);
SquareNode nextRow;
if( j == 0 ) {
if( n.getNumberOfConnections() != 2 ) {
if( verbose ) System.err.println(
"Unexpected number of connections. want 2 found "+n.getNumberOfConnections());
return true;
}
nextRow = pickNot(n, column.get(j + 1));
} else if( j == column.size()-1 ) {
if( n.getNumberOfConnections() != 2 ) {
if (verbose) System.err.println(
"Unexpected number of connections. want 2 found " + n.getNumberOfConnections());
return true;
}
nextRow = pickNot(n,column.get(j-1));
} else {
if( n.getNumberOfConnections() != 3 ) {
if (verbose) System.err.println(
"Unexpected number of connections. want 2 found " + n.getNumberOfConnections());
return true;
}
nextRow = pickNot(n, column.get(j-1),column.get(j+1));
}
nextRow.graph = SEARCHED;
ordered.add(nextRow);
int numberLine = addLineToGrid(n, nextRow, ordered);
if( j == 0 ) {
numFirsRow = numberLine;
} else if(numberLine != numFirsRow ) {
if( verbose ) System.err.println("Number of elements in rows do not match.");
return true;
}
}
return false;
} | java | boolean addRowsToGrid(List<SquareNode> column, List<SquareNode> ordered) {
for (int i = 0; i < column.size(); i++) {
column.get(i).graph = 0;
}
// now add the rows by traversing down the column
int numFirsRow = 0;
for (int j = 0; j < column.size(); j++) {
SquareNode n = column.get(j);
n.graph = SEARCHED;
ordered.add(n);
SquareNode nextRow;
if( j == 0 ) {
if( n.getNumberOfConnections() != 2 ) {
if( verbose ) System.err.println(
"Unexpected number of connections. want 2 found "+n.getNumberOfConnections());
return true;
}
nextRow = pickNot(n, column.get(j + 1));
} else if( j == column.size()-1 ) {
if( n.getNumberOfConnections() != 2 ) {
if (verbose) System.err.println(
"Unexpected number of connections. want 2 found " + n.getNumberOfConnections());
return true;
}
nextRow = pickNot(n,column.get(j-1));
} else {
if( n.getNumberOfConnections() != 3 ) {
if (verbose) System.err.println(
"Unexpected number of connections. want 2 found " + n.getNumberOfConnections());
return true;
}
nextRow = pickNot(n, column.get(j-1),column.get(j+1));
}
nextRow.graph = SEARCHED;
ordered.add(nextRow);
int numberLine = addLineToGrid(n, nextRow, ordered);
if( j == 0 ) {
numFirsRow = numberLine;
} else if(numberLine != numFirsRow ) {
if( verbose ) System.err.println("Number of elements in rows do not match.");
return true;
}
}
return false;
} | [
"boolean",
"addRowsToGrid",
"(",
"List",
"<",
"SquareNode",
">",
"column",
",",
"List",
"<",
"SquareNode",
">",
"ordered",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"column",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"colu... | Competes the graph by traversing down the first column and adding the rows one at a time | [
"Competes",
"the",
"graph",
"by",
"traversing",
"down",
"the",
"first",
"column",
"and",
"adding",
"the",
"rows",
"one",
"at",
"a",
"time"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquareRegularClustersIntoGrids.java#L220-L271 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquareRegularClustersIntoGrids.java | SquareRegularClustersIntoGrids.addLineToGrid | int addLineToGrid(SquareNode a, SquareNode b, List<SquareNode> list) {
int total = 2;
// double maxAngle = UtilAngle.radian(45);
while( true ) {
// double slopeX0 = b.center.x - a.center.x;
// double slopeY0 = b.center.y - a.center.y;
// double angleAB = Math.atan2(slopeY0,slopeX0);
// see which side the edge belongs to on b
boolean matched = false;
int side;
for( side = 0; side < 4; side++ ) {
if( b.edges[side] != null && b.edges[side].destination(b) == a ) {
matched = true;
break;
}
}
if(!matched) {
throw new RuntimeException("BUG!");
}
// must be on the adjacent side
side = (side+2)%4;
if( b.edges[side] == null )
break;
SquareNode c = b.edges[side].destination(b);
if (c.graph == SEARCHED )
break;
// double slopeX1 = c.center.x - b.center.x;
// double slopeY1 = c.center.y - b.center.y;
//
// double angleBC = Math.atan2(slopeY1,slopeX1);
// double acute = Math.abs(UtilAngle.minus(angleAB,angleBC));
// if( acute >= maxAngle )
// break;
total++;
c.graph = SEARCHED;
list.add(c);
a = b;
b = c;
}
return total;
} | java | int addLineToGrid(SquareNode a, SquareNode b, List<SquareNode> list) {
int total = 2;
// double maxAngle = UtilAngle.radian(45);
while( true ) {
// double slopeX0 = b.center.x - a.center.x;
// double slopeY0 = b.center.y - a.center.y;
// double angleAB = Math.atan2(slopeY0,slopeX0);
// see which side the edge belongs to on b
boolean matched = false;
int side;
for( side = 0; side < 4; side++ ) {
if( b.edges[side] != null && b.edges[side].destination(b) == a ) {
matched = true;
break;
}
}
if(!matched) {
throw new RuntimeException("BUG!");
}
// must be on the adjacent side
side = (side+2)%4;
if( b.edges[side] == null )
break;
SquareNode c = b.edges[side].destination(b);
if (c.graph == SEARCHED )
break;
// double slopeX1 = c.center.x - b.center.x;
// double slopeY1 = c.center.y - b.center.y;
//
// double angleBC = Math.atan2(slopeY1,slopeX1);
// double acute = Math.abs(UtilAngle.minus(angleAB,angleBC));
// if( acute >= maxAngle )
// break;
total++;
c.graph = SEARCHED;
list.add(c);
a = b;
b = c;
}
return total;
} | [
"int",
"addLineToGrid",
"(",
"SquareNode",
"a",
",",
"SquareNode",
"b",
",",
"List",
"<",
"SquareNode",
">",
"list",
")",
"{",
"int",
"total",
"=",
"2",
";",
"//\t\tdouble maxAngle = UtilAngle.radian(45);",
"while",
"(",
"true",
")",
"{",
"//\t\t\tdouble slopeX0... | Add all the nodes into the list which lie along the line defined by a and b. a is assumed to be
an end point. Care is taken to not cycle. | [
"Add",
"all",
"the",
"nodes",
"into",
"the",
"list",
"which",
"lie",
"along",
"the",
"line",
"defined",
"by",
"a",
"and",
"b",
".",
"a",
"is",
"assumed",
"to",
"be",
"an",
"end",
"point",
".",
"Care",
"is",
"taken",
"to",
"not",
"cycle",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquareRegularClustersIntoGrids.java#L277-L329 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquareRegularClustersIntoGrids.java | SquareRegularClustersIntoGrids.pickNot | static SquareNode pickNot( SquareNode target , SquareNode child ) {
for (int i = 0; i < 4; i++) {
SquareEdge e = target.edges[i];
if( e == null )
continue;
SquareNode c = e.destination(target);
if( c != child )
return c;
}
throw new RuntimeException("There was no odd one out some how");
} | java | static SquareNode pickNot( SquareNode target , SquareNode child ) {
for (int i = 0; i < 4; i++) {
SquareEdge e = target.edges[i];
if( e == null )
continue;
SquareNode c = e.destination(target);
if( c != child )
return c;
}
throw new RuntimeException("There was no odd one out some how");
} | [
"static",
"SquareNode",
"pickNot",
"(",
"SquareNode",
"target",
",",
"SquareNode",
"child",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
")",
"{",
"SquareEdge",
"e",
"=",
"target",
".",
"edges",
"[",
"i",
"]",
"... | There are only two edges on target. Pick the edge which does not go to the provided child | [
"There",
"are",
"only",
"two",
"edges",
"on",
"target",
".",
"Pick",
"the",
"edge",
"which",
"does",
"not",
"go",
"to",
"the",
"provided",
"child"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquareRegularClustersIntoGrids.java#L334-L344 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquareRegularClustersIntoGrids.java | SquareRegularClustersIntoGrids.pickNot | static SquareNode pickNot( SquareNode target , SquareNode child0 , SquareNode child1 ) {
for (int i = 0; i < 4; i++) {
SquareEdge e = target.edges[i];
if( e == null ) continue;
SquareNode c = e.destination(target);
if( c != child0 && c != child1 )
return c;
}
throw new RuntimeException("There was no odd one out some how");
} | java | static SquareNode pickNot( SquareNode target , SquareNode child0 , SquareNode child1 ) {
for (int i = 0; i < 4; i++) {
SquareEdge e = target.edges[i];
if( e == null ) continue;
SquareNode c = e.destination(target);
if( c != child0 && c != child1 )
return c;
}
throw new RuntimeException("There was no odd one out some how");
} | [
"static",
"SquareNode",
"pickNot",
"(",
"SquareNode",
"target",
",",
"SquareNode",
"child0",
",",
"SquareNode",
"child1",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
")",
"{",
"SquareEdge",
"e",
"=",
"target",
".",... | There are only three edges on target and two of them are known. Pick the one which isn't an inptu child | [
"There",
"are",
"only",
"three",
"edges",
"on",
"target",
"and",
"two",
"of",
"them",
"are",
"known",
".",
"Pick",
"the",
"one",
"which",
"isn",
"t",
"an",
"inptu",
"child"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquareRegularClustersIntoGrids.java#L349-L358 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ImageSegmentationOps.java | ImageSegmentationOps.countRegionPixels | public static int countRegionPixels(GrayS32 labeled , int which ) {
int total = 0;
for( int y = 0; y < labeled.height; y++ ) {
int index = labeled.startIndex + y*labeled.stride;
for( int x = 0; x < labeled.width; x++ ) {
if( labeled.data[index++] == which ) {
total++;
}
}
}
return total;
} | java | public static int countRegionPixels(GrayS32 labeled , int which ) {
int total = 0;
for( int y = 0; y < labeled.height; y++ ) {
int index = labeled.startIndex + y*labeled.stride;
for( int x = 0; x < labeled.width; x++ ) {
if( labeled.data[index++] == which ) {
total++;
}
}
}
return total;
} | [
"public",
"static",
"int",
"countRegionPixels",
"(",
"GrayS32",
"labeled",
",",
"int",
"which",
")",
"{",
"int",
"total",
"=",
"0",
";",
"for",
"(",
"int",
"y",
"=",
"0",
";",
"y",
"<",
"labeled",
".",
"height",
";",
"y",
"++",
")",
"{",
"int",
"... | Counts the number of instances of 'which' inside the labeled image.
@param labeled Image which has been labeled
@param which The label being searched for
@return Number of instances of 'which' in 'labeled' | [
"Counts",
"the",
"number",
"of",
"instances",
"of",
"which",
"inside",
"the",
"labeled",
"image",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ImageSegmentationOps.java#L44-L55 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ImageSegmentationOps.java | ImageSegmentationOps.countRegionPixels | public static void countRegionPixels(GrayS32 labeled , int totalRegions , int counts[] ) {
Arrays.fill(counts,0,totalRegions,0);
for( int y = 0; y < labeled.height; y++ ) {
int index = labeled.startIndex + y*labeled.stride;
for( int x = 0; x < labeled.width; x++ ) {
counts[labeled.data[index++]]++;
}
}
} | java | public static void countRegionPixels(GrayS32 labeled , int totalRegions , int counts[] ) {
Arrays.fill(counts,0,totalRegions,0);
for( int y = 0; y < labeled.height; y++ ) {
int index = labeled.startIndex + y*labeled.stride;
for( int x = 0; x < labeled.width; x++ ) {
counts[labeled.data[index++]]++;
}
}
} | [
"public",
"static",
"void",
"countRegionPixels",
"(",
"GrayS32",
"labeled",
",",
"int",
"totalRegions",
",",
"int",
"counts",
"[",
"]",
")",
"{",
"Arrays",
".",
"fill",
"(",
"counts",
",",
"0",
",",
"totalRegions",
",",
"0",
")",
";",
"for",
"(",
"int"... | Counts the number of pixels in all regions. Regions must be have labels from 0 to totalRegions-1.
@param labeled (Input) labeled image
@param totalRegions Total number of regions
@param counts Storage for pixel counts | [
"Counts",
"the",
"number",
"of",
"pixels",
"in",
"all",
"regions",
".",
"Regions",
"must",
"be",
"have",
"labels",
"from",
"0",
"to",
"totalRegions",
"-",
"1",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ImageSegmentationOps.java#L64-L74 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ImageSegmentationOps.java | ImageSegmentationOps.regionPixelId_to_Compact | public static void regionPixelId_to_Compact(GrayS32 graph, GrowQueue_I32 segmentId, GrayS32 output) {
InputSanityCheck.checkSameShape(graph,output);
// Change the label of root nodes to be the new compacted labels
for( int i = 0; i < segmentId.size; i++ ) {
graph.data[segmentId.data[i]] = i;
}
// In the second pass assign all the children to the new compacted labels
for( int y = 0; y < output.height; y++ ) {
int indexGraph = graph.startIndex + y*graph.stride;
int indexOut = output.startIndex + y*output.stride;
for( int x = 0; x < output.width; x++ , indexGraph++,indexOut++) {
output.data[indexOut] = graph.data[graph.data[indexGraph]];
}
}
// need to do some clean up since the above approach doesn't work for the roots
for( int i = 0; i < segmentId.size; i++ ) {
int indexGraph = segmentId.data[i] - graph.startIndex;
int x = indexGraph%graph.stride;
int y = indexGraph/graph.stride;
output.data[output.startIndex + y*output.stride + x] = i;
}
} | java | public static void regionPixelId_to_Compact(GrayS32 graph, GrowQueue_I32 segmentId, GrayS32 output) {
InputSanityCheck.checkSameShape(graph,output);
// Change the label of root nodes to be the new compacted labels
for( int i = 0; i < segmentId.size; i++ ) {
graph.data[segmentId.data[i]] = i;
}
// In the second pass assign all the children to the new compacted labels
for( int y = 0; y < output.height; y++ ) {
int indexGraph = graph.startIndex + y*graph.stride;
int indexOut = output.startIndex + y*output.stride;
for( int x = 0; x < output.width; x++ , indexGraph++,indexOut++) {
output.data[indexOut] = graph.data[graph.data[indexGraph]];
}
}
// need to do some clean up since the above approach doesn't work for the roots
for( int i = 0; i < segmentId.size; i++ ) {
int indexGraph = segmentId.data[i] - graph.startIndex;
int x = indexGraph%graph.stride;
int y = indexGraph/graph.stride;
output.data[output.startIndex + y*output.stride + x] = i;
}
} | [
"public",
"static",
"void",
"regionPixelId_to_Compact",
"(",
"GrayS32",
"graph",
",",
"GrowQueue_I32",
"segmentId",
",",
"GrayS32",
"output",
")",
"{",
"InputSanityCheck",
".",
"checkSameShape",
"(",
"graph",
",",
"output",
")",
";",
"// Change the label of root nodes... | Compacts the region labels such that they are consecutive numbers starting from 0.
The ID of a root node must the index of a pixel in the 'graph' image, taking in account the change
in coordinates for sub-images.
@param graph Input segmented image where the ID's are not compacted
@param segmentId List of segment ID's. See comment above about what ID's are acceptable.
@param output The new image after it has been compacted | [
"Compacts",
"the",
"region",
"labels",
"such",
"that",
"they",
"are",
"consecutive",
"numbers",
"starting",
"from",
"0",
".",
"The",
"ID",
"of",
"a",
"root",
"node",
"must",
"the",
"index",
"of",
"a",
"pixel",
"in",
"the",
"graph",
"image",
"taking",
"in... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ImageSegmentationOps.java#L85-L111 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/factory/feature/orientation/FactoryOrientationAlgs.java | FactoryOrientationAlgs.image_ii | public static <II extends ImageGray<II>>
OrientationIntegral<II> image_ii( double objectRadiusToScale,
int sampleRadius , double samplePeriod , int sampleWidth,
double weightSigma , Class<II> integralImage)
{
return (OrientationIntegral<II>)
new ImplOrientationImageAverageIntegral(objectRadiusToScale,
sampleRadius,samplePeriod,sampleWidth,weightSigma,integralImage);
} | java | public static <II extends ImageGray<II>>
OrientationIntegral<II> image_ii( double objectRadiusToScale,
int sampleRadius , double samplePeriod , int sampleWidth,
double weightSigma , Class<II> integralImage)
{
return (OrientationIntegral<II>)
new ImplOrientationImageAverageIntegral(objectRadiusToScale,
sampleRadius,samplePeriod,sampleWidth,weightSigma,integralImage);
} | [
"public",
"static",
"<",
"II",
"extends",
"ImageGray",
"<",
"II",
">",
">",
"OrientationIntegral",
"<",
"II",
">",
"image_ii",
"(",
"double",
"objectRadiusToScale",
",",
"int",
"sampleRadius",
",",
"double",
"samplePeriod",
",",
"int",
"sampleWidth",
",",
"dou... | Estimates the orientation without calculating the image derivative.
@see ImplOrientationImageAverageIntegral
@param sampleRadius Radius of the region being considered in terms of samples. Typically 6.
@param samplePeriod How often the image is sampled. This number is scaled. Typically 1.
@param sampleWidth How wide of a kernel should be used to sample. Try 4
@param weightSigma Sigma for weighting. zero for unweighted.
@param integralImage Type of image being processed.
@return OrientationIntegral | [
"Estimates",
"the",
"orientation",
"without",
"calculating",
"the",
"image",
"derivative",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/factory/feature/orientation/FactoryOrientationAlgs.java#L148-L156 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/factory/feature/orientation/FactoryOrientationAlgs.java | FactoryOrientationAlgs.sliding_ii | public static <II extends ImageGray<II>>
OrientationIntegral<II> sliding_ii( ConfigSlidingIntegral config , Class<II> integralType)
{
if( config == null )
config = new ConfigSlidingIntegral();
config.checkValidity();
return (OrientationIntegral<II>)
new ImplOrientationSlidingWindowIntegral(config.objectRadiusToScale,config.samplePeriod,
config.windowSize,config.radius,config.weightSigma, config.sampleWidth,integralType);
} | java | public static <II extends ImageGray<II>>
OrientationIntegral<II> sliding_ii( ConfigSlidingIntegral config , Class<II> integralType)
{
if( config == null )
config = new ConfigSlidingIntegral();
config.checkValidity();
return (OrientationIntegral<II>)
new ImplOrientationSlidingWindowIntegral(config.objectRadiusToScale,config.samplePeriod,
config.windowSize,config.radius,config.weightSigma, config.sampleWidth,integralType);
} | [
"public",
"static",
"<",
"II",
"extends",
"ImageGray",
"<",
"II",
">",
">",
"OrientationIntegral",
"<",
"II",
">",
"sliding_ii",
"(",
"ConfigSlidingIntegral",
"config",
",",
"Class",
"<",
"II",
">",
"integralType",
")",
"{",
"if",
"(",
"config",
"==",
"nul... | Estimates the orientation of a region by using a sliding window across the different potential
angles.
@see OrientationSlidingWindow
@param config Configuration for algorithm. If null defaults will be used.
@param integralType Type of integral image being processed.
@return OrientationIntegral | [
"Estimates",
"the",
"orientation",
"of",
"a",
"region",
"by",
"using",
"a",
"sliding",
"window",
"across",
"the",
"different",
"potential",
"angles",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/factory/feature/orientation/FactoryOrientationAlgs.java#L168-L178 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/factory/feature/orientation/FactoryOrientationAlgs.java | FactoryOrientationAlgs.sift | public static <D extends ImageGray<D>>
OrientationHistogramSift<D> sift(ConfigSiftOrientation config , Class<D> derivType ) {
if( config == null )
config = new ConfigSiftOrientation();
config.checkValidity();
return new OrientationHistogramSift(config.histogramSize,config.sigmaEnlarge,derivType);
} | java | public static <D extends ImageGray<D>>
OrientationHistogramSift<D> sift(ConfigSiftOrientation config , Class<D> derivType ) {
if( config == null )
config = new ConfigSiftOrientation();
config.checkValidity();
return new OrientationHistogramSift(config.histogramSize,config.sigmaEnlarge,derivType);
} | [
"public",
"static",
"<",
"D",
"extends",
"ImageGray",
"<",
"D",
">",
">",
"OrientationHistogramSift",
"<",
"D",
">",
"sift",
"(",
"ConfigSiftOrientation",
"config",
",",
"Class",
"<",
"D",
">",
"derivType",
")",
"{",
"if",
"(",
"config",
"==",
"null",
")... | Estimates multiple orientations as specified in SIFT paper.
@param config Configuration for algorithm. If null defaults will be used.
@param derivType Type of derivative image it takes as input
@return OrientationHistogramSift | [
"Estimates",
"multiple",
"orientations",
"as",
"specified",
"in",
"SIFT",
"paper",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/factory/feature/orientation/FactoryOrientationAlgs.java#L187-L194 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/template/TemplateMatching.java | TemplateMatching.setTemplate | public void setTemplate(T template, T mask , int maxMatches) {
this.template = template;
this.mask = mask;
this.maxMatches = maxMatches;
} | java | public void setTemplate(T template, T mask , int maxMatches) {
this.template = template;
this.mask = mask;
this.maxMatches = maxMatches;
} | [
"public",
"void",
"setTemplate",
"(",
"T",
"template",
",",
"T",
"mask",
",",
"int",
"maxMatches",
")",
"{",
"this",
".",
"template",
"=",
"template",
";",
"this",
".",
"mask",
"=",
"mask",
";",
"this",
".",
"maxMatches",
"=",
"maxMatches",
";",
"}"
] | Specifies the template to search for and the maximum number of matches to return.
@param template Template being searched for
@param mask Optional mask. Same size as template. 0 = pixel is transparent, values larger than zero
determine how influential the pixel is. Can be null.
@param maxMatches The maximum number of matches it will return | [
"Specifies",
"the",
"template",
"to",
"search",
"for",
"and",
"the",
"maximum",
"number",
"of",
"matches",
"to",
"return",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/template/TemplateMatching.java#L92-L96 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/template/TemplateMatching.java | TemplateMatching.setImage | public void setImage(T image ) {
match.setInputImage(image);
this.imageWidth = image.width;
this.imageHeight = image.height;
} | java | public void setImage(T image ) {
match.setInputImage(image);
this.imageWidth = image.width;
this.imageHeight = image.height;
} | [
"public",
"void",
"setImage",
"(",
"T",
"image",
")",
"{",
"match",
".",
"setInputImage",
"(",
"image",
")",
";",
"this",
".",
"imageWidth",
"=",
"image",
".",
"width",
";",
"this",
".",
"imageHeight",
"=",
"image",
".",
"height",
";",
"}"
] | Specifies the input image which the template is to be found inside.
@param image Image being processed | [
"Specifies",
"the",
"input",
"image",
"which",
"the",
"template",
"is",
"to",
"be",
"found",
"inside",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/template/TemplateMatching.java#L103-L107 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/template/TemplateMatching.java | TemplateMatching.process | public void process() {
// compute match intensities
if( mask == null )
match.process(template);
else
match.process(template,mask);
GrayF32 intensity = match.getIntensity();
int offsetX = 0;
int offsetY = 0;
// adjust intensity image size depending on if there is a border or not
if (!match.isBorderProcessed()) {
int x0 = match.getBorderX0();
int x1 = imageWidth - (template.width - x0);
int y0 = match.getBorderY0();
int y1 = imageHeight - (template.height - y0);
intensity = intensity.subimage(x0, y0, x1, y1, null);
} else {
offsetX = match.getBorderX0();
offsetY = match.getBorderY0();
}
// find local peaks in intensity image
candidates.reset();
extractor.process(intensity, null,null,null, candidates);
// select the best matches
if (scores.length < candidates.size) {
scores = new float[candidates.size];
indexes = new int[candidates.size];
}
for (int i = 0; i < candidates.size; i++) {
Point2D_I16 p = candidates.get(i);
scores[i] = -intensity.get(p.x, p.y);
}
int N = Math.min(maxMatches, candidates.size);
QuickSelect.selectIndex(scores, N, candidates.size, indexes);
// save the results
results.reset();
for (int i = 0; i < N; i++) {
Point2D_I16 p = candidates.get(indexes[i]);
Match m = results.grow();
m.score = -scores[indexes[i]];
m.set(p.x - offsetX, p.y - offsetY);
}
} | java | public void process() {
// compute match intensities
if( mask == null )
match.process(template);
else
match.process(template,mask);
GrayF32 intensity = match.getIntensity();
int offsetX = 0;
int offsetY = 0;
// adjust intensity image size depending on if there is a border or not
if (!match.isBorderProcessed()) {
int x0 = match.getBorderX0();
int x1 = imageWidth - (template.width - x0);
int y0 = match.getBorderY0();
int y1 = imageHeight - (template.height - y0);
intensity = intensity.subimage(x0, y0, x1, y1, null);
} else {
offsetX = match.getBorderX0();
offsetY = match.getBorderY0();
}
// find local peaks in intensity image
candidates.reset();
extractor.process(intensity, null,null,null, candidates);
// select the best matches
if (scores.length < candidates.size) {
scores = new float[candidates.size];
indexes = new int[candidates.size];
}
for (int i = 0; i < candidates.size; i++) {
Point2D_I16 p = candidates.get(i);
scores[i] = -intensity.get(p.x, p.y);
}
int N = Math.min(maxMatches, candidates.size);
QuickSelect.selectIndex(scores, N, candidates.size, indexes);
// save the results
results.reset();
for (int i = 0; i < N; i++) {
Point2D_I16 p = candidates.get(indexes[i]);
Match m = results.grow();
m.score = -scores[indexes[i]];
m.set(p.x - offsetX, p.y - offsetY);
}
} | [
"public",
"void",
"process",
"(",
")",
"{",
"// compute match intensities",
"if",
"(",
"mask",
"==",
"null",
")",
"match",
".",
"process",
"(",
"template",
")",
";",
"else",
"match",
".",
"process",
"(",
"template",
",",
"mask",
")",
";",
"GrayF32",
"int... | Performs template matching. | [
"Performs",
"template",
"matching",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/template/TemplateMatching.java#L112-L165 | train |
lessthanoptimal/BoofCV | integration/boofcv-swing/src/main/java/boofcv/gui/SelectAlgorithmPanel.java | SelectAlgorithmPanel.refreshAlgorithm | public void refreshAlgorithm() {
Object cookie = algCookies.get(algBox.getSelectedIndex());
String name = (String)algBox.getSelectedItem();
performSetAlgorithm(name, cookie);
} | java | public void refreshAlgorithm() {
Object cookie = algCookies.get(algBox.getSelectedIndex());
String name = (String)algBox.getSelectedItem();
performSetAlgorithm(name, cookie);
} | [
"public",
"void",
"refreshAlgorithm",
"(",
")",
"{",
"Object",
"cookie",
"=",
"algCookies",
".",
"get",
"(",
"algBox",
".",
"getSelectedIndex",
"(",
")",
")",
";",
"String",
"name",
"=",
"(",
"String",
")",
"algBox",
".",
"getSelectedItem",
"(",
")",
";"... | Tells it to switch again to the current algorithm. Useful if the input has changed and information
needs to be rendered again. | [
"Tells",
"it",
"to",
"switch",
"again",
"to",
"the",
"current",
"algorithm",
".",
"Useful",
"if",
"the",
"input",
"has",
"changed",
"and",
"information",
"needs",
"to",
"be",
"rendered",
"again",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/integration/boofcv-swing/src/main/java/boofcv/gui/SelectAlgorithmPanel.java#L83-L87 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.process | public boolean process(List<Point2D_I32> contour ) {
// Reset internal book keeping variables
reset();
if( loops ) {
// Reject pathological case
if (contour.size() < 3)
return false;
if (!findInitialTriangle(contour))
return false;
} else {
// Reject pathological case
if( contour.size() < 2 )
return false;
// two end points are the seeds. Plus they can't change
addCorner(0);
addCorner(contour.size()-1);
initializeScore(contour,false);
}
savePolyline();
sequentialSideFit(contour,loops);
if( fatalError )
return false;
int MIN_SIZE = loops ? 3 : 2;
double bestScore = Double.MAX_VALUE;
int bestSize = -1;
for (int i = 0; i < Math.min(maxSides-(MIN_SIZE-1),polylines.size); i++) {
if( polylines.get(i).score < bestScore ) {
bestPolyline = polylines.get(i);
bestScore = bestPolyline.score;
bestSize = i + MIN_SIZE;
}
}
// There was no good match within the min/max size requirement
if( bestSize < minSides) {
return false;
}
// make sure all the sides are within error tolerance
for (int i = 0,j=bestSize-1; i < bestSize; j=i,i++) {
Point2D_I32 a = contour.get(bestPolyline.splits.get(i));
Point2D_I32 b = contour.get(bestPolyline.splits.get(j));
double length = a.distance(b);
double thresholdSideError = this.maxSideError.compute(length);
if( bestPolyline.sideErrors.get(i) >= thresholdSideError*thresholdSideError) {
bestPolyline = null;
return false;
}
}
return true;
} | java | public boolean process(List<Point2D_I32> contour ) {
// Reset internal book keeping variables
reset();
if( loops ) {
// Reject pathological case
if (contour.size() < 3)
return false;
if (!findInitialTriangle(contour))
return false;
} else {
// Reject pathological case
if( contour.size() < 2 )
return false;
// two end points are the seeds. Plus they can't change
addCorner(0);
addCorner(contour.size()-1);
initializeScore(contour,false);
}
savePolyline();
sequentialSideFit(contour,loops);
if( fatalError )
return false;
int MIN_SIZE = loops ? 3 : 2;
double bestScore = Double.MAX_VALUE;
int bestSize = -1;
for (int i = 0; i < Math.min(maxSides-(MIN_SIZE-1),polylines.size); i++) {
if( polylines.get(i).score < bestScore ) {
bestPolyline = polylines.get(i);
bestScore = bestPolyline.score;
bestSize = i + MIN_SIZE;
}
}
// There was no good match within the min/max size requirement
if( bestSize < minSides) {
return false;
}
// make sure all the sides are within error tolerance
for (int i = 0,j=bestSize-1; i < bestSize; j=i,i++) {
Point2D_I32 a = contour.get(bestPolyline.splits.get(i));
Point2D_I32 b = contour.get(bestPolyline.splits.get(j));
double length = a.distance(b);
double thresholdSideError = this.maxSideError.compute(length);
if( bestPolyline.sideErrors.get(i) >= thresholdSideError*thresholdSideError) {
bestPolyline = null;
return false;
}
}
return true;
} | [
"public",
"boolean",
"process",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
")",
"{",
"// Reset internal book keeping variables",
"reset",
"(",
")",
";",
"if",
"(",
"loops",
")",
"{",
"// Reject pathological case",
"if",
"(",
"contour",
".",
"size",
"(",
... | Process the contour and returns true if a polyline could be found.
@param contour Contour. Must be a ordered in CW or CCW
@return true for success or false if one could not be fit | [
"Process",
"the",
"contour",
"and",
"returns",
"true",
"if",
"a",
"polyline",
"could",
"be",
"found",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L130-L189 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.savePolyline | boolean savePolyline() {
int N = loops ? 3 : 2;
// if a polyline of this size has already been saved then over write it
CandidatePolyline c;
if( list.size() <= polylines.size+N-1 ) {
c = polylines.get( list.size()-N );
// sanity check
if( c.splits.size != list.size() )
throw new RuntimeException("Egads saved polylines aren't in the expected order");
} else {
c = polylines.grow();
c.reset();
c.score = Double.MAX_VALUE;
}
double foundScore = computeScore(list,cornerScorePenalty, loops);
// only save the results if it's an improvement
if( c.score > foundScore ) {
c.score = foundScore;
c.splits.reset();
c.sideErrors.reset();
Element<Corner> e = list.getHead();
double maxSideError = 0;
while (e != null) {
maxSideError = Math.max(maxSideError,e.object.sideError);
c.splits.add(e.object.index);
c.sideErrors.add(e.object.sideError);
e = e.next;
}
c.maxSideError = maxSideError;
return true;
} else {
return false;
}
} | java | boolean savePolyline() {
int N = loops ? 3 : 2;
// if a polyline of this size has already been saved then over write it
CandidatePolyline c;
if( list.size() <= polylines.size+N-1 ) {
c = polylines.get( list.size()-N );
// sanity check
if( c.splits.size != list.size() )
throw new RuntimeException("Egads saved polylines aren't in the expected order");
} else {
c = polylines.grow();
c.reset();
c.score = Double.MAX_VALUE;
}
double foundScore = computeScore(list,cornerScorePenalty, loops);
// only save the results if it's an improvement
if( c.score > foundScore ) {
c.score = foundScore;
c.splits.reset();
c.sideErrors.reset();
Element<Corner> e = list.getHead();
double maxSideError = 0;
while (e != null) {
maxSideError = Math.max(maxSideError,e.object.sideError);
c.splits.add(e.object.index);
c.sideErrors.add(e.object.sideError);
e = e.next;
}
c.maxSideError = maxSideError;
return true;
} else {
return false;
}
} | [
"boolean",
"savePolyline",
"(",
")",
"{",
"int",
"N",
"=",
"loops",
"?",
"3",
":",
"2",
";",
"// if a polyline of this size has already been saved then over write it",
"CandidatePolyline",
"c",
";",
"if",
"(",
"list",
".",
"size",
"(",
")",
"<=",
"polylines",
".... | Saves the current polyline
@return true if the polyline is better than any previously saved result false if not and it wasn't saved | [
"Saves",
"the",
"current",
"polyline"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L250-L286 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.computeScore | static double computeScore( LinkedList<Corner> list , double cornerPenalty , boolean loops ) {
double sumSides = 0;
Element<Corner> e = list.getHead();
Element<Corner> end = loops ? null : list.getTail();
while( e != end ) {
sumSides += e.object.sideError;
e = e.next;
}
int numSides = loops ? list.size() : list.size() - 1;
return sumSides/numSides + cornerPenalty*numSides;
} | java | static double computeScore( LinkedList<Corner> list , double cornerPenalty , boolean loops ) {
double sumSides = 0;
Element<Corner> e = list.getHead();
Element<Corner> end = loops ? null : list.getTail();
while( e != end ) {
sumSides += e.object.sideError;
e = e.next;
}
int numSides = loops ? list.size() : list.size() - 1;
return sumSides/numSides + cornerPenalty*numSides;
} | [
"static",
"double",
"computeScore",
"(",
"LinkedList",
"<",
"Corner",
">",
"list",
",",
"double",
"cornerPenalty",
",",
"boolean",
"loops",
")",
"{",
"double",
"sumSides",
"=",
"0",
";",
"Element",
"<",
"Corner",
">",
"e",
"=",
"list",
".",
"getHead",
"(... | Computes the score for a list | [
"Computes",
"the",
"score",
"for",
"a",
"list"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L291-L303 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.findInitialTriangle | boolean findInitialTriangle(List<Point2D_I32> contour) {
// find the first estimate for a corner
int cornerSeed = findCornerSeed(contour);
// see if it can reject the contour immediately
if( convex ) {
if( !isConvexUsingMaxDistantPoints(contour,0,cornerSeed))
return false;
}
// Select the second corner.
splitter.selectSplitPoint(contour,0,cornerSeed,resultsA);
splitter.selectSplitPoint(contour,cornerSeed,0,resultsB);
if( splitter.compareScore(resultsA.score,resultsB.score) >= 0 ) {
addCorner(resultsA.index);
addCorner(cornerSeed);
} else {
addCorner(cornerSeed);
addCorner(resultsB.index);
}
// Select the third corner. Initial triangle will be complete now
// the third corner will be the one which maximizes the distance from the first two
int index0 = list.getHead().object.index;
int index1 = list.getHead().next.object.index;
int index2 = maximumDistance(contour,index0,index1);
addCorner(index2);
// enforce CCW requirement
ensureTriangleOrder(contour);
return initializeScore(contour, true);
} | java | boolean findInitialTriangle(List<Point2D_I32> contour) {
// find the first estimate for a corner
int cornerSeed = findCornerSeed(contour);
// see if it can reject the contour immediately
if( convex ) {
if( !isConvexUsingMaxDistantPoints(contour,0,cornerSeed))
return false;
}
// Select the second corner.
splitter.selectSplitPoint(contour,0,cornerSeed,resultsA);
splitter.selectSplitPoint(contour,cornerSeed,0,resultsB);
if( splitter.compareScore(resultsA.score,resultsB.score) >= 0 ) {
addCorner(resultsA.index);
addCorner(cornerSeed);
} else {
addCorner(cornerSeed);
addCorner(resultsB.index);
}
// Select the third corner. Initial triangle will be complete now
// the third corner will be the one which maximizes the distance from the first two
int index0 = list.getHead().object.index;
int index1 = list.getHead().next.object.index;
int index2 = maximumDistance(contour,index0,index1);
addCorner(index2);
// enforce CCW requirement
ensureTriangleOrder(contour);
return initializeScore(contour, true);
} | [
"boolean",
"findInitialTriangle",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
")",
"{",
"// find the first estimate for a corner",
"int",
"cornerSeed",
"=",
"findCornerSeed",
"(",
"contour",
")",
";",
"// see if it can reject the contour immediately",
"if",
"(",
"con... | Select an initial triangle. A good initial triangle is needed. By good it
should minimize the error of the contour from each side | [
"Select",
"an",
"initial",
"triangle",
".",
"A",
"good",
"initial",
"triangle",
"is",
"needed",
".",
"By",
"good",
"it",
"should",
"minimize",
"the",
"error",
"of",
"the",
"contour",
"from",
"each",
"side"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L309-L342 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.initializeScore | private boolean initializeScore(List<Point2D_I32> contour , boolean loops ) {
// Score each side
Element<Corner> e = list.getHead();
Element<Corner> end = loops ? null : list.getTail();
while( e != end ) {
if (convex && !isSideConvex(contour, e))
return false;
Element<Corner> n = e.next;
double error;
if( n == null ) {
error = computeSideError(contour,e.object.index, list.getHead().object.index);
} else {
error = computeSideError(contour,e.object.index, n.object.index);
}
e.object.sideError = error;
e = n;
}
// Compute what would happen if a side was split
e = list.getHead();
while( e != end ) {
computePotentialSplitScore(contour,e,list.size() < minSides);
e = e.next;
}
return true;
} | java | private boolean initializeScore(List<Point2D_I32> contour , boolean loops ) {
// Score each side
Element<Corner> e = list.getHead();
Element<Corner> end = loops ? null : list.getTail();
while( e != end ) {
if (convex && !isSideConvex(contour, e))
return false;
Element<Corner> n = e.next;
double error;
if( n == null ) {
error = computeSideError(contour,e.object.index, list.getHead().object.index);
} else {
error = computeSideError(contour,e.object.index, n.object.index);
}
e.object.sideError = error;
e = n;
}
// Compute what would happen if a side was split
e = list.getHead();
while( e != end ) {
computePotentialSplitScore(contour,e,list.size() < minSides);
e = e.next;
}
return true;
} | [
"private",
"boolean",
"initializeScore",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
",",
"boolean",
"loops",
")",
"{",
"// Score each side",
"Element",
"<",
"Corner",
">",
"e",
"=",
"list",
".",
"getHead",
"(",
")",
";",
"Element",
"<",
"Corner",
">"... | Computes the score and potential split for each side
@param contour
@return | [
"Computes",
"the",
"score",
"and",
"potential",
"split",
"for",
"each",
"side"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L349-L377 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.ensureTriangleOrder | void ensureTriangleOrder(List<Point2D_I32> contour ) {
Element<Corner> e = list.getHead();
Corner a = e.object;e=e.next;
Corner b = e.object;e=e.next;
Corner c = e.object;
int distB = CircularIndex.distanceP(a.index,b.index,contour.size());
int distC = CircularIndex.distanceP(a.index,c.index,contour.size());
if( distB > distC ) {
list.reset();
list.pushTail(a);
list.pushTail(c);
list.pushTail(b);
}
} | java | void ensureTriangleOrder(List<Point2D_I32> contour ) {
Element<Corner> e = list.getHead();
Corner a = e.object;e=e.next;
Corner b = e.object;e=e.next;
Corner c = e.object;
int distB = CircularIndex.distanceP(a.index,b.index,contour.size());
int distC = CircularIndex.distanceP(a.index,c.index,contour.size());
if( distB > distC ) {
list.reset();
list.pushTail(a);
list.pushTail(c);
list.pushTail(b);
}
} | [
"void",
"ensureTriangleOrder",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
")",
"{",
"Element",
"<",
"Corner",
">",
"e",
"=",
"list",
".",
"getHead",
"(",
")",
";",
"Corner",
"a",
"=",
"e",
".",
"object",
";",
"e",
"=",
"e",
".",
"next",
";",
... | Make sure the next corner after the head is the closest one to the head | [
"Make",
"sure",
"the",
"next",
"corner",
"after",
"the",
"head",
"is",
"the",
"closest",
"one",
"to",
"the",
"head"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L382-L397 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.increaseNumberOfSidesByOne | boolean increaseNumberOfSidesByOne(List<Point2D_I32> contour, boolean loops ) {
// System.out.println("increase number of sides by one. list = "+list.size());
Element<Corner> selected = selectCornerToSplit(loops);
// No side can be split
if( selected == null )
return false;
// Update the corner who's side was just split
selected.object.sideError = selected.object.splitError0;
// split the selected side and add a new corner
Corner c = corners.grow();
c.reset();
c.index = selected.object.splitLocation;
c.sideError = selected.object.splitError1;
Element<Corner> cornerE = list.insertAfter(selected,c);
// see if the new side could be convex
if (convex && !isSideConvex(contour, selected))
return false;
else {
// compute the score for sides which just changed
computePotentialSplitScore(contour, cornerE, list.size() < minSides);
computePotentialSplitScore(contour, selected, list.size() < minSides);
// Save the results
// printCurrent(contour);
savePolyline();
return true;
}
} | java | boolean increaseNumberOfSidesByOne(List<Point2D_I32> contour, boolean loops ) {
// System.out.println("increase number of sides by one. list = "+list.size());
Element<Corner> selected = selectCornerToSplit(loops);
// No side can be split
if( selected == null )
return false;
// Update the corner who's side was just split
selected.object.sideError = selected.object.splitError0;
// split the selected side and add a new corner
Corner c = corners.grow();
c.reset();
c.index = selected.object.splitLocation;
c.sideError = selected.object.splitError1;
Element<Corner> cornerE = list.insertAfter(selected,c);
// see if the new side could be convex
if (convex && !isSideConvex(contour, selected))
return false;
else {
// compute the score for sides which just changed
computePotentialSplitScore(contour, cornerE, list.size() < minSides);
computePotentialSplitScore(contour, selected, list.size() < minSides);
// Save the results
// printCurrent(contour);
savePolyline();
return true;
}
} | [
"boolean",
"increaseNumberOfSidesByOne",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
",",
"boolean",
"loops",
")",
"{",
"//\t\tSystem.out.println(\"increase number of sides by one. list = \"+list.size());",
"Element",
"<",
"Corner",
">",
"selected",
"=",
"selectCornerToS... | Increase the number of sides in the polyline. This is done greedily selecting the side which would improve the
score by the most of it was split.
@param contour Contour
@return true if a split was selected and false if not | [
"Increase",
"the",
"number",
"of",
"sides",
"in",
"the",
"polyline",
".",
"This",
"is",
"done",
"greedily",
"selecting",
"the",
"side",
"which",
"would",
"improve",
"the",
"score",
"by",
"the",
"most",
"of",
"it",
"was",
"split",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L413-L444 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.isSideConvex | boolean isSideConvex(List<Point2D_I32> contour, Element<Corner> e1) {
// a conservative estimate for concavity. Assumes a triangle and that the farthest
// point is equal to the distance between the two corners
Element<Corner> e2 = next(e1);
int length = CircularIndex.distanceP(e1.object.index,e2.object.index,contour.size());
Point2D_I32 p0 = contour.get(e1.object.index);
Point2D_I32 p1 = contour.get(e2.object.index);
double d = p0.distance(p1);
if (length >= d*convexTest) {
return false;
}
return true;
} | java | boolean isSideConvex(List<Point2D_I32> contour, Element<Corner> e1) {
// a conservative estimate for concavity. Assumes a triangle and that the farthest
// point is equal to the distance between the two corners
Element<Corner> e2 = next(e1);
int length = CircularIndex.distanceP(e1.object.index,e2.object.index,contour.size());
Point2D_I32 p0 = contour.get(e1.object.index);
Point2D_I32 p1 = contour.get(e2.object.index);
double d = p0.distance(p1);
if (length >= d*convexTest) {
return false;
}
return true;
} | [
"boolean",
"isSideConvex",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
",",
"Element",
"<",
"Corner",
">",
"e1",
")",
"{",
"// a conservative estimate for concavity. Assumes a triangle and that the farthest",
"// point is equal to the distance between the two corners",
"Elem... | Checks to see if the side could belong to a convex shape | [
"Checks",
"to",
"see",
"if",
"the",
"side",
"could",
"belong",
"to",
"a",
"convex",
"shape"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L449-L466 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.selectCornerToSplit | Element<Corner> selectCornerToSplit( boolean loops ) {
Element<Corner> selected = null;
double bestChange = convex ? 0 : -Double.MAX_VALUE;
// Pick the side that if split would improve the overall score the most
Element<Corner> e=list.getHead();
Element<Corner> end = loops ? null : list.getTail();
while( e != end ) {
Corner c = e.object;
if( !c.splitable) {
e = e.next;
continue;
}
// compute how much better the score will improve because of the split
double change = c.sideError*2 - c.splitError0 - c.splitError1;
// it was found that selecting for the biggest change tends to produce better results
if( change < 0 ) {
change = -change;
}
if( change > bestChange ) {
bestChange = change;
selected = e;
}
e = e.next;
}
return selected;
} | java | Element<Corner> selectCornerToSplit( boolean loops ) {
Element<Corner> selected = null;
double bestChange = convex ? 0 : -Double.MAX_VALUE;
// Pick the side that if split would improve the overall score the most
Element<Corner> e=list.getHead();
Element<Corner> end = loops ? null : list.getTail();
while( e != end ) {
Corner c = e.object;
if( !c.splitable) {
e = e.next;
continue;
}
// compute how much better the score will improve because of the split
double change = c.sideError*2 - c.splitError0 - c.splitError1;
// it was found that selecting for the biggest change tends to produce better results
if( change < 0 ) {
change = -change;
}
if( change > bestChange ) {
bestChange = change;
selected = e;
}
e = e.next;
}
return selected;
} | [
"Element",
"<",
"Corner",
">",
"selectCornerToSplit",
"(",
"boolean",
"loops",
")",
"{",
"Element",
"<",
"Corner",
">",
"selected",
"=",
"null",
";",
"double",
"bestChange",
"=",
"convex",
"?",
"0",
":",
"-",
"Double",
".",
"MAX_VALUE",
";",
"// Pick the s... | Selects the best side to split the polyline at.
@return the selected side or null if the score will not be improved if any of the sides are split | [
"Selects",
"the",
"best",
"side",
"to",
"split",
"the",
"polyline",
"at",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L472-L501 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.selectCornerToRemove | Element<Corner> selectCornerToRemove(List<Point2D_I32> contour , ErrorValue sideError , boolean loops ) {
if( list.size() <= 3 )
return null;
// Pick the side that if split would improve the overall score the most
Element<Corner> target,end;
// if it loops any corner can be split. If it doesn't look the end points can't be removed
if( loops ) {
target = list.getHead();
end = null;
} else {
target = list.getHead().next;
end = list.getTail();
}
Element<Corner> best = null;
double bestScore = -Double.MAX_VALUE;
while( target != end ) {
Element<Corner> p = previous(target);
Element<Corner> n = next(target);
// just contributions of the corners in question
double before = (p.object.sideError + target.object.sideError)/2.0 + cornerScorePenalty;
double after = computeSideError(contour, p.object.index, n.object.index);
if( before-after > bestScore ) {
bestScore = before-after;
best = target;
sideError.value = after;
}
target = target.next;
}
return best;
} | java | Element<Corner> selectCornerToRemove(List<Point2D_I32> contour , ErrorValue sideError , boolean loops ) {
if( list.size() <= 3 )
return null;
// Pick the side that if split would improve the overall score the most
Element<Corner> target,end;
// if it loops any corner can be split. If it doesn't look the end points can't be removed
if( loops ) {
target = list.getHead();
end = null;
} else {
target = list.getHead().next;
end = list.getTail();
}
Element<Corner> best = null;
double bestScore = -Double.MAX_VALUE;
while( target != end ) {
Element<Corner> p = previous(target);
Element<Corner> n = next(target);
// just contributions of the corners in question
double before = (p.object.sideError + target.object.sideError)/2.0 + cornerScorePenalty;
double after = computeSideError(contour, p.object.index, n.object.index);
if( before-after > bestScore ) {
bestScore = before-after;
best = target;
sideError.value = after;
}
target = target.next;
}
return best;
} | [
"Element",
"<",
"Corner",
">",
"selectCornerToRemove",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
",",
"ErrorValue",
"sideError",
",",
"boolean",
"loops",
")",
"{",
"if",
"(",
"list",
".",
"size",
"(",
")",
"<=",
"3",
")",
"return",
"null",
";",
... | Selects the best corner to remove. If no corner was found that can be removed then null is returned
@return The corner to remove. Should only return null if there are 3 sides or less | [
"Selects",
"the",
"best",
"corner",
"to",
"remove",
".",
"If",
"no",
"corner",
"was",
"found",
"that",
"can",
"be",
"removed",
"then",
"null",
"is",
"returned"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L507-L543 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.removeCornerAndSavePolyline | boolean removeCornerAndSavePolyline( Element<Corner> corner, double sideErrorAfterRemoved ) {
// System.out.println("removing a corner idx="+target.object.index);
// Note: the corner is "lost" until the next contour is fit. Not worth the effort to recycle
Element<Corner> p = previous(corner);
// go through the hassle of passing in this value instead of recomputing it
// since recomputing it isn't trivial
p.object.sideError = sideErrorAfterRemoved;
list.remove(corner);
// the line below is commented out because right now the current algorithm will
// never grow after removing a corner. If this changes in the future uncomment it
// computePotentialSplitScore(contour,p);
return savePolyline();
} | java | boolean removeCornerAndSavePolyline( Element<Corner> corner, double sideErrorAfterRemoved ) {
// System.out.println("removing a corner idx="+target.object.index);
// Note: the corner is "lost" until the next contour is fit. Not worth the effort to recycle
Element<Corner> p = previous(corner);
// go through the hassle of passing in this value instead of recomputing it
// since recomputing it isn't trivial
p.object.sideError = sideErrorAfterRemoved;
list.remove(corner);
// the line below is commented out because right now the current algorithm will
// never grow after removing a corner. If this changes in the future uncomment it
// computePotentialSplitScore(contour,p);
return savePolyline();
} | [
"boolean",
"removeCornerAndSavePolyline",
"(",
"Element",
"<",
"Corner",
">",
"corner",
",",
"double",
"sideErrorAfterRemoved",
")",
"{",
"//\t\t\tSystem.out.println(\"removing a corner idx=\"+target.object.index);",
"// Note: the corner is \"lost\" until the next contour is fit. Not wor... | Remove the corner from the current polyline. If the new polyline has a better score than the currently
saved one with the same number of corners save it
@param corner The corner to removed | [
"Remove",
"the",
"corner",
"from",
"the",
"current",
"polyline",
".",
"If",
"the",
"new",
"polyline",
"has",
"a",
"better",
"score",
"than",
"the",
"currently",
"saved",
"one",
"with",
"the",
"same",
"number",
"of",
"corners",
"save",
"it"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L550-L563 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.findCornerSeed | static int findCornerSeed(List<Point2D_I32> contour ) {
Point2D_I32 a = contour.get(0);
int best = -1;
double bestDistance = -Double.MAX_VALUE;
for (int i = 1; i < contour.size(); i++) {
Point2D_I32 b = contour.get(i);
double d = distanceSq(a,b);
if( d > bestDistance ) {
bestDistance = d;
best = i;
}
}
return best;
} | java | static int findCornerSeed(List<Point2D_I32> contour ) {
Point2D_I32 a = contour.get(0);
int best = -1;
double bestDistance = -Double.MAX_VALUE;
for (int i = 1; i < contour.size(); i++) {
Point2D_I32 b = contour.get(i);
double d = distanceSq(a,b);
if( d > bestDistance ) {
bestDistance = d;
best = i;
}
}
return best;
} | [
"static",
"int",
"findCornerSeed",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
")",
"{",
"Point2D_I32",
"a",
"=",
"contour",
".",
"get",
"(",
"0",
")",
";",
"int",
"best",
"=",
"-",
"1",
";",
"double",
"bestDistance",
"=",
"-",
"Double",
".",
"M... | The seed corner is the point farther away from the first point. In a perfect polygon with no noise this should
be a corner. | [
"The",
"seed",
"corner",
"is",
"the",
"point",
"farther",
"away",
"from",
"the",
"first",
"point",
".",
"In",
"a",
"perfect",
"polygon",
"with",
"no",
"noise",
"this",
"should",
"be",
"a",
"corner",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L569-L586 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.maximumDistance | static int maximumDistance(List<Point2D_I32> contour , int indexA , int indexB ) {
Point2D_I32 a = contour.get(indexA);
Point2D_I32 b = contour.get(indexB);
int best = -1;
double bestDistance = -Double.MAX_VALUE;
for (int i = 0; i < contour.size(); i++) {
Point2D_I32 c = contour.get(i);
// can't sum sq distance because some skinny shapes it maximizes one and not the other
// double d = Math.sqrt(distanceSq(a,c)) + Math.sqrt(distanceSq(b,c));
double d = distanceAbs(a,c) + distanceAbs(b,c);
if( d > bestDistance ) {
bestDistance = d;
best = i;
}
}
return best;
} | java | static int maximumDistance(List<Point2D_I32> contour , int indexA , int indexB ) {
Point2D_I32 a = contour.get(indexA);
Point2D_I32 b = contour.get(indexB);
int best = -1;
double bestDistance = -Double.MAX_VALUE;
for (int i = 0; i < contour.size(); i++) {
Point2D_I32 c = contour.get(i);
// can't sum sq distance because some skinny shapes it maximizes one and not the other
// double d = Math.sqrt(distanceSq(a,c)) + Math.sqrt(distanceSq(b,c));
double d = distanceAbs(a,c) + distanceAbs(b,c);
if( d > bestDistance ) {
bestDistance = d;
best = i;
}
}
return best;
} | [
"static",
"int",
"maximumDistance",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
",",
"int",
"indexA",
",",
"int",
"indexB",
")",
"{",
"Point2D_I32",
"a",
"=",
"contour",
".",
"get",
"(",
"indexA",
")",
";",
"Point2D_I32",
"b",
"=",
"contour",
".",
... | Finds the point in the contour which maximizes the distance between points A
and B.
@param contour List of all pointsi n the contour
@param indexA Index of point A
@param indexB Index of point B
@return Index of maximal distant point | [
"Finds",
"the",
"point",
"in",
"the",
"contour",
"which",
"maximizes",
"the",
"distance",
"between",
"points",
"A",
"and",
"B",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L597-L616 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.computeSideError | double computeSideError(List<Point2D_I32> contour , int indexA , int indexB ) {
assignLine(contour, indexA, indexB, line);
// don't sample the end points because the error will be zero by definition
int numSamples;
double sumOfDistances = 0;
int length;
if( indexB >= indexA ) {
length = indexB-indexA-1;
numSamples = Math.min(length,maxNumberOfSideSamples);
for (int i = 0; i < numSamples; i++) {
int index = indexA+1+length*i/numSamples;
Point2D_I32 p = contour.get(index);
sumOfDistances += Distance2D_F64.distanceSq(line,p.x,p.y);
}
sumOfDistances /= numSamples;
} else {
length = contour.size()-indexA-1 + indexB;
numSamples = Math.min(length,maxNumberOfSideSamples);
for (int i = 0; i < numSamples; i++) {
int where = length*i/numSamples;
int index = (indexA+1+where)%contour.size();
Point2D_I32 p = contour.get(index);
sumOfDistances += Distance2D_F64.distanceSq(line,p.x,p.y);
}
sumOfDistances /= numSamples;
}
// handle divide by zero error
if( numSamples > 0 )
return sumOfDistances;
else
return 0;
} | java | double computeSideError(List<Point2D_I32> contour , int indexA , int indexB ) {
assignLine(contour, indexA, indexB, line);
// don't sample the end points because the error will be zero by definition
int numSamples;
double sumOfDistances = 0;
int length;
if( indexB >= indexA ) {
length = indexB-indexA-1;
numSamples = Math.min(length,maxNumberOfSideSamples);
for (int i = 0; i < numSamples; i++) {
int index = indexA+1+length*i/numSamples;
Point2D_I32 p = contour.get(index);
sumOfDistances += Distance2D_F64.distanceSq(line,p.x,p.y);
}
sumOfDistances /= numSamples;
} else {
length = contour.size()-indexA-1 + indexB;
numSamples = Math.min(length,maxNumberOfSideSamples);
for (int i = 0; i < numSamples; i++) {
int where = length*i/numSamples;
int index = (indexA+1+where)%contour.size();
Point2D_I32 p = contour.get(index);
sumOfDistances += Distance2D_F64.distanceSq(line,p.x,p.y);
}
sumOfDistances /= numSamples;
}
// handle divide by zero error
if( numSamples > 0 )
return sumOfDistances;
else
return 0;
} | [
"double",
"computeSideError",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
",",
"int",
"indexA",
",",
"int",
"indexB",
")",
"{",
"assignLine",
"(",
"contour",
",",
"indexA",
",",
"indexB",
",",
"line",
")",
";",
"// don't sample the end points because the er... | Scores a side based on the sum of Euclidean distance squared of each point along the line. Euclidean squared
is used because its fast to compute
@param indexA first index. Inclusive
@param indexB last index. Exclusive | [
"Scores",
"a",
"side",
"based",
"on",
"the",
"sum",
"of",
"Euclidean",
"distance",
"squared",
"of",
"each",
"point",
"along",
"the",
"line",
".",
"Euclidean",
"squared",
"is",
"used",
"because",
"its",
"fast",
"to",
"compute"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L625-L658 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.computePotentialSplitScore | void computePotentialSplitScore( List<Point2D_I32> contour , Element<Corner> e0 , boolean mustSplit )
{
Element<Corner> e1 = next(e0);
e0.object.splitable = canBeSplit(contour,e0,mustSplit);
if( e0.object.splitable ) {
setSplitVariables(contour, e0, e1);
}
} | java | void computePotentialSplitScore( List<Point2D_I32> contour , Element<Corner> e0 , boolean mustSplit )
{
Element<Corner> e1 = next(e0);
e0.object.splitable = canBeSplit(contour,e0,mustSplit);
if( e0.object.splitable ) {
setSplitVariables(contour, e0, e1);
}
} | [
"void",
"computePotentialSplitScore",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
",",
"Element",
"<",
"Corner",
">",
"e0",
",",
"boolean",
"mustSplit",
")",
"{",
"Element",
"<",
"Corner",
">",
"e1",
"=",
"next",
"(",
"e0",
")",
";",
"e0",
".",
"o... | Computes the split location and the score of the two new sides if it's split there | [
"Computes",
"the",
"split",
"location",
"and",
"the",
"score",
"of",
"the",
"two",
"new",
"sides",
"if",
"it",
"s",
"split",
"there"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L663-L672 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.setSplitVariables | void setSplitVariables(List<Point2D_I32> contour, Element<Corner> e0, Element<Corner> e1) {
int distance0 = CircularIndex.distanceP(e0.object.index, e1.object.index, contour.size());
int index0 = CircularIndex.plusPOffset(e0.object.index,minimumSideLength,contour.size());
int index1 = CircularIndex.minusPOffset(e1.object.index,minimumSideLength,contour.size());
splitter.selectSplitPoint(contour, index0, index1, resultsA);
// if convex only perform the split if it would result in a convex polygon
if( convex ) {
Point2D_I32 a = contour.get(e0.object.index);
Point2D_I32 b = contour.get(resultsA.index);
Point2D_I32 c = contour.get(next(e0).object.index);
if (UtilPolygons2D_I32.isPositiveZ(a, b, c)) {
e0.object.splitable = false;
return;
}
}
// see if this would result in a side that's too small
int dist0 = CircularIndex.distanceP(e0.object.index,resultsA.index, contour.size());
if( dist0 < minimumSideLength || (contour.size()-dist0) < minimumSideLength ) {
throw new RuntimeException("Should be impossible");
}
// this function is only called if splitable is set to true so no need to set it again
e0.object.splitLocation = resultsA.index;
e0.object.splitError0 = computeSideError(contour, e0.object.index, resultsA.index);
e0.object.splitError1 = computeSideError(contour, resultsA.index, e1.object.index);
if( e0.object.splitLocation >= contour.size() )
throw new RuntimeException("Egads");
} | java | void setSplitVariables(List<Point2D_I32> contour, Element<Corner> e0, Element<Corner> e1) {
int distance0 = CircularIndex.distanceP(e0.object.index, e1.object.index, contour.size());
int index0 = CircularIndex.plusPOffset(e0.object.index,minimumSideLength,contour.size());
int index1 = CircularIndex.minusPOffset(e1.object.index,minimumSideLength,contour.size());
splitter.selectSplitPoint(contour, index0, index1, resultsA);
// if convex only perform the split if it would result in a convex polygon
if( convex ) {
Point2D_I32 a = contour.get(e0.object.index);
Point2D_I32 b = contour.get(resultsA.index);
Point2D_I32 c = contour.get(next(e0).object.index);
if (UtilPolygons2D_I32.isPositiveZ(a, b, c)) {
e0.object.splitable = false;
return;
}
}
// see if this would result in a side that's too small
int dist0 = CircularIndex.distanceP(e0.object.index,resultsA.index, contour.size());
if( dist0 < minimumSideLength || (contour.size()-dist0) < minimumSideLength ) {
throw new RuntimeException("Should be impossible");
}
// this function is only called if splitable is set to true so no need to set it again
e0.object.splitLocation = resultsA.index;
e0.object.splitError0 = computeSideError(contour, e0.object.index, resultsA.index);
e0.object.splitError1 = computeSideError(contour, resultsA.index, e1.object.index);
if( e0.object.splitLocation >= contour.size() )
throw new RuntimeException("Egads");
} | [
"void",
"setSplitVariables",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
",",
"Element",
"<",
"Corner",
">",
"e0",
",",
"Element",
"<",
"Corner",
">",
"e1",
")",
"{",
"int",
"distance0",
"=",
"CircularIndex",
".",
"distanceP",
"(",
"e0",
".",
"objec... | Selects and splits the side defined by the e0 corner. If convex a check is performed to
ensure that the polyline will be convex still. | [
"Selects",
"and",
"splits",
"the",
"side",
"defined",
"by",
"the",
"e0",
"corner",
".",
"If",
"convex",
"a",
"check",
"is",
"performed",
"to",
"ensure",
"that",
"the",
"polyline",
"will",
"be",
"convex",
"still",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L678-L712 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.canBeSplit | boolean canBeSplit( List<Point2D_I32> contour, Element<Corner> e0 , boolean mustSplit ) {
Element<Corner> e1 = next(e0);
// NOTE: The contour is passed in but only the size of the contour matters. This was done to prevent
// changing the signature if the algorithm was changed later on.
int length = CircularIndex.distanceP(e0.object.index, e1.object.index, contour.size());
// needs to be <= to prevent it from trying to split a side less than 1
// times two because the two new sides would have to have a length of at least min
if (length <= 2*minimumSideLength) {
return false;
}
// threshold is greater than zero ti prevent it from saying it can split a perfect side
return mustSplit || e0.object.sideError > thresholdSideSplitScore;
} | java | boolean canBeSplit( List<Point2D_I32> contour, Element<Corner> e0 , boolean mustSplit ) {
Element<Corner> e1 = next(e0);
// NOTE: The contour is passed in but only the size of the contour matters. This was done to prevent
// changing the signature if the algorithm was changed later on.
int length = CircularIndex.distanceP(e0.object.index, e1.object.index, contour.size());
// needs to be <= to prevent it from trying to split a side less than 1
// times two because the two new sides would have to have a length of at least min
if (length <= 2*minimumSideLength) {
return false;
}
// threshold is greater than zero ti prevent it from saying it can split a perfect side
return mustSplit || e0.object.sideError > thresholdSideSplitScore;
} | [
"boolean",
"canBeSplit",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
",",
"Element",
"<",
"Corner",
">",
"e0",
",",
"boolean",
"mustSplit",
")",
"{",
"Element",
"<",
"Corner",
">",
"e1",
"=",
"next",
"(",
"e0",
")",
";",
"// NOTE: The contour is passe... | Determines if the side can be split again. A side can always be split as long as
it's ≥ the minimum length or that the side score is larger the the split threshold
@param e0 The side which is to be tested to see if it can be split
@param mustSplit if true this will force it to split even if the error would prevent it from splitting
@return true if it can be split or false if not | [
"Determines",
"if",
"the",
"side",
"can",
"be",
"split",
"again",
".",
"A",
"side",
"can",
"always",
"be",
"split",
"as",
"long",
"as",
"it",
"s",
"&ge",
";",
"the",
"minimum",
"length",
"or",
"that",
"the",
"side",
"score",
"is",
"larger",
"the",
"t... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L722-L737 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.next | Element<Corner> next( Element<Corner> e ) {
if( e.next == null ) {
return list.getHead();
} else {
return e.next;
}
} | java | Element<Corner> next( Element<Corner> e ) {
if( e.next == null ) {
return list.getHead();
} else {
return e.next;
}
} | [
"Element",
"<",
"Corner",
">",
"next",
"(",
"Element",
"<",
"Corner",
">",
"e",
")",
"{",
"if",
"(",
"e",
".",
"next",
"==",
"null",
")",
"{",
"return",
"list",
".",
"getHead",
"(",
")",
";",
"}",
"else",
"{",
"return",
"e",
".",
"next",
";",
... | Returns the next corner in the list | [
"Returns",
"the",
"next",
"corner",
"in",
"the",
"list"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L742-L748 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.previous | Element<Corner> previous( Element<Corner> e ) {
if( e.previous == null ) {
return list.getTail();
} else {
return e.previous;
}
} | java | Element<Corner> previous( Element<Corner> e ) {
if( e.previous == null ) {
return list.getTail();
} else {
return e.previous;
}
} | [
"Element",
"<",
"Corner",
">",
"previous",
"(",
"Element",
"<",
"Corner",
">",
"e",
")",
"{",
"if",
"(",
"e",
".",
"previous",
"==",
"null",
")",
"{",
"return",
"list",
".",
"getTail",
"(",
")",
";",
"}",
"else",
"{",
"return",
"e",
".",
"previou... | Returns the previous corner in the list | [
"Returns",
"the",
"previous",
"corner",
"in",
"the",
"list"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L753-L759 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.distanceSq | static double distanceSq( Point2D_I32 a , Point2D_I32 b ) {
double dx = b.x-a.x;
double dy = b.y-a.y;
return dx*dx + dy*dy;
} | java | static double distanceSq( Point2D_I32 a , Point2D_I32 b ) {
double dx = b.x-a.x;
double dy = b.y-a.y;
return dx*dx + dy*dy;
} | [
"static",
"double",
"distanceSq",
"(",
"Point2D_I32",
"a",
",",
"Point2D_I32",
"b",
")",
"{",
"double",
"dx",
"=",
"b",
".",
"x",
"-",
"a",
".",
"x",
";",
"double",
"dy",
"=",
"b",
".",
"y",
"-",
"a",
".",
"y",
";",
"return",
"dx",
"*",
"dx",
... | Using double prevision here instead of int due to fear of overflow in very large images | [
"Using",
"double",
"prevision",
"here",
"instead",
"of",
"int",
"due",
"to",
"fear",
"of",
"overflow",
"in",
"very",
"large",
"images"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L791-L796 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java | PolylineSplitMerge.assignLine | public static void assignLine(List<Point2D_I32> contour, int indexA, int indexB, LineParametric2D_F64 line) {
Point2D_I32 endA = contour.get(indexA);
Point2D_I32 endB = contour.get(indexB);
line.p.x = endA.x;
line.p.y = endA.y;
line.slope.x = endB.x-endA.x;
line.slope.y = endB.y-endA.y;
} | java | public static void assignLine(List<Point2D_I32> contour, int indexA, int indexB, LineParametric2D_F64 line) {
Point2D_I32 endA = contour.get(indexA);
Point2D_I32 endB = contour.get(indexB);
line.p.x = endA.x;
line.p.y = endA.y;
line.slope.x = endB.x-endA.x;
line.slope.y = endB.y-endA.y;
} | [
"public",
"static",
"void",
"assignLine",
"(",
"List",
"<",
"Point2D_I32",
">",
"contour",
",",
"int",
"indexA",
",",
"int",
"indexB",
",",
"LineParametric2D_F64",
"line",
")",
"{",
"Point2D_I32",
"endA",
"=",
"contour",
".",
"get",
"(",
"indexA",
")",
";"... | Assigns the line so that it passes through points A and B. | [
"Assigns",
"the",
"line",
"so",
"that",
"it",
"passes",
"through",
"points",
"A",
"and",
"B",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/PolylineSplitMerge.java#L808-L816 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/SplitMergeLineFitSegment.java | SplitMergeLineFitSegment.splitPixels | protected void splitPixels( int indexStart , int indexStop ) {
// too short to split
if( indexStart+1 >= indexStop )
return;
int indexSplit = selectSplitBetween(indexStart, indexStop);
if( indexSplit >= 0 ) {
splitPixels(indexStart, indexSplit);
splits.add(indexSplit);
splitPixels(indexSplit, indexStop);
}
} | java | protected void splitPixels( int indexStart , int indexStop ) {
// too short to split
if( indexStart+1 >= indexStop )
return;
int indexSplit = selectSplitBetween(indexStart, indexStop);
if( indexSplit >= 0 ) {
splitPixels(indexStart, indexSplit);
splits.add(indexSplit);
splitPixels(indexSplit, indexStop);
}
} | [
"protected",
"void",
"splitPixels",
"(",
"int",
"indexStart",
",",
"int",
"indexStop",
")",
"{",
"// too short to split",
"if",
"(",
"indexStart",
"+",
"1",
">=",
"indexStop",
")",
"return",
";",
"int",
"indexSplit",
"=",
"selectSplitBetween",
"(",
"indexStart",... | Recursively splits pixels. Used in the initial segmentation. Only split points between
the two ends are added | [
"Recursively",
"splits",
"pixels",
".",
"Used",
"in",
"the",
"initial",
"segmentation",
".",
"Only",
"split",
"points",
"between",
"the",
"two",
"ends",
"are",
"added"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/SplitMergeLineFitSegment.java#L70-L82 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/SplitMergeLineFitSegment.java | SplitMergeLineFitSegment.splitSegments | protected boolean splitSegments() {
boolean change = false;
work.reset();
for( int i = 0; i < splits.size-1; i++ ) {
int start = splits.data[i];
int end = splits.data[i+1];
int bestIndex = selectSplitBetween(start, end);
if( bestIndex >= 0 ) {
change |= true;
work.add(start);
work.add(bestIndex);
} else {
work.add(start);
}
}
work.add(splits.data[ splits.size-1] );
// swap the two lists
GrowQueue_I32 tmp = work;
work = splits;
splits = tmp;
return change;
} | java | protected boolean splitSegments() {
boolean change = false;
work.reset();
for( int i = 0; i < splits.size-1; i++ ) {
int start = splits.data[i];
int end = splits.data[i+1];
int bestIndex = selectSplitBetween(start, end);
if( bestIndex >= 0 ) {
change |= true;
work.add(start);
work.add(bestIndex);
} else {
work.add(start);
}
}
work.add(splits.data[ splits.size-1] );
// swap the two lists
GrowQueue_I32 tmp = work;
work = splits;
splits = tmp;
return change;
} | [
"protected",
"boolean",
"splitSegments",
"(",
")",
"{",
"boolean",
"change",
"=",
"false",
";",
"work",
".",
"reset",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"splits",
".",
"size",
"-",
"1",
";",
"i",
"++",
")",
"{",
"in... | Splits a line in two if there is a paint that is too far away
@return true for change | [
"Splits",
"a",
"line",
"in",
"two",
"if",
"there",
"is",
"a",
"paint",
"that",
"is",
"too",
"far",
"away"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/SplitMergeLineFitSegment.java#L88-L113 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/SplitMergeLineFitSegment.java | SplitMergeLineFitSegment.mergeSegments | protected boolean mergeSegments() {
// can't merge a single line
if( splits.size <= 2 )
return false;
boolean change = false;
work.reset();
// first point is always at the start
work.add(splits.data[0]);
for( int i = 0; i < splits.size-2; i++ ) {
if( selectSplitBetween(splits.data[i],splits.data[i+2]) < 0 ) {
// merge the two lines by not adding it
change = true;
} else {
work.add(splits.data[i + 1]);
}
}
// and end
work.add(splits.data[splits.size-1]);
// swap the two lists
GrowQueue_I32 tmp = work;
work = splits;
splits = tmp;
return change;
} | java | protected boolean mergeSegments() {
// can't merge a single line
if( splits.size <= 2 )
return false;
boolean change = false;
work.reset();
// first point is always at the start
work.add(splits.data[0]);
for( int i = 0; i < splits.size-2; i++ ) {
if( selectSplitBetween(splits.data[i],splits.data[i+2]) < 0 ) {
// merge the two lines by not adding it
change = true;
} else {
work.add(splits.data[i + 1]);
}
}
// and end
work.add(splits.data[splits.size-1]);
// swap the two lists
GrowQueue_I32 tmp = work;
work = splits;
splits = tmp;
return change;
} | [
"protected",
"boolean",
"mergeSegments",
"(",
")",
"{",
"// can't merge a single line",
"if",
"(",
"splits",
".",
"size",
"<=",
"2",
")",
"return",
"false",
";",
"boolean",
"change",
"=",
"false",
";",
"work",
".",
"reset",
"(",
")",
";",
"// first point is ... | Merges lines together which have an acute angle less than the threshold.
@return true the list being changed | [
"Merges",
"lines",
"together",
"which",
"have",
"an",
"acute",
"angle",
"less",
"than",
"the",
"threshold",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polyline/splitmerge/SplitMergeLineFitSegment.java#L153-L182 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldRegionTracker.java | TldRegionTracker.initialize | public void initialize(PyramidDiscrete<I> image ) {
if( previousDerivX == null || previousDerivX.length != image.getNumLayers()
|| previousImage.getInputWidth() != image.getInputWidth() || previousImage.getInputHeight() != image.getInputHeight() ) {
declareDataStructures(image);
}
for( int i = 0; i < image.getNumLayers(); i++ ) {
gradient.process(image.getLayer(i), previousDerivX[i], previousDerivY[i]);
}
previousImage.setTo(image);
} | java | public void initialize(PyramidDiscrete<I> image ) {
if( previousDerivX == null || previousDerivX.length != image.getNumLayers()
|| previousImage.getInputWidth() != image.getInputWidth() || previousImage.getInputHeight() != image.getInputHeight() ) {
declareDataStructures(image);
}
for( int i = 0; i < image.getNumLayers(); i++ ) {
gradient.process(image.getLayer(i), previousDerivX[i], previousDerivY[i]);
}
previousImage.setTo(image);
} | [
"public",
"void",
"initialize",
"(",
"PyramidDiscrete",
"<",
"I",
">",
"image",
")",
"{",
"if",
"(",
"previousDerivX",
"==",
"null",
"||",
"previousDerivX",
".",
"length",
"!=",
"image",
".",
"getNumLayers",
"(",
")",
"||",
"previousImage",
".",
"getInputWid... | Call for the first image being tracked
@param image Most recent video image. | [
"Call",
"for",
"the",
"first",
"image",
"being",
"tracked"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldRegionTracker.java#L124-L135 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldRegionTracker.java | TldRegionTracker.declareDataStructures | protected void declareDataStructures(PyramidDiscrete<I> image) {
numPyramidLayers = image.getNumLayers();
previousDerivX = (D[])Array.newInstance(derivType,image.getNumLayers());
previousDerivY = (D[])Array.newInstance(derivType,image.getNumLayers());
currentDerivX = (D[])Array.newInstance(derivType,image.getNumLayers());
currentDerivY = (D[])Array.newInstance(derivType,image.getNumLayers());
for( int i = 0; i < image.getNumLayers(); i++ ) {
int w = image.getWidth(i);
int h = image.getHeight(i);
previousDerivX[i] = GeneralizedImageOps.createSingleBand(derivType, w, h);
previousDerivY[i] = GeneralizedImageOps.createSingleBand(derivType, w, h);
currentDerivX[i] = GeneralizedImageOps.createSingleBand(derivType, w, h);
currentDerivY[i] = GeneralizedImageOps.createSingleBand(derivType, w, h);
}
Class imageClass = image.getImageType().getImageClass();
previousImage = FactoryPyramid.discreteGaussian(image.getScales(), -1, 1, false, ImageType.single(imageClass));
previousImage.initialize(image.getInputWidth(), image.getInputHeight());
for( int i = 0; i < tracks.length; i++ ) {
Track t = new Track();
t.klt = new PyramidKltFeature(numPyramidLayers,featureRadius);
tracks[i] = t;
}
} | java | protected void declareDataStructures(PyramidDiscrete<I> image) {
numPyramidLayers = image.getNumLayers();
previousDerivX = (D[])Array.newInstance(derivType,image.getNumLayers());
previousDerivY = (D[])Array.newInstance(derivType,image.getNumLayers());
currentDerivX = (D[])Array.newInstance(derivType,image.getNumLayers());
currentDerivY = (D[])Array.newInstance(derivType,image.getNumLayers());
for( int i = 0; i < image.getNumLayers(); i++ ) {
int w = image.getWidth(i);
int h = image.getHeight(i);
previousDerivX[i] = GeneralizedImageOps.createSingleBand(derivType, w, h);
previousDerivY[i] = GeneralizedImageOps.createSingleBand(derivType, w, h);
currentDerivX[i] = GeneralizedImageOps.createSingleBand(derivType, w, h);
currentDerivY[i] = GeneralizedImageOps.createSingleBand(derivType, w, h);
}
Class imageClass = image.getImageType().getImageClass();
previousImage = FactoryPyramid.discreteGaussian(image.getScales(), -1, 1, false, ImageType.single(imageClass));
previousImage.initialize(image.getInputWidth(), image.getInputHeight());
for( int i = 0; i < tracks.length; i++ ) {
Track t = new Track();
t.klt = new PyramidKltFeature(numPyramidLayers,featureRadius);
tracks[i] = t;
}
} | [
"protected",
"void",
"declareDataStructures",
"(",
"PyramidDiscrete",
"<",
"I",
">",
"image",
")",
"{",
"numPyramidLayers",
"=",
"image",
".",
"getNumLayers",
"(",
")",
";",
"previousDerivX",
"=",
"(",
"D",
"[",
"]",
")",
"Array",
".",
"newInstance",
"(",
... | Declares internal data structures based on the input image pyramid | [
"Declares",
"internal",
"data",
"structures",
"based",
"on",
"the",
"input",
"image",
"pyramid"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldRegionTracker.java#L140-L167 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldRegionTracker.java | TldRegionTracker.process | public boolean process(ImagePyramid<I> image , Rectangle2D_F64 targetRectangle ) {
boolean success = true;
updateCurrent(image);
// create feature tracks
spawnGrid(targetRectangle);
// track features while computing forward/backward error and NCC error
if( !trackFeature() )
success = false;
// makes the current image into a previous image
setCurrentToPrevious();
return success;
} | java | public boolean process(ImagePyramid<I> image , Rectangle2D_F64 targetRectangle ) {
boolean success = true;
updateCurrent(image);
// create feature tracks
spawnGrid(targetRectangle);
// track features while computing forward/backward error and NCC error
if( !trackFeature() )
success = false;
// makes the current image into a previous image
setCurrentToPrevious();
return success;
} | [
"public",
"boolean",
"process",
"(",
"ImagePyramid",
"<",
"I",
">",
"image",
",",
"Rectangle2D_F64",
"targetRectangle",
")",
"{",
"boolean",
"success",
"=",
"true",
";",
"updateCurrent",
"(",
"image",
")",
";",
"// create feature tracks",
"spawnGrid",
"(",
"targ... | Creates several tracks inside the target rectangle and compuets their motion
@param image Most recent video image.
@param targetRectangle Location of target in previous frame. Not modified.
@return true if tracking was successful or false if not | [
"Creates",
"several",
"tracks",
"inside",
"the",
"target",
"rectangle",
"and",
"compuets",
"their",
"motion"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldRegionTracker.java#L176-L192 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldRegionTracker.java | TldRegionTracker.updateCurrent | protected void updateCurrent(ImagePyramid<I> image) {
this.currentImage = image;
for( int i = 0; i < image.getNumLayers(); i++ ) {
gradient.process(image.getLayer(i), currentDerivX[i], currentDerivY[i]);
}
} | java | protected void updateCurrent(ImagePyramid<I> image) {
this.currentImage = image;
for( int i = 0; i < image.getNumLayers(); i++ ) {
gradient.process(image.getLayer(i), currentDerivX[i], currentDerivY[i]);
}
} | [
"protected",
"void",
"updateCurrent",
"(",
"ImagePyramid",
"<",
"I",
">",
"image",
")",
"{",
"this",
".",
"currentImage",
"=",
"image",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"image",
".",
"getNumLayers",
"(",
")",
";",
"i",
"++",
")... | Computes the gradient and changes the reference to the current pyramid | [
"Computes",
"the",
"gradient",
"and",
"changes",
"the",
"reference",
"to",
"the",
"current",
"pyramid"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldRegionTracker.java#L197-L202 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldRegionTracker.java | TldRegionTracker.spawnGrid | protected void spawnGrid(Rectangle2D_F64 prevRect ) {
// Shrink the rectangle to ensure that all features are entirely contained inside
spawnRect.p0.x = prevRect.p0.x + featureRadius;
spawnRect.p0.y = prevRect.p0.y + featureRadius;
spawnRect.p1.x = prevRect.p1.x - featureRadius;
spawnRect.p1.y = prevRect.p1.y - featureRadius;
double spawnWidth = spawnRect.getWidth();
double spawnHeight = spawnRect.getHeight();
// try spawning features at evenly spaced points inside the grid
tracker.setImage(previousImage,previousDerivX,previousDerivY);
for( int i = 0; i < gridWidth; i++ ) {
float y = (float)(spawnRect.p0.y + i*spawnHeight/(gridWidth-1));
for( int j = 0; j < gridWidth; j++ ) {
float x = (float)(spawnRect.p0.x + j*spawnWidth/(gridWidth-1));
Track t = tracks[i*gridWidth+j];
t.klt.x = x;
t.klt.y = y;
if( tracker.setDescription(t.klt) ) {
t.active = true;
} else {
t.active = false;
}
}
}
} | java | protected void spawnGrid(Rectangle2D_F64 prevRect ) {
// Shrink the rectangle to ensure that all features are entirely contained inside
spawnRect.p0.x = prevRect.p0.x + featureRadius;
spawnRect.p0.y = prevRect.p0.y + featureRadius;
spawnRect.p1.x = prevRect.p1.x - featureRadius;
spawnRect.p1.y = prevRect.p1.y - featureRadius;
double spawnWidth = spawnRect.getWidth();
double spawnHeight = spawnRect.getHeight();
// try spawning features at evenly spaced points inside the grid
tracker.setImage(previousImage,previousDerivX,previousDerivY);
for( int i = 0; i < gridWidth; i++ ) {
float y = (float)(spawnRect.p0.y + i*spawnHeight/(gridWidth-1));
for( int j = 0; j < gridWidth; j++ ) {
float x = (float)(spawnRect.p0.x + j*spawnWidth/(gridWidth-1));
Track t = tracks[i*gridWidth+j];
t.klt.x = x;
t.klt.y = y;
if( tracker.setDescription(t.klt) ) {
t.active = true;
} else {
t.active = false;
}
}
}
} | [
"protected",
"void",
"spawnGrid",
"(",
"Rectangle2D_F64",
"prevRect",
")",
"{",
"// Shrink the rectangle to ensure that all features are entirely contained inside",
"spawnRect",
".",
"p0",
".",
"x",
"=",
"prevRect",
".",
"p0",
".",
"x",
"+",
"featureRadius",
";",
"spawn... | Spawn KLT tracks at evenly spaced points inside a grid | [
"Spawn",
"KLT",
"tracks",
"at",
"evenly",
"spaced",
"points",
"inside",
"a",
"grid"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldRegionTracker.java#L290-L321 | train |
lessthanoptimal/BoofCV | main/boofcv-sfm/src/main/java/boofcv/alg/sfm/d3/VisOdomQuadPnP.java | VisOdomQuadPnP.process | public boolean process( T left , T right ) {
if( first ) {
associateL2R(left, right);
first = false;
} else {
// long time0 = System.currentTimeMillis();
associateL2R(left, right);
// long time1 = System.currentTimeMillis();
associateF2F();
// long time2 = System.currentTimeMillis();
cyclicConsistency();
// long time3 = System.currentTimeMillis();
if( !estimateMotion() )
return false;
// long time4 = System.currentTimeMillis();
// System.out.println("timing: "+(time1-time0)+" "+(time2-time1)+" "+(time3-time2)+" "+(time4-time3));
}
return true;
} | java | public boolean process( T left , T right ) {
if( first ) {
associateL2R(left, right);
first = false;
} else {
// long time0 = System.currentTimeMillis();
associateL2R(left, right);
// long time1 = System.currentTimeMillis();
associateF2F();
// long time2 = System.currentTimeMillis();
cyclicConsistency();
// long time3 = System.currentTimeMillis();
if( !estimateMotion() )
return false;
// long time4 = System.currentTimeMillis();
// System.out.println("timing: "+(time1-time0)+" "+(time2-time1)+" "+(time3-time2)+" "+(time4-time3));
}
return true;
} | [
"public",
"boolean",
"process",
"(",
"T",
"left",
",",
"T",
"right",
")",
"{",
"if",
"(",
"first",
")",
"{",
"associateL2R",
"(",
"left",
",",
"right",
")",
";",
"first",
"=",
"false",
";",
"}",
"else",
"{",
"//\t\t\tlong time0 = System.currentTimeMillis()... | Estimates camera egomotion from the stereo pair
@param left Image from left camera
@param right Image from right camera
@return true if motion was estimated and false if not | [
"Estimates",
"camera",
"egomotion",
"from",
"the",
"stereo",
"pair"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-sfm/src/main/java/boofcv/alg/sfm/d3/VisOdomQuadPnP.java#L173-L195 | train |
lessthanoptimal/BoofCV | main/boofcv-sfm/src/main/java/boofcv/alg/sfm/d3/VisOdomQuadPnP.java | VisOdomQuadPnP.associateL2R | private void associateL2R( T left , T right ) {
// make the previous new observations into the new old ones
ImageInfo<TD> tmp = featsLeft1;
featsLeft1 = featsLeft0; featsLeft0 = tmp;
tmp = featsRight1;
featsRight1 = featsRight0; featsRight0 = tmp;
// detect and associate features in the two images
featsLeft1.reset();
featsRight1.reset();
// long time0 = System.currentTimeMillis();
describeImage(left,featsLeft1);
describeImage(right,featsRight1);
// long time1 = System.currentTimeMillis();
// detect and associate features in the current stereo pair
for( int i = 0; i < detector.getNumberOfSets(); i++ ) {
SetMatches matches = setMatches[i];
matches.swap();
matches.match2to3.reset();
FastQueue<Point2D_F64> leftLoc = featsLeft1.location[i];
FastQueue<Point2D_F64> rightLoc = featsRight1.location[i];
assocL2R.setSource(leftLoc,featsLeft1.description[i]);
assocL2R.setDestination(rightLoc, featsRight1.description[i]);
assocL2R.associate();
FastQueue<AssociatedIndex> found = assocL2R.getMatches();
// removeUnassociated(leftLoc,featsLeft1.description[i],rightLoc,featsRight1.description[i],found);
setMatches(matches.match2to3, found, leftLoc.size);
}
// long time2 = System.currentTimeMillis();
// System.out.println(" desc "+(time1-time0)+" assoc "+(time2-time1));
} | java | private void associateL2R( T left , T right ) {
// make the previous new observations into the new old ones
ImageInfo<TD> tmp = featsLeft1;
featsLeft1 = featsLeft0; featsLeft0 = tmp;
tmp = featsRight1;
featsRight1 = featsRight0; featsRight0 = tmp;
// detect and associate features in the two images
featsLeft1.reset();
featsRight1.reset();
// long time0 = System.currentTimeMillis();
describeImage(left,featsLeft1);
describeImage(right,featsRight1);
// long time1 = System.currentTimeMillis();
// detect and associate features in the current stereo pair
for( int i = 0; i < detector.getNumberOfSets(); i++ ) {
SetMatches matches = setMatches[i];
matches.swap();
matches.match2to3.reset();
FastQueue<Point2D_F64> leftLoc = featsLeft1.location[i];
FastQueue<Point2D_F64> rightLoc = featsRight1.location[i];
assocL2R.setSource(leftLoc,featsLeft1.description[i]);
assocL2R.setDestination(rightLoc, featsRight1.description[i]);
assocL2R.associate();
FastQueue<AssociatedIndex> found = assocL2R.getMatches();
// removeUnassociated(leftLoc,featsLeft1.description[i],rightLoc,featsRight1.description[i],found);
setMatches(matches.match2to3, found, leftLoc.size);
}
// long time2 = System.currentTimeMillis();
// System.out.println(" desc "+(time1-time0)+" assoc "+(time2-time1));
} | [
"private",
"void",
"associateL2R",
"(",
"T",
"left",
",",
"T",
"right",
")",
"{",
"// make the previous new observations into the new old ones",
"ImageInfo",
"<",
"TD",
">",
"tmp",
"=",
"featsLeft1",
";",
"featsLeft1",
"=",
"featsLeft0",
";",
"featsLeft0",
"=",
"t... | Associates image features from the left and right camera together while applying epipolar constraints.
@param left Image from left camera
@param right Image from right camera | [
"Associates",
"image",
"features",
"from",
"the",
"left",
"and",
"right",
"camera",
"together",
"while",
"applying",
"epipolar",
"constraints",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-sfm/src/main/java/boofcv/alg/sfm/d3/VisOdomQuadPnP.java#L203-L239 | train |
lessthanoptimal/BoofCV | main/boofcv-sfm/src/main/java/boofcv/alg/sfm/d3/VisOdomQuadPnP.java | VisOdomQuadPnP.associateF2F | private void associateF2F()
{
quadViews.reset();
for( int i = 0; i < detector.getNumberOfSets(); i++ ) {
SetMatches matches = setMatches[i];
// old left to new left
assocSame.setSource(featsLeft0.location[i],featsLeft0.description[i]);
assocSame.setDestination(featsLeft1.location[i], featsLeft1.description[i]);
assocSame.associate();
setMatches(matches.match0to2, assocSame.getMatches(), featsLeft0.location[i].size);
// old right to new right
assocSame.setSource(featsRight0.location[i],featsRight0.description[i]);
assocSame.setDestination(featsRight1.location[i], featsRight1.description[i]);
assocSame.associate();
setMatches(matches.match1to3, assocSame.getMatches(), featsRight0.location[i].size);
}
} | java | private void associateF2F()
{
quadViews.reset();
for( int i = 0; i < detector.getNumberOfSets(); i++ ) {
SetMatches matches = setMatches[i];
// old left to new left
assocSame.setSource(featsLeft0.location[i],featsLeft0.description[i]);
assocSame.setDestination(featsLeft1.location[i], featsLeft1.description[i]);
assocSame.associate();
setMatches(matches.match0to2, assocSame.getMatches(), featsLeft0.location[i].size);
// old right to new right
assocSame.setSource(featsRight0.location[i],featsRight0.description[i]);
assocSame.setDestination(featsRight1.location[i], featsRight1.description[i]);
assocSame.associate();
setMatches(matches.match1to3, assocSame.getMatches(), featsRight0.location[i].size);
}
} | [
"private",
"void",
"associateF2F",
"(",
")",
"{",
"quadViews",
".",
"reset",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"detector",
".",
"getNumberOfSets",
"(",
")",
";",
"i",
"++",
")",
"{",
"SetMatches",
"matches",
"=",
"setM... | Associates images between left and left and right and right images | [
"Associates",
"images",
"between",
"left",
"and",
"left",
"and",
"right",
"and",
"right",
"images"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-sfm/src/main/java/boofcv/alg/sfm/d3/VisOdomQuadPnP.java#L300-L321 | train |
lessthanoptimal/BoofCV | main/boofcv-sfm/src/main/java/boofcv/alg/sfm/d3/VisOdomQuadPnP.java | VisOdomQuadPnP.cyclicConsistency | private void cyclicConsistency() {
for( int i = 0; i < detector.getNumberOfSets(); i++ ) {
FastQueue<Point2D_F64> obs0 = featsLeft0.location[i];
FastQueue<Point2D_F64> obs1 = featsRight0.location[i];
FastQueue<Point2D_F64> obs2 = featsLeft1.location[i];
FastQueue<Point2D_F64> obs3 = featsRight1.location[i];
SetMatches matches = setMatches[i];
if( matches.match0to1.size != matches.match0to2.size )
throw new RuntimeException("Failed sanity check");
for( int j = 0; j < matches.match0to1.size; j++ ) {
int indexIn1 = matches.match0to1.data[j];
int indexIn2 = matches.match0to2.data[j];
if( indexIn1 < 0 || indexIn2 < 0 )
continue;
int indexIn3a = matches.match1to3.data[indexIn1];
int indexIn3b = matches.match2to3.data[indexIn2];
if( indexIn3a < 0 || indexIn3b < 0 )
continue;
// consistent association to new right camera image
if( indexIn3a == indexIn3b ) {
QuadView v = quadViews.grow();
v.v0 = obs0.get(j);
v.v1 = obs1.get(indexIn1);
v.v2 = obs2.get(indexIn2);
v.v3 = obs3.get(indexIn3a);
}
}
}
} | java | private void cyclicConsistency() {
for( int i = 0; i < detector.getNumberOfSets(); i++ ) {
FastQueue<Point2D_F64> obs0 = featsLeft0.location[i];
FastQueue<Point2D_F64> obs1 = featsRight0.location[i];
FastQueue<Point2D_F64> obs2 = featsLeft1.location[i];
FastQueue<Point2D_F64> obs3 = featsRight1.location[i];
SetMatches matches = setMatches[i];
if( matches.match0to1.size != matches.match0to2.size )
throw new RuntimeException("Failed sanity check");
for( int j = 0; j < matches.match0to1.size; j++ ) {
int indexIn1 = matches.match0to1.data[j];
int indexIn2 = matches.match0to2.data[j];
if( indexIn1 < 0 || indexIn2 < 0 )
continue;
int indexIn3a = matches.match1to3.data[indexIn1];
int indexIn3b = matches.match2to3.data[indexIn2];
if( indexIn3a < 0 || indexIn3b < 0 )
continue;
// consistent association to new right camera image
if( indexIn3a == indexIn3b ) {
QuadView v = quadViews.grow();
v.v0 = obs0.get(j);
v.v1 = obs1.get(indexIn1);
v.v2 = obs2.get(indexIn2);
v.v3 = obs3.get(indexIn3a);
}
}
}
} | [
"private",
"void",
"cyclicConsistency",
"(",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"detector",
".",
"getNumberOfSets",
"(",
")",
";",
"i",
"++",
")",
"{",
"FastQueue",
"<",
"Point2D_F64",
">",
"obs0",
"=",
"featsLeft0",
".",
"loc... | Create a list of features which have a consistent cycle of matches
0 -> 1 -> 3 and 0 -> 2 -> 3 | [
"Create",
"a",
"list",
"of",
"features",
"which",
"have",
"a",
"consistent",
"cycle",
"of",
"matches",
"0",
"-",
">",
"1",
"-",
">",
"3",
"and",
"0",
"-",
">",
"2",
"-",
">",
"3"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-sfm/src/main/java/boofcv/alg/sfm/d3/VisOdomQuadPnP.java#L327-L362 | train |
lessthanoptimal/BoofCV | main/boofcv-sfm/src/main/java/boofcv/alg/sfm/d3/VisOdomQuadPnP.java | VisOdomQuadPnP.describeImage | private void describeImage(T left , ImageInfo<TD> info ) {
detector.process(left);
for( int i = 0; i < detector.getNumberOfSets(); i++ ) {
PointDescSet<TD> set = detector.getFeatureSet(i);
FastQueue<Point2D_F64> l = info.location[i];
FastQueue<TD> d = info.description[i];
for( int j = 0; j < set.getNumberOfFeatures(); j++ ) {
l.grow().set( set.getLocation(j) );
d.grow().setTo( set.getDescription(j) );
}
}
} | java | private void describeImage(T left , ImageInfo<TD> info ) {
detector.process(left);
for( int i = 0; i < detector.getNumberOfSets(); i++ ) {
PointDescSet<TD> set = detector.getFeatureSet(i);
FastQueue<Point2D_F64> l = info.location[i];
FastQueue<TD> d = info.description[i];
for( int j = 0; j < set.getNumberOfFeatures(); j++ ) {
l.grow().set( set.getLocation(j) );
d.grow().setTo( set.getDescription(j) );
}
}
} | [
"private",
"void",
"describeImage",
"(",
"T",
"left",
",",
"ImageInfo",
"<",
"TD",
">",
"info",
")",
"{",
"detector",
".",
"process",
"(",
"left",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"detector",
".",
"getNumberOfSets",
"(",
"... | Computes image features and stores the results in info | [
"Computes",
"image",
"features",
"and",
"stores",
"the",
"results",
"in",
"info"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-sfm/src/main/java/boofcv/alg/sfm/d3/VisOdomQuadPnP.java#L380-L392 | train |
lessthanoptimal/BoofCV | main/boofcv-sfm/src/main/java/boofcv/alg/sfm/d3/VisOdomQuadPnP.java | VisOdomQuadPnP.estimateMotion | private boolean estimateMotion() {
modelFitData.reset();
Point2D_F64 normLeft = new Point2D_F64();
Point2D_F64 normRight = new Point2D_F64();
// use 0 -> 1 stereo associations to estimate each feature's 3D position
for( int i = 0; i < quadViews.size; i++ ) {
QuadView obs = quadViews.get(i);
// convert old stereo view to normalized coordinates
leftImageToNorm.compute(obs.v0.x,obs.v0.y,normLeft);
rightImageToNorm.compute(obs.v1.x,obs.v1.y,normRight);
// compute 3D location using triangulation
triangulate.triangulate(normLeft,normRight,leftToRight,obs.X);
// add to data set for fitting if not at infinity
if( !Double.isInfinite(obs.X.normSq()) ) {
Stereo2D3D data = modelFitData.grow();
leftImageToNorm.compute(obs.v2.x,obs.v2.y,data.leftObs);
rightImageToNorm.compute(obs.v3.x,obs.v3.y,data.rightObs);
data.location.set(obs.X);
}
}
// robustly match the data
if( !matcher.process(modelFitData.toList()) )
return false;
Se3_F64 oldToNew = matcher.getModelParameters();
// System.out.println("matcher rot = "+toString(oldToNew));
// optionally refine the results
if( modelRefiner != null ) {
Se3_F64 found = new Se3_F64();
if( modelRefiner.fitModel(matcher.getMatchSet(), oldToNew, found) ) {
// System.out.println("matcher rot = "+toString(found));
found.invert(newToOld);
} else {
oldToNew.invert(newToOld);
// System.out.println("Fit failed!");
}
} else {
oldToNew.invert(newToOld);
}
// compound the just found motion with the previously found motion
Se3_F64 temp = new Se3_F64();
newToOld.concat(leftCamToWorld, temp);
leftCamToWorld.set(temp);
return true;
} | java | private boolean estimateMotion() {
modelFitData.reset();
Point2D_F64 normLeft = new Point2D_F64();
Point2D_F64 normRight = new Point2D_F64();
// use 0 -> 1 stereo associations to estimate each feature's 3D position
for( int i = 0; i < quadViews.size; i++ ) {
QuadView obs = quadViews.get(i);
// convert old stereo view to normalized coordinates
leftImageToNorm.compute(obs.v0.x,obs.v0.y,normLeft);
rightImageToNorm.compute(obs.v1.x,obs.v1.y,normRight);
// compute 3D location using triangulation
triangulate.triangulate(normLeft,normRight,leftToRight,obs.X);
// add to data set for fitting if not at infinity
if( !Double.isInfinite(obs.X.normSq()) ) {
Stereo2D3D data = modelFitData.grow();
leftImageToNorm.compute(obs.v2.x,obs.v2.y,data.leftObs);
rightImageToNorm.compute(obs.v3.x,obs.v3.y,data.rightObs);
data.location.set(obs.X);
}
}
// robustly match the data
if( !matcher.process(modelFitData.toList()) )
return false;
Se3_F64 oldToNew = matcher.getModelParameters();
// System.out.println("matcher rot = "+toString(oldToNew));
// optionally refine the results
if( modelRefiner != null ) {
Se3_F64 found = new Se3_F64();
if( modelRefiner.fitModel(matcher.getMatchSet(), oldToNew, found) ) {
// System.out.println("matcher rot = "+toString(found));
found.invert(newToOld);
} else {
oldToNew.invert(newToOld);
// System.out.println("Fit failed!");
}
} else {
oldToNew.invert(newToOld);
}
// compound the just found motion with the previously found motion
Se3_F64 temp = new Se3_F64();
newToOld.concat(leftCamToWorld, temp);
leftCamToWorld.set(temp);
return true;
} | [
"private",
"boolean",
"estimateMotion",
"(",
")",
"{",
"modelFitData",
".",
"reset",
"(",
")",
";",
"Point2D_F64",
"normLeft",
"=",
"new",
"Point2D_F64",
"(",
")",
";",
"Point2D_F64",
"normRight",
"=",
"new",
"Point2D_F64",
"(",
")",
";",
"// use 0 -> 1 stereo... | Estimates camera egomotion between the two most recent image frames
@return | [
"Estimates",
"camera",
"egomotion",
"between",
"the",
"two",
"most",
"recent",
"image",
"frames"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-sfm/src/main/java/boofcv/alg/sfm/d3/VisOdomQuadPnP.java#L398-L451 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/alg/distort/spherical/EquirectangularRotate_F64.java | EquirectangularRotate_F64.setEquirectangularShape | @Override
public void setEquirectangularShape( int width , int height ) {
super.setEquirectangularShape(width, height);
declareVectors(width, height);
// precompute vectors for each pixel
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
tools.equiToNormFV(x,y,vectors[y*width+x]);
}
}
} | java | @Override
public void setEquirectangularShape( int width , int height ) {
super.setEquirectangularShape(width, height);
declareVectors(width, height);
// precompute vectors for each pixel
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
tools.equiToNormFV(x,y,vectors[y*width+x]);
}
}
} | [
"@",
"Override",
"public",
"void",
"setEquirectangularShape",
"(",
"int",
"width",
",",
"int",
"height",
")",
"{",
"super",
".",
"setEquirectangularShape",
"(",
"width",
",",
"height",
")",
";",
"declareVectors",
"(",
"width",
",",
"height",
")",
";",
"// pr... | Specifies the image's width and height
@param width Image width
@param height Image height | [
"Specifies",
"the",
"image",
"s",
"width",
"and",
"height"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/alg/distort/spherical/EquirectangularRotate_F64.java#L35-L46 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/factory/tracker/FactoryTrackerObjectQuad.java | FactoryTrackerObjectQuad.meanShiftLikelihood | public static <T extends ImageBase<T>>
TrackerObjectQuad<T> meanShiftLikelihood(int maxIterations,
int numBins,
double maxPixelValue,
MeanShiftLikelihoodType modelType,
ImageType<T> imageType) {
PixelLikelihood<T> likelihood;
switch( modelType ) {
case HISTOGRAM:
likelihood = FactoryTrackerObjectAlgs.likelihoodHistogramCoupled(maxPixelValue,numBins,imageType);
break;
case HISTOGRAM_INDEPENDENT_RGB_to_HSV:
if( imageType.getNumBands() != 3 )
throw new IllegalArgumentException("Expected RGB image as input with 3-bands");
likelihood = FactoryTrackerObjectAlgs.
likelihoodHueSatHistIndependent(maxPixelValue, numBins, (ImageType) imageType);
break;
case HISTOGRAM_RGB_to_HSV:
if( imageType.getNumBands() != 3 )
throw new IllegalArgumentException("Expected RGB image as input with 3-bands");
likelihood = FactoryTrackerObjectAlgs.likelihoodHueSatHistCoupled(maxPixelValue,numBins,(ImageType)imageType);
break;
default:
throw new IllegalArgumentException("Unknown likelihood model "+modelType);
}
TrackerMeanShiftLikelihood<T> alg =
new TrackerMeanShiftLikelihood<>(likelihood, maxIterations, 0.1f);
return new Msl_to_TrackerObjectQuad<>(alg, likelihood, imageType);
} | java | public static <T extends ImageBase<T>>
TrackerObjectQuad<T> meanShiftLikelihood(int maxIterations,
int numBins,
double maxPixelValue,
MeanShiftLikelihoodType modelType,
ImageType<T> imageType) {
PixelLikelihood<T> likelihood;
switch( modelType ) {
case HISTOGRAM:
likelihood = FactoryTrackerObjectAlgs.likelihoodHistogramCoupled(maxPixelValue,numBins,imageType);
break;
case HISTOGRAM_INDEPENDENT_RGB_to_HSV:
if( imageType.getNumBands() != 3 )
throw new IllegalArgumentException("Expected RGB image as input with 3-bands");
likelihood = FactoryTrackerObjectAlgs.
likelihoodHueSatHistIndependent(maxPixelValue, numBins, (ImageType) imageType);
break;
case HISTOGRAM_RGB_to_HSV:
if( imageType.getNumBands() != 3 )
throw new IllegalArgumentException("Expected RGB image as input with 3-bands");
likelihood = FactoryTrackerObjectAlgs.likelihoodHueSatHistCoupled(maxPixelValue,numBins,(ImageType)imageType);
break;
default:
throw new IllegalArgumentException("Unknown likelihood model "+modelType);
}
TrackerMeanShiftLikelihood<T> alg =
new TrackerMeanShiftLikelihood<>(likelihood, maxIterations, 0.1f);
return new Msl_to_TrackerObjectQuad<>(alg, likelihood, imageType);
} | [
"public",
"static",
"<",
"T",
"extends",
"ImageBase",
"<",
"T",
">",
">",
"TrackerObjectQuad",
"<",
"T",
">",
"meanShiftLikelihood",
"(",
"int",
"maxIterations",
",",
"int",
"numBins",
",",
"double",
"maxPixelValue",
",",
"MeanShiftLikelihoodType",
"modelType",
... | Very basic and very fast implementation of mean-shift which uses a fixed sized rectangle for its region.
Works best when the target is composed of a single color.
@see TrackerMeanShiftLikelihood
@param maxIterations Maximum number of mean-shift iterations. Try 30.
@param numBins Number of bins in the histogram color model. Try 5.
@param maxPixelValue Maximum number of pixel values. For 8-bit images this will be 256
@param modelType Type of color model used.
@param imageType Type of image
@return TrackerObjectQuad based on {@link TrackerMeanShiftLikelihood}. | [
"Very",
"basic",
"and",
"very",
"fast",
"implementation",
"of",
"mean",
"-",
"shift",
"which",
"uses",
"a",
"fixed",
"sized",
"rectangle",
"for",
"its",
"region",
".",
"Works",
"best",
"when",
"the",
"target",
"is",
"composed",
"of",
"a",
"single",
"color"... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/factory/tracker/FactoryTrackerObjectQuad.java#L108-L142 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/factory/tracker/FactoryTrackerObjectQuad.java | FactoryTrackerObjectQuad.meanShiftComaniciu2003 | public static <T extends ImageBase<T>>
TrackerObjectQuad<T> meanShiftComaniciu2003(ConfigComaniciu2003 config, ImageType<T> imageType ) {
TrackerMeanShiftComaniciu2003<T> alg = FactoryTrackerObjectAlgs.meanShiftComaniciu2003(config,imageType);
return new Comaniciu2003_to_TrackerObjectQuad<>(alg, imageType);
} | java | public static <T extends ImageBase<T>>
TrackerObjectQuad<T> meanShiftComaniciu2003(ConfigComaniciu2003 config, ImageType<T> imageType ) {
TrackerMeanShiftComaniciu2003<T> alg = FactoryTrackerObjectAlgs.meanShiftComaniciu2003(config,imageType);
return new Comaniciu2003_to_TrackerObjectQuad<>(alg, imageType);
} | [
"public",
"static",
"<",
"T",
"extends",
"ImageBase",
"<",
"T",
">",
">",
"TrackerObjectQuad",
"<",
"T",
">",
"meanShiftComaniciu2003",
"(",
"ConfigComaniciu2003",
"config",
",",
"ImageType",
"<",
"T",
">",
"imageType",
")",
"{",
"TrackerMeanShiftComaniciu2003",
... | Implementation of mean-shift which matches the histogram and can handle targets composed of multiple colors.
The tracker can also be configured to estimate gradual changes in scale. The track region is
composed of a rotated rectangle.
@see TrackerMeanShiftComaniciu2003
@param config Tracker configuration
@param <T> Image type
@return TrackerObjectQuad based on Comaniciu2003 | [
"Implementation",
"of",
"mean",
"-",
"shift",
"which",
"matches",
"the",
"histogram",
"and",
"can",
"handle",
"targets",
"composed",
"of",
"multiple",
"colors",
".",
"The",
"tracker",
"can",
"also",
"be",
"configured",
"to",
"estimate",
"gradual",
"changes",
"... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/factory/tracker/FactoryTrackerObjectQuad.java#L155-L161 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/background/BackgroundModelStationary.java | BackgroundModelStationary.updateBackground | public void updateBackground( T frame , GrayU8 segment ) {
updateBackground(frame);
segment(frame,segment);
} | java | public void updateBackground( T frame , GrayU8 segment ) {
updateBackground(frame);
segment(frame,segment);
} | [
"public",
"void",
"updateBackground",
"(",
"T",
"frame",
",",
"GrayU8",
"segment",
")",
"{",
"updateBackground",
"(",
"frame",
")",
";",
"segment",
"(",
"frame",
",",
"segment",
")",
";",
"}"
] | Updates the background and segments it at the same time. In some implementations this can be
significantly faster than doing it with separate function calls. Segmentation is performed using the model
which it has prior to the update. | [
"Updates",
"the",
"background",
"and",
"segments",
"it",
"at",
"the",
"same",
"time",
".",
"In",
"some",
"implementations",
"this",
"can",
"be",
"significantly",
"faster",
"than",
"doing",
"it",
"with",
"separate",
"function",
"calls",
".",
"Segmentation",
"is... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/background/BackgroundModelStationary.java#L48-L51 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/PackedBits8.java | PackedBits8.append | public void append( int bits , int numberOfBits , boolean swapOrder ) {
if( numberOfBits > 32 )
throw new IllegalArgumentException("Number of bits exceeds the size of bits");
int indexTail = size;
growArray(numberOfBits,true);
if( swapOrder ) {
for (int i = 0; i < numberOfBits; i++) {
set( indexTail + i , ( bits >> i ) & 1 );
}
} else {
for (int i = 0; i < numberOfBits; i++) {
set( indexTail + numberOfBits-i-1 , ( bits >> i ) & 1 );
}
}
} | java | public void append( int bits , int numberOfBits , boolean swapOrder ) {
if( numberOfBits > 32 )
throw new IllegalArgumentException("Number of bits exceeds the size of bits");
int indexTail = size;
growArray(numberOfBits,true);
if( swapOrder ) {
for (int i = 0; i < numberOfBits; i++) {
set( indexTail + i , ( bits >> i ) & 1 );
}
} else {
for (int i = 0; i < numberOfBits; i++) {
set( indexTail + numberOfBits-i-1 , ( bits >> i ) & 1 );
}
}
} | [
"public",
"void",
"append",
"(",
"int",
"bits",
",",
"int",
"numberOfBits",
",",
"boolean",
"swapOrder",
")",
"{",
"if",
"(",
"numberOfBits",
">",
"32",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Number of bits exceeds the size of bits\"",
")",
";",
... | Appends bits on to the end of the stack.
@param bits Storage for bits. Relevant bits start at the front.
@param numberOfBits Number of relevant bits in 'bits'
@param swapOrder If true then the first bit in 'bits' will be the last bit in this array. | [
"Appends",
"bits",
"on",
"to",
"the",
"end",
"of",
"the",
"stack",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/PackedBits8.java#L72-L87 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/PackedBits8.java | PackedBits8.read | public int read( int location , int length , boolean swapOrder ) {
if( length < 0 || length > 32 )
throw new IllegalArgumentException("Length can't exceed 32");
if( location + length > size )
throw new IllegalArgumentException("Attempting to read past the end");
// TODO speed up by reading in byte chunks
int output = 0;
if( swapOrder ) {
for (int i = 0; i < length; i++) {
output |= get(location+i) << (length-i-1);
}
} else {
for (int i = 0; i < length; i++) {
output |= get(location+i) << i;
}
}
return output;
} | java | public int read( int location , int length , boolean swapOrder ) {
if( length < 0 || length > 32 )
throw new IllegalArgumentException("Length can't exceed 32");
if( location + length > size )
throw new IllegalArgumentException("Attempting to read past the end");
// TODO speed up by reading in byte chunks
int output = 0;
if( swapOrder ) {
for (int i = 0; i < length; i++) {
output |= get(location+i) << (length-i-1);
}
} else {
for (int i = 0; i < length; i++) {
output |= get(location+i) << i;
}
}
return output;
} | [
"public",
"int",
"read",
"(",
"int",
"location",
",",
"int",
"length",
",",
"boolean",
"swapOrder",
")",
"{",
"if",
"(",
"length",
"<",
"0",
"||",
"length",
">",
"32",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Length can't exceed 32\"",
")",
... | Read bits from the array and store them in an int
@param location The index of the first bit
@param length Number of bits to real up to 32
@param swapOrder Should the order be swapped?
@return The read in data | [
"Read",
"bits",
"from",
"the",
"array",
"and",
"store",
"them",
"in",
"an",
"int"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/PackedBits8.java#L96-L114 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/PackedBits8.java | PackedBits8.growArray | public void growArray( int amountBits , boolean saveValue ) {
size = size+amountBits;
int N = size/8 + (size%8==0?0:1);
if( N > data.length ) {
// add in some buffer to avoid lots of calls to new
int extra = Math.min(1024,N+10);
byte[] tmp = new byte[N+extra];
if( saveValue )
System.arraycopy(data,0,tmp,0,data.length);
this.data = tmp;
}
} | java | public void growArray( int amountBits , boolean saveValue ) {
size = size+amountBits;
int N = size/8 + (size%8==0?0:1);
if( N > data.length ) {
// add in some buffer to avoid lots of calls to new
int extra = Math.min(1024,N+10);
byte[] tmp = new byte[N+extra];
if( saveValue )
System.arraycopy(data,0,tmp,0,data.length);
this.data = tmp;
}
} | [
"public",
"void",
"growArray",
"(",
"int",
"amountBits",
",",
"boolean",
"saveValue",
")",
"{",
"size",
"=",
"size",
"+",
"amountBits",
";",
"int",
"N",
"=",
"size",
"/",
"8",
"+",
"(",
"size",
"%",
"8",
"==",
"0",
"?",
"0",
":",
"1",
")",
";",
... | Increases the size of the data array so that it can store an addition number of bits
@param amountBits Number of bits beyond 'size' that you wish the array to be able to store
@param saveValue if true it will save the value of the array. If false it will not copy it | [
"Increases",
"the",
"size",
"of",
"the",
"data",
"array",
"so",
"that",
"it",
"can",
"store",
"an",
"addition",
"number",
"of",
"bits"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/PackedBits8.java#L133-L146 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/alg/geo/h/HomographyDirectLinearTransform.java | HomographyDirectLinearTransform.computeH | protected boolean computeH(DMatrixRMaj A, DMatrixRMaj H) {
if( !solverNullspace.process(A.copy(),1,H) )
return true;
H.numRows = 3;
H.numCols = 3;
return false;
} | java | protected boolean computeH(DMatrixRMaj A, DMatrixRMaj H) {
if( !solverNullspace.process(A.copy(),1,H) )
return true;
H.numRows = 3;
H.numCols = 3;
return false;
} | [
"protected",
"boolean",
"computeH",
"(",
"DMatrixRMaj",
"A",
",",
"DMatrixRMaj",
"H",
")",
"{",
"if",
"(",
"!",
"solverNullspace",
".",
"process",
"(",
"A",
".",
"copy",
"(",
")",
",",
"1",
",",
"H",
")",
")",
"return",
"true",
";",
"H",
".",
"numR... | Computes the SVD of A and extracts the homography matrix from its null space | [
"Computes",
"the",
"SVD",
"of",
"A",
"and",
"extracts",
"the",
"homography",
"matrix",
"from",
"its",
"null",
"space"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/alg/geo/h/HomographyDirectLinearTransform.java#L189-L198 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/alg/geo/h/HomographyDirectLinearTransform.java | HomographyDirectLinearTransform.undoNormalizationH | public static void undoNormalizationH(DMatrixRMaj M, NormalizationPoint2D N1, NormalizationPoint2D N2) {
SimpleMatrix a = SimpleMatrix.wrap(M);
SimpleMatrix b = SimpleMatrix.wrap(N1.matrix());
SimpleMatrix c_inv = SimpleMatrix.wrap(N2.matrixInv());
SimpleMatrix result = c_inv.mult(a).mult(b);
M.set(result.getDDRM());
} | java | public static void undoNormalizationH(DMatrixRMaj M, NormalizationPoint2D N1, NormalizationPoint2D N2) {
SimpleMatrix a = SimpleMatrix.wrap(M);
SimpleMatrix b = SimpleMatrix.wrap(N1.matrix());
SimpleMatrix c_inv = SimpleMatrix.wrap(N2.matrixInv());
SimpleMatrix result = c_inv.mult(a).mult(b);
M.set(result.getDDRM());
} | [
"public",
"static",
"void",
"undoNormalizationH",
"(",
"DMatrixRMaj",
"M",
",",
"NormalizationPoint2D",
"N1",
",",
"NormalizationPoint2D",
"N2",
")",
"{",
"SimpleMatrix",
"a",
"=",
"SimpleMatrix",
".",
"wrap",
"(",
"M",
")",
";",
"SimpleMatrix",
"b",
"=",
"Sim... | Undoes normalization for a homography matrix. | [
"Undoes",
"normalization",
"for",
"a",
"homography",
"matrix",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/alg/geo/h/HomographyDirectLinearTransform.java#L203-L211 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/alg/geo/h/HomographyDirectLinearTransform.java | HomographyDirectLinearTransform.addConicPairConstraints | protected int addConicPairConstraints( AssociatedPairConic a , AssociatedPairConic b , DMatrixRMaj A , int rowA ) {
// s*C[i] = H^T*V[i]*H
// C[i] = a, C[j] = b
// Conic in view 1 is C and view 2 is V, e.g. x' = H*x. x' is in view 2 and x in view 1
UtilCurves_F64.convert(a.p1, C1);
UtilCurves_F64.convert(a.p2, V1);
CommonOps_DDF3.invert(C1, C1_inv);
CommonOps_DDF3.invert(V1, V1_inv);
UtilCurves_F64.convert(b.p1, C2);
UtilCurves_F64.convert(b.p2, V2);
CommonOps_DDF3.invert(C2, C2_inv);
CommonOps_DDF3.invert(V2, V2_inv);
// L = inv(V[i])*V[j]
CommonOps_DDF3.mult(V1_inv, V2,L);
// R = C[i]*inv(C[j])
CommonOps_DDF3.mult(C1_inv, C2,R);
// clear this row
int idxA = rowA*9;
// Arrays.fill(A.data,idxA,9*9,0); <-- has already been zeroed
// NOTE: adding all 9 rows is redundant. The source paper doesn't attempt to reduce the number of rows
// maybe this can be made to run faster if the rows can be intelligently pruned
// inv(V[i])*V[j]*H - H*C[i]*inv(C[j]) == 0
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
for (int i = 0; i < 3; i++) {
A.data[idxA + 3*i + col] += L.get(row,i);
A.data[idxA + 3*row + i] -= R.get(i,col);
}
idxA += 9;
}
}
return rowA+9;
} | java | protected int addConicPairConstraints( AssociatedPairConic a , AssociatedPairConic b , DMatrixRMaj A , int rowA ) {
// s*C[i] = H^T*V[i]*H
// C[i] = a, C[j] = b
// Conic in view 1 is C and view 2 is V, e.g. x' = H*x. x' is in view 2 and x in view 1
UtilCurves_F64.convert(a.p1, C1);
UtilCurves_F64.convert(a.p2, V1);
CommonOps_DDF3.invert(C1, C1_inv);
CommonOps_DDF3.invert(V1, V1_inv);
UtilCurves_F64.convert(b.p1, C2);
UtilCurves_F64.convert(b.p2, V2);
CommonOps_DDF3.invert(C2, C2_inv);
CommonOps_DDF3.invert(V2, V2_inv);
// L = inv(V[i])*V[j]
CommonOps_DDF3.mult(V1_inv, V2,L);
// R = C[i]*inv(C[j])
CommonOps_DDF3.mult(C1_inv, C2,R);
// clear this row
int idxA = rowA*9;
// Arrays.fill(A.data,idxA,9*9,0); <-- has already been zeroed
// NOTE: adding all 9 rows is redundant. The source paper doesn't attempt to reduce the number of rows
// maybe this can be made to run faster if the rows can be intelligently pruned
// inv(V[i])*V[j]*H - H*C[i]*inv(C[j]) == 0
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
for (int i = 0; i < 3; i++) {
A.data[idxA + 3*i + col] += L.get(row,i);
A.data[idxA + 3*row + i] -= R.get(i,col);
}
idxA += 9;
}
}
return rowA+9;
} | [
"protected",
"int",
"addConicPairConstraints",
"(",
"AssociatedPairConic",
"a",
",",
"AssociatedPairConic",
"b",
",",
"DMatrixRMaj",
"A",
",",
"int",
"rowA",
")",
"{",
"// s*C[i] = H^T*V[i]*H",
"// C[i] = a, C[j] = b",
"// Conic in view 1 is C and view 2 is V, e.g. x' = H*x. x... | Add constraint for a pair of conics | [
"Add",
"constraint",
"for",
"a",
"pair",
"of",
"conics"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/alg/geo/h/HomographyDirectLinearTransform.java#L334-L371 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java | SegmentSlic.initalize | protected void initalize(T input) {
this.input = input;
pixels.resize(input.width * input.height);
initialSegments.reshape(input.width, input.height);
// number of usable pixels that cluster centers can be placed in
int numberOfUsable = (input.width-2*BORDER)*(input.height-2*BORDER);
gridInterval = (int)Math.sqrt( numberOfUsable/(double)numberOfRegions);
if( gridInterval <= 0 )
throw new IllegalArgumentException("Too many regions for an image of this size");
// See equation (1)
adjustSpacial = m/gridInterval;
} | java | protected void initalize(T input) {
this.input = input;
pixels.resize(input.width * input.height);
initialSegments.reshape(input.width, input.height);
// number of usable pixels that cluster centers can be placed in
int numberOfUsable = (input.width-2*BORDER)*(input.height-2*BORDER);
gridInterval = (int)Math.sqrt( numberOfUsable/(double)numberOfRegions);
if( gridInterval <= 0 )
throw new IllegalArgumentException("Too many regions for an image of this size");
// See equation (1)
adjustSpacial = m/gridInterval;
} | [
"protected",
"void",
"initalize",
"(",
"T",
"input",
")",
"{",
"this",
".",
"input",
"=",
"input",
";",
"pixels",
".",
"resize",
"(",
"input",
".",
"width",
"*",
"input",
".",
"height",
")",
";",
"initialSegments",
".",
"reshape",
"(",
"input",
".",
... | prepares all data structures | [
"prepares",
"all",
"data",
"structures"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java#L177-L191 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java | SegmentSlic.initializeClusters | protected void initializeClusters() {
int offsetX = Math.max(BORDER,((input.width-1) % gridInterval)/2);
int offsetY = Math.max(BORDER,((input.height-1) % gridInterval)/2);
int clusterId = 0;
clusters.reset();
for( int y = offsetY; y < input.height-BORDER; y += gridInterval ) {
for( int x = offsetX; x < input.width-BORDER; x += gridInterval ) {
Cluster c = clusters.grow();
c.id = clusterId++;
if( c.color == null)
c.color = new float[numBands];
// sets the location and color at the local minimal gradient point
perturbCenter( c , x , y );
}
}
} | java | protected void initializeClusters() {
int offsetX = Math.max(BORDER,((input.width-1) % gridInterval)/2);
int offsetY = Math.max(BORDER,((input.height-1) % gridInterval)/2);
int clusterId = 0;
clusters.reset();
for( int y = offsetY; y < input.height-BORDER; y += gridInterval ) {
for( int x = offsetX; x < input.width-BORDER; x += gridInterval ) {
Cluster c = clusters.grow();
c.id = clusterId++;
if( c.color == null)
c.color = new float[numBands];
// sets the location and color at the local minimal gradient point
perturbCenter( c , x , y );
}
}
} | [
"protected",
"void",
"initializeClusters",
"(",
")",
"{",
"int",
"offsetX",
"=",
"Math",
".",
"max",
"(",
"BORDER",
",",
"(",
"(",
"input",
".",
"width",
"-",
"1",
")",
"%",
"gridInterval",
")",
"/",
"2",
")",
";",
"int",
"offsetY",
"=",
"Math",
".... | initialize all the clusters at regularly spaced intervals. Their locations are perturbed a bit to reduce
the likelihood of a bad location. Initial color is set to the image color at the location | [
"initialize",
"all",
"the",
"clusters",
"at",
"regularly",
"spaced",
"intervals",
".",
"Their",
"locations",
"are",
"perturbed",
"a",
"bit",
"to",
"reduce",
"the",
"likelihood",
"of",
"a",
"bad",
"location",
".",
"Initial",
"color",
"is",
"set",
"to",
"the",... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java#L197-L215 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java | SegmentSlic.perturbCenter | protected void perturbCenter( Cluster c , int x , int y ) {
float best = Float.MAX_VALUE;
int bestX=0,bestY=0;
for( int dy = -1; dy <= 1; dy++ ) {
for( int dx = -1; dx <= 1; dx++ ) {
float d = gradient(x + dx, y + dy);
if( d < best ) {
best = d;
bestX = dx;
bestY = dy;
}
}
}
c.x = x+bestX;
c.y = y+bestY;
setColor(c.color,x+bestX,y+bestY);
} | java | protected void perturbCenter( Cluster c , int x , int y ) {
float best = Float.MAX_VALUE;
int bestX=0,bestY=0;
for( int dy = -1; dy <= 1; dy++ ) {
for( int dx = -1; dx <= 1; dx++ ) {
float d = gradient(x + dx, y + dy);
if( d < best ) {
best = d;
bestX = dx;
bestY = dy;
}
}
}
c.x = x+bestX;
c.y = y+bestY;
setColor(c.color,x+bestX,y+bestY);
} | [
"protected",
"void",
"perturbCenter",
"(",
"Cluster",
"c",
",",
"int",
"x",
",",
"int",
"y",
")",
"{",
"float",
"best",
"=",
"Float",
".",
"MAX_VALUE",
";",
"int",
"bestX",
"=",
"0",
",",
"bestY",
"=",
"0",
";",
"for",
"(",
"int",
"dy",
"=",
"-",... | Set the cluster's center to be the pixel in a 3x3 neighborhood with the smallest gradient | [
"Set",
"the",
"cluster",
"s",
"center",
"to",
"be",
"the",
"pixel",
"in",
"a",
"3x3",
"neighborhood",
"with",
"the",
"smallest",
"gradient"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java#L220-L238 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java | SegmentSlic.gradient | protected float gradient(int x, int y) {
float dx = getIntensity(x+1,y) - getIntensity(x-1,y);
float dy = getIntensity(x,y+1) - getIntensity(x,y-1);
return dx*dx + dy*dy;
} | java | protected float gradient(int x, int y) {
float dx = getIntensity(x+1,y) - getIntensity(x-1,y);
float dy = getIntensity(x,y+1) - getIntensity(x,y-1);
return dx*dx + dy*dy;
} | [
"protected",
"float",
"gradient",
"(",
"int",
"x",
",",
"int",
"y",
")",
"{",
"float",
"dx",
"=",
"getIntensity",
"(",
"x",
"+",
"1",
",",
"y",
")",
"-",
"getIntensity",
"(",
"x",
"-",
"1",
",",
"y",
")",
";",
"float",
"dy",
"=",
"getIntensity",
... | Computes the gradient at the specified pixel | [
"Computes",
"the",
"gradient",
"at",
"the",
"specified",
"pixel"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java#L243-L248 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java | SegmentSlic.computeClusterDistance | protected void computeClusterDistance() {
for( int i = 0; i < pixels.size; i++ ) {
pixels.data[i].reset();
}
for( int i = 0; i < clusters.size && !stopRequested; i++ ) {
Cluster c = clusters.data[i];
// compute search bounds
int centerX = (int)(c.x + 0.5f);
int centerY = (int)(c.y + 0.5f);
int x0 = centerX - gridInterval; int x1 = centerX + gridInterval + 1;
int y0 = centerY - gridInterval; int y1 = centerY + gridInterval + 1;
if( x0 < 0 ) x0 = 0;
if( y0 < 0 ) y0 = 0;
if( x1 > input.width ) x1 = input.width;
if( y1 > input.height ) y1 = input.height;
for( int y = y0; y < y1; y++ ) {
int indexPixel = y*input.width + x0;
int indexInput = input.startIndex + y*input.stride + x0;
int dy = y-centerY;
for( int x = x0; x < x1; x++ ) {
int dx = x-centerX;
float distanceColor = colorDistance(c.color,indexInput++);
float distanceSpacial = dx*dx + dy*dy;
pixels.data[indexPixel++].add(c,distanceColor + adjustSpacial*distanceSpacial);
}
}
}
} | java | protected void computeClusterDistance() {
for( int i = 0; i < pixels.size; i++ ) {
pixels.data[i].reset();
}
for( int i = 0; i < clusters.size && !stopRequested; i++ ) {
Cluster c = clusters.data[i];
// compute search bounds
int centerX = (int)(c.x + 0.5f);
int centerY = (int)(c.y + 0.5f);
int x0 = centerX - gridInterval; int x1 = centerX + gridInterval + 1;
int y0 = centerY - gridInterval; int y1 = centerY + gridInterval + 1;
if( x0 < 0 ) x0 = 0;
if( y0 < 0 ) y0 = 0;
if( x1 > input.width ) x1 = input.width;
if( y1 > input.height ) y1 = input.height;
for( int y = y0; y < y1; y++ ) {
int indexPixel = y*input.width + x0;
int indexInput = input.startIndex + y*input.stride + x0;
int dy = y-centerY;
for( int x = x0; x < x1; x++ ) {
int dx = x-centerX;
float distanceColor = colorDistance(c.color,indexInput++);
float distanceSpacial = dx*dx + dy*dy;
pixels.data[indexPixel++].add(c,distanceColor + adjustSpacial*distanceSpacial);
}
}
}
} | [
"protected",
"void",
"computeClusterDistance",
"(",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"pixels",
".",
"size",
";",
"i",
"++",
")",
"{",
"pixels",
".",
"data",
"[",
"i",
"]",
".",
"reset",
"(",
")",
";",
"}",
"for",
"(",
... | Computes how far away each cluster is from each pixel. Expectation step. | [
"Computes",
"how",
"far",
"away",
"each",
"cluster",
"is",
"from",
"each",
"pixel",
".",
"Expectation",
"step",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java#L273-L308 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java | SegmentSlic.updateClusters | protected void updateClusters() {
for( int i = 0; i < clusters.size; i++ ) {
clusters.data[i].reset();
}
int indexPixel = 0;
for( int y = 0; y < input.height&& !stopRequested; y++ ) {
int indexInput = input.startIndex + y*input.stride;
for( int x =0; x < input.width; x++ , indexPixel++ , indexInput++) {
Pixel p = pixels.get(indexPixel);
// convert the distance each cluster is from the pixel into weights
p.computeWeights();
for( int i = 0; i < p.clusters.size; i++ ) {
ClusterDistance d = p.clusters.data[i];
d.cluster.x += x*d.distance;
d.cluster.y += y*d.distance;
d.cluster.totalWeight += d.distance;
addColor(d.cluster.color,indexInput,d.distance);
}
}
}
// recompute the center of each cluster
for( int i = 0; i < clusters.size; i++ ) {
clusters.data[i].update();
}
} | java | protected void updateClusters() {
for( int i = 0; i < clusters.size; i++ ) {
clusters.data[i].reset();
}
int indexPixel = 0;
for( int y = 0; y < input.height&& !stopRequested; y++ ) {
int indexInput = input.startIndex + y*input.stride;
for( int x =0; x < input.width; x++ , indexPixel++ , indexInput++) {
Pixel p = pixels.get(indexPixel);
// convert the distance each cluster is from the pixel into weights
p.computeWeights();
for( int i = 0; i < p.clusters.size; i++ ) {
ClusterDistance d = p.clusters.data[i];
d.cluster.x += x*d.distance;
d.cluster.y += y*d.distance;
d.cluster.totalWeight += d.distance;
addColor(d.cluster.color,indexInput,d.distance);
}
}
}
// recompute the center of each cluster
for( int i = 0; i < clusters.size; i++ ) {
clusters.data[i].update();
}
} | [
"protected",
"void",
"updateClusters",
"(",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"clusters",
".",
"size",
";",
"i",
"++",
")",
"{",
"clusters",
".",
"data",
"[",
"i",
"]",
".",
"reset",
"(",
")",
";",
"}",
"int",
"indexPix... | Update the value of each cluster using Maximization step. | [
"Update",
"the",
"value",
"of",
"each",
"cluster",
"using",
"Maximization",
"step",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java#L313-L341 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java | SegmentSlic.assignLabelsToPixels | public void assignLabelsToPixels( GrayS32 pixelToRegions ,
GrowQueue_I32 regionMemberCount ,
FastQueue<float[]> regionColor ) {
regionColor.reset();
for( int i = 0; i < clusters.size(); i++ ) {
float[] r = regionColor.grow();
float[] c = clusters.get(i).color;
for( int j = 0; j < numBands; j++ ) {
r[j] = c[j];
}
}
regionMemberCount.resize(clusters.size());
regionMemberCount.fill(0);
int indexPixel = 0;
for( int y = 0; y < pixelToRegions.height; y++ ) {
int indexOutput = pixelToRegions.startIndex + y*pixelToRegions.stride;
for( int x =0; x < pixelToRegions.width; x++ , indexPixel++ , indexOutput++) {
Pixel p = pixels.data[indexPixel];
// It is possible for a pixel to be unassigned if all the means move too far away from it
// Default to a non-existant cluster if that's the case
int best = -1;
float bestDistance = Float.MAX_VALUE;
// find the region/cluster which it is closest to
for( int j = 0; j < p.clusters.size; j++ ) {
ClusterDistance d = p.clusters.data[j];
if( d.distance < bestDistance ) {
bestDistance = d.distance;
best = d.cluster.id;
}
}
if( best == -1 ) {
regionColor.grow();
best = regionMemberCount.size();
regionMemberCount.add(0);
}
pixelToRegions.data[indexOutput] = best;
regionMemberCount.data[best]++;
}
}
} | java | public void assignLabelsToPixels( GrayS32 pixelToRegions ,
GrowQueue_I32 regionMemberCount ,
FastQueue<float[]> regionColor ) {
regionColor.reset();
for( int i = 0; i < clusters.size(); i++ ) {
float[] r = regionColor.grow();
float[] c = clusters.get(i).color;
for( int j = 0; j < numBands; j++ ) {
r[j] = c[j];
}
}
regionMemberCount.resize(clusters.size());
regionMemberCount.fill(0);
int indexPixel = 0;
for( int y = 0; y < pixelToRegions.height; y++ ) {
int indexOutput = pixelToRegions.startIndex + y*pixelToRegions.stride;
for( int x =0; x < pixelToRegions.width; x++ , indexPixel++ , indexOutput++) {
Pixel p = pixels.data[indexPixel];
// It is possible for a pixel to be unassigned if all the means move too far away from it
// Default to a non-existant cluster if that's the case
int best = -1;
float bestDistance = Float.MAX_VALUE;
// find the region/cluster which it is closest to
for( int j = 0; j < p.clusters.size; j++ ) {
ClusterDistance d = p.clusters.data[j];
if( d.distance < bestDistance ) {
bestDistance = d.distance;
best = d.cluster.id;
}
}
if( best == -1 ) {
regionColor.grow();
best = regionMemberCount.size();
regionMemberCount.add(0);
}
pixelToRegions.data[indexOutput] = best;
regionMemberCount.data[best]++;
}
}
} | [
"public",
"void",
"assignLabelsToPixels",
"(",
"GrayS32",
"pixelToRegions",
",",
"GrowQueue_I32",
"regionMemberCount",
",",
"FastQueue",
"<",
"float",
"[",
"]",
">",
"regionColor",
")",
"{",
"regionColor",
".",
"reset",
"(",
")",
";",
"for",
"(",
"int",
"i",
... | Selects which region each pixel belongs to based on which cluster it is the closest to | [
"Selects",
"which",
"region",
"each",
"pixel",
"belongs",
"to",
"based",
"on",
"which",
"cluster",
"it",
"is",
"the",
"closest",
"to"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/slic/SegmentSlic.java#L346-L390 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/alg/geo/rectify/RectifyFundamental.java | RectifyFundamental.process | public void process( DMatrixRMaj F , List<AssociatedPair> observations ,
int width , int height ) {
int centerX = width/2;
int centerY = height/2;
MultiViewOps.extractEpipoles(F, epipole1, epipole2);
checkEpipoleInside(width, height);
// compute the transform H which will send epipole2 to infinity
SimpleMatrix R = rotateEpipole(epipole2,centerX,centerY);
SimpleMatrix T = translateToOrigin(centerX,centerY);
SimpleMatrix G = computeG(epipole2,centerX,centerY);
SimpleMatrix H = G.mult(R).mult(T);
//Find the two matching transforms
SimpleMatrix Hzero = computeHZero(F,epipole2,H);
SimpleMatrix Ha = computeAffineH(observations,H.getDDRM(),Hzero.getDDRM());
rect1.set(Ha.mult(Hzero).getDDRM());
rect2.set(H.getDDRM());
} | java | public void process( DMatrixRMaj F , List<AssociatedPair> observations ,
int width , int height ) {
int centerX = width/2;
int centerY = height/2;
MultiViewOps.extractEpipoles(F, epipole1, epipole2);
checkEpipoleInside(width, height);
// compute the transform H which will send epipole2 to infinity
SimpleMatrix R = rotateEpipole(epipole2,centerX,centerY);
SimpleMatrix T = translateToOrigin(centerX,centerY);
SimpleMatrix G = computeG(epipole2,centerX,centerY);
SimpleMatrix H = G.mult(R).mult(T);
//Find the two matching transforms
SimpleMatrix Hzero = computeHZero(F,epipole2,H);
SimpleMatrix Ha = computeAffineH(observations,H.getDDRM(),Hzero.getDDRM());
rect1.set(Ha.mult(Hzero).getDDRM());
rect2.set(H.getDDRM());
} | [
"public",
"void",
"process",
"(",
"DMatrixRMaj",
"F",
",",
"List",
"<",
"AssociatedPair",
">",
"observations",
",",
"int",
"width",
",",
"int",
"height",
")",
"{",
"int",
"centerX",
"=",
"width",
"/",
"2",
";",
"int",
"centerY",
"=",
"height",
"/",
"2"... | Compute rectification transforms for the stereo pair given a fundamental matrix and its observations.
@param F Fundamental matrix
@param observations Observations used to compute F
@param width Width of first image.
@param height Height of first image. | [
"Compute",
"rectification",
"transforms",
"for",
"the",
"stereo",
"pair",
"given",
"a",
"fundamental",
"matrix",
"and",
"its",
"observations",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/alg/geo/rectify/RectifyFundamental.java#L73-L97 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/alg/geo/rectify/RectifyFundamental.java | RectifyFundamental.checkEpipoleInside | private void checkEpipoleInside(int width, int height) {
double x1 = epipole1.x/epipole1.z;
double y1 = epipole1.y/epipole1.z;
double x2 = epipole2.x/epipole2.z;
double y2 = epipole2.y/epipole2.z;
if( x1 >= 0 && x1 < width && y1 >= 0 && y1 < height )
throw new IllegalArgumentException("First epipole is inside the image");
if( x2 >= 0 && x2 < width && y2 >= 0 && y2 < height )
throw new IllegalArgumentException("Second epipole is inside the image");
} | java | private void checkEpipoleInside(int width, int height) {
double x1 = epipole1.x/epipole1.z;
double y1 = epipole1.y/epipole1.z;
double x2 = epipole2.x/epipole2.z;
double y2 = epipole2.y/epipole2.z;
if( x1 >= 0 && x1 < width && y1 >= 0 && y1 < height )
throw new IllegalArgumentException("First epipole is inside the image");
if( x2 >= 0 && x2 < width && y2 >= 0 && y2 < height )
throw new IllegalArgumentException("Second epipole is inside the image");
} | [
"private",
"void",
"checkEpipoleInside",
"(",
"int",
"width",
",",
"int",
"height",
")",
"{",
"double",
"x1",
"=",
"epipole1",
".",
"x",
"/",
"epipole1",
".",
"z",
";",
"double",
"y1",
"=",
"epipole1",
".",
"y",
"/",
"epipole1",
".",
"z",
";",
"doubl... | The epipoles need to be outside the image | [
"The",
"epipoles",
"need",
"to",
"be",
"outside",
"the",
"image"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/alg/geo/rectify/RectifyFundamental.java#L102-L113 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/alg/geo/rectify/RectifyFundamental.java | RectifyFundamental.translateToOrigin | private SimpleMatrix translateToOrigin( int x0 , int y0 ) {
SimpleMatrix T = SimpleMatrix.identity(3);
T.set(0, 2, -x0);
T.set(1, 2, -y0);
return T;
} | java | private SimpleMatrix translateToOrigin( int x0 , int y0 ) {
SimpleMatrix T = SimpleMatrix.identity(3);
T.set(0, 2, -x0);
T.set(1, 2, -y0);
return T;
} | [
"private",
"SimpleMatrix",
"translateToOrigin",
"(",
"int",
"x0",
",",
"int",
"y0",
")",
"{",
"SimpleMatrix",
"T",
"=",
"SimpleMatrix",
".",
"identity",
"(",
"3",
")",
";",
"T",
".",
"set",
"(",
"0",
",",
"2",
",",
"-",
"x0",
")",
";",
"T",
".",
... | Create a transform which will move the specified point to the origin | [
"Create",
"a",
"transform",
"which",
"will",
"move",
"the",
"specified",
"point",
"to",
"the",
"origin"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/alg/geo/rectify/RectifyFundamental.java#L118-L126 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/alg/geo/rectify/RectifyFundamental.java | RectifyFundamental.computeAffineH | private SimpleMatrix computeAffineH( List<AssociatedPair> observations ,
DMatrixRMaj H , DMatrixRMaj Hzero ) {
SimpleMatrix A = new SimpleMatrix(observations.size(),3);
SimpleMatrix b = new SimpleMatrix(A.numRows(),1);
Point2D_F64 c = new Point2D_F64();
Point2D_F64 k = new Point2D_F64();
for( int i = 0; i < observations.size(); i++ ) {
AssociatedPair a = observations.get(i);
GeometryMath_F64.mult(Hzero, a.p1, k);
GeometryMath_F64.mult(H,a.p2,c);
A.setRow(i,0,k.x,k.y,1);
b.set(i,0,c.x);
}
SimpleMatrix x = A.solve(b);
SimpleMatrix Ha = SimpleMatrix.identity(3);
Ha.setRow(0,0,x.getDDRM().data);
return Ha;
} | java | private SimpleMatrix computeAffineH( List<AssociatedPair> observations ,
DMatrixRMaj H , DMatrixRMaj Hzero ) {
SimpleMatrix A = new SimpleMatrix(observations.size(),3);
SimpleMatrix b = new SimpleMatrix(A.numRows(),1);
Point2D_F64 c = new Point2D_F64();
Point2D_F64 k = new Point2D_F64();
for( int i = 0; i < observations.size(); i++ ) {
AssociatedPair a = observations.get(i);
GeometryMath_F64.mult(Hzero, a.p1, k);
GeometryMath_F64.mult(H,a.p2,c);
A.setRow(i,0,k.x,k.y,1);
b.set(i,0,c.x);
}
SimpleMatrix x = A.solve(b);
SimpleMatrix Ha = SimpleMatrix.identity(3);
Ha.setRow(0,0,x.getDDRM().data);
return Ha;
} | [
"private",
"SimpleMatrix",
"computeAffineH",
"(",
"List",
"<",
"AssociatedPair",
">",
"observations",
",",
"DMatrixRMaj",
"H",
",",
"DMatrixRMaj",
"Hzero",
")",
"{",
"SimpleMatrix",
"A",
"=",
"new",
"SimpleMatrix",
"(",
"observations",
".",
"size",
"(",
")",
"... | Finds the values of a,b,c which minimize
sum (a*x(+)_i + b*y(+)_i + c - x(-)_i)^2
See page 306
@return Affine transform | [
"Finds",
"the",
"values",
"of",
"a",
"b",
"c",
"which",
"minimize"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/alg/geo/rectify/RectifyFundamental.java#L171-L196 | train |
lessthanoptimal/BoofCV | main/boofcv-io/src/main/java/boofcv/io/UtilIO.java | UtilIO.pathExampleURL | public static URL pathExampleURL( String path ) {
try {
File fpath = new File(path);
if (fpath.isAbsolute())
return fpath.toURI().toURL();
// Assume we are running inside of the project come
String pathToBase = getPathToBase();
if( pathToBase != null ) {
File pathExample = new File(pathToBase, "data/example/");
if (pathExample.exists()) {
return new File(pathExample.getPath(), path).getAbsoluteFile().toURL();
}
}
// System.out.println("-----------------------");
// maybe we are running inside an app and all data is stored inside as a resource
// System.out.println("Attempting to load resource "+path);
URL url = UtilIO.class.getClassLoader().getResource(path);
if (url == null) {
System.err.println();
System.err.println("Can't find data/example directory! There are three likely causes for this problem.");
System.err.println();
System.err.println("1) You checked out the source code from git and did not pull the data submodule too.");
System.err.println("2) You are trying to run an example from outside the BoofCV directory tree.");
System.err.println("3) You are trying to pass in your own image.");
System.err.println();
System.err.println("Solutions:");
System.err.println("1) Follow instructions in the boofcv/readme.md file to grab the data directory.");
System.err.println("2) Launch the example from inside BoofCV's directory tree!");
System.err.println("3) Don't use this function and just pass in the path directly");
System.exit(1);
}
return url;
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
} | java | public static URL pathExampleURL( String path ) {
try {
File fpath = new File(path);
if (fpath.isAbsolute())
return fpath.toURI().toURL();
// Assume we are running inside of the project come
String pathToBase = getPathToBase();
if( pathToBase != null ) {
File pathExample = new File(pathToBase, "data/example/");
if (pathExample.exists()) {
return new File(pathExample.getPath(), path).getAbsoluteFile().toURL();
}
}
// System.out.println("-----------------------");
// maybe we are running inside an app and all data is stored inside as a resource
// System.out.println("Attempting to load resource "+path);
URL url = UtilIO.class.getClassLoader().getResource(path);
if (url == null) {
System.err.println();
System.err.println("Can't find data/example directory! There are three likely causes for this problem.");
System.err.println();
System.err.println("1) You checked out the source code from git and did not pull the data submodule too.");
System.err.println("2) You are trying to run an example from outside the BoofCV directory tree.");
System.err.println("3) You are trying to pass in your own image.");
System.err.println();
System.err.println("Solutions:");
System.err.println("1) Follow instructions in the boofcv/readme.md file to grab the data directory.");
System.err.println("2) Launch the example from inside BoofCV's directory tree!");
System.err.println("3) Don't use this function and just pass in the path directly");
System.exit(1);
}
return url;
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
} | [
"public",
"static",
"URL",
"pathExampleURL",
"(",
"String",
"path",
")",
"{",
"try",
"{",
"File",
"fpath",
"=",
"new",
"File",
"(",
"path",
")",
";",
"if",
"(",
"fpath",
".",
"isAbsolute",
"(",
")",
")",
"return",
"fpath",
".",
"toURI",
"(",
")",
"... | Returns an absolute path to the file that is relative to the example directory
@param path File path relative to root directory
@return Absolute path to file | [
"Returns",
"an",
"absolute",
"path",
"to",
"the",
"file",
"that",
"is",
"relative",
"to",
"the",
"example",
"directory"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-io/src/main/java/boofcv/io/UtilIO.java#L44-L81 | train |
lessthanoptimal/BoofCV | main/boofcv-io/src/main/java/boofcv/io/UtilIO.java | UtilIO.ensureURL | public static URL ensureURL(String path ) {
path = systemToUnix(path);
URL url;
try {
url = new URL(path);
if( url.getProtocol().equals("jar")) {
return simplifyJarPath(url);
}
} catch (MalformedURLException e) {
// might just be a file reference.
try {
url = new File(path).toURI().toURL(); // simplify the path. "1/2/../3" = "1/3"
} catch (MalformedURLException e2) {
return null;
}
}
return url;
} | java | public static URL ensureURL(String path ) {
path = systemToUnix(path);
URL url;
try {
url = new URL(path);
if( url.getProtocol().equals("jar")) {
return simplifyJarPath(url);
}
} catch (MalformedURLException e) {
// might just be a file reference.
try {
url = new File(path).toURI().toURL(); // simplify the path. "1/2/../3" = "1/3"
} catch (MalformedURLException e2) {
return null;
}
}
return url;
} | [
"public",
"static",
"URL",
"ensureURL",
"(",
"String",
"path",
")",
"{",
"path",
"=",
"systemToUnix",
"(",
"path",
")",
";",
"URL",
"url",
";",
"try",
"{",
"url",
"=",
"new",
"URL",
"(",
"path",
")",
";",
"if",
"(",
"url",
".",
"getProtocol",
"(",
... | Given a path which may or may not be a URL return a URL | [
"Given",
"a",
"path",
"which",
"may",
"or",
"may",
"not",
"be",
"a",
"URL",
"return",
"a",
"URL"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-io/src/main/java/boofcv/io/UtilIO.java#L93-L110 | train |
lessthanoptimal/BoofCV | main/boofcv-io/src/main/java/boofcv/io/UtilIO.java | UtilIO.simplifyJarPath | public static URL simplifyJarPath( URL url ) {
try {
String segments[] = url.toString().split(".jar!/");
String path = simplifyJarPath(segments[1]);
return new URL(segments[0]+".jar!/"+path);
} catch (IOException e) {
return url;
}
} | java | public static URL simplifyJarPath( URL url ) {
try {
String segments[] = url.toString().split(".jar!/");
String path = simplifyJarPath(segments[1]);
return new URL(segments[0]+".jar!/"+path);
} catch (IOException e) {
return url;
}
} | [
"public",
"static",
"URL",
"simplifyJarPath",
"(",
"URL",
"url",
")",
"{",
"try",
"{",
"String",
"segments",
"[",
"]",
"=",
"url",
".",
"toString",
"(",
")",
".",
"split",
"(",
"\".jar!/\"",
")",
";",
"String",
"path",
"=",
"simplifyJarPath",
"(",
"seg... | Jar paths don't work if they include up directory. this wills trip those out. | [
"Jar",
"paths",
"don",
"t",
"work",
"if",
"they",
"include",
"up",
"directory",
".",
"this",
"wills",
"trip",
"those",
"out",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-io/src/main/java/boofcv/io/UtilIO.java#L115-L123 | train |
lessthanoptimal/BoofCV | main/boofcv-io/src/main/java/boofcv/io/UtilIO.java | UtilIO.path | public static String path( String path ) {
String pathToBase = getPathToBase();
if( pathToBase == null )
return path;
return new File(pathToBase,path).getAbsolutePath();
} | java | public static String path( String path ) {
String pathToBase = getPathToBase();
if( pathToBase == null )
return path;
return new File(pathToBase,path).getAbsolutePath();
} | [
"public",
"static",
"String",
"path",
"(",
"String",
"path",
")",
"{",
"String",
"pathToBase",
"=",
"getPathToBase",
"(",
")",
";",
"if",
"(",
"pathToBase",
"==",
"null",
")",
"return",
"path",
";",
"return",
"new",
"File",
"(",
"pathToBase",
",",
"path"... | Searches for the root BoofCV directory and returns an absolute path from it.
@param path File path relative to root directory
@return Absolute path to file | [
"Searches",
"for",
"the",
"root",
"BoofCV",
"directory",
"and",
"returns",
"an",
"absolute",
"path",
"from",
"it",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-io/src/main/java/boofcv/io/UtilIO.java#L194-L199 | train |
lessthanoptimal/BoofCV | main/boofcv-io/src/main/java/boofcv/io/UtilIO.java | UtilIO.getPathToBase | public static String getPathToBase() {
String path = new File(".").getAbsoluteFile().getParent();
while( path != null ) {
File f = new File(path);
if( !f.exists() )
break;
String[] files = f.list();
if( files == null )
break;
boolean foundMain = false;
boolean foundExamples = false;
boolean foundIntegration = false;
for( String s : files ) {
if( s.compareToIgnoreCase("main") == 0 )
foundMain = true;
else if( s.compareToIgnoreCase("examples") == 0 )
foundExamples = true;
else if( s.compareToIgnoreCase("integration") == 0 )
foundIntegration = true;
}
if( foundMain && foundExamples && foundIntegration)
return path;
path = f.getParent();
}
return null;
} | java | public static String getPathToBase() {
String path = new File(".").getAbsoluteFile().getParent();
while( path != null ) {
File f = new File(path);
if( !f.exists() )
break;
String[] files = f.list();
if( files == null )
break;
boolean foundMain = false;
boolean foundExamples = false;
boolean foundIntegration = false;
for( String s : files ) {
if( s.compareToIgnoreCase("main") == 0 )
foundMain = true;
else if( s.compareToIgnoreCase("examples") == 0 )
foundExamples = true;
else if( s.compareToIgnoreCase("integration") == 0 )
foundIntegration = true;
}
if( foundMain && foundExamples && foundIntegration)
return path;
path = f.getParent();
}
return null;
} | [
"public",
"static",
"String",
"getPathToBase",
"(",
")",
"{",
"String",
"path",
"=",
"new",
"File",
"(",
"\".\"",
")",
".",
"getAbsoluteFile",
"(",
")",
".",
"getParent",
"(",
")",
";",
"while",
"(",
"path",
"!=",
"null",
")",
"{",
"File",
"f",
"=",
... | Steps back until it finds the base BoofCV directory.
@return Path to the base directory. | [
"Steps",
"back",
"until",
"it",
"finds",
"the",
"base",
"BoofCV",
"directory",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-io/src/main/java/boofcv/io/UtilIO.java#L210-L241 | train |
lessthanoptimal/BoofCV | main/boofcv-io/src/main/java/boofcv/io/UtilIO.java | UtilIO.selectFile | public static String selectFile(boolean exitOnCancel) {
String fileName = null;
JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
fileName = fc.getSelectedFile().getAbsolutePath();
} else if (exitOnCancel) {
System.exit(0);
}
return fileName;
} | java | public static String selectFile(boolean exitOnCancel) {
String fileName = null;
JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
fileName = fc.getSelectedFile().getAbsolutePath();
} else if (exitOnCancel) {
System.exit(0);
}
return fileName;
} | [
"public",
"static",
"String",
"selectFile",
"(",
"boolean",
"exitOnCancel",
")",
"{",
"String",
"fileName",
"=",
"null",
";",
"JFileChooser",
"fc",
"=",
"new",
"JFileChooser",
"(",
")",
";",
"int",
"returnVal",
"=",
"fc",
".",
"showOpenDialog",
"(",
"null",
... | Opens up a dialog box asking the user to select a file. If the user cancels
it either returns null or quits the program.
@param exitOnCancel If it should quit on cancel or not.
@return Name of the selected file or null if nothing was selected. | [
"Opens",
"up",
"a",
"dialog",
"box",
"asking",
"the",
"user",
"to",
"select",
"a",
"file",
".",
"If",
"the",
"user",
"cancels",
"it",
"either",
"returns",
"null",
"or",
"quits",
"the",
"program",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-io/src/main/java/boofcv/io/UtilIO.java#L250-L263 | train |
lessthanoptimal/BoofCV | main/boofcv-io/src/main/java/boofcv/io/UtilIO.java | UtilIO.listByPrefix | public static List<String> listByPrefix(String directory, String prefix, String suffix) {
List<String> ret = new ArrayList<>();
File d = new File(directory);
if( !d.isDirectory() ) {
try {
URL url = new URL(directory);
if( url.getProtocol().equals("file")) {
d = new File(url.getFile());
} else if( url.getProtocol().equals("jar")){
return listJarPrefix(url,prefix,suffix);
}
} catch( MalformedURLException ignore){}
}
if( !d.isDirectory() )
throw new IllegalArgumentException("Must specify an directory. "+directory);
File files[] = d.listFiles();
for( File f : files ) {
if( f.isDirectory() || f.isHidden() )
continue;
if( prefix == null || f.getName().startsWith(prefix )) {
if( suffix ==null || f.getName().endsWith(suffix)) {
ret.add(f.getAbsolutePath());
}
}
}
return ret;
} | java | public static List<String> listByPrefix(String directory, String prefix, String suffix) {
List<String> ret = new ArrayList<>();
File d = new File(directory);
if( !d.isDirectory() ) {
try {
URL url = new URL(directory);
if( url.getProtocol().equals("file")) {
d = new File(url.getFile());
} else if( url.getProtocol().equals("jar")){
return listJarPrefix(url,prefix,suffix);
}
} catch( MalformedURLException ignore){}
}
if( !d.isDirectory() )
throw new IllegalArgumentException("Must specify an directory. "+directory);
File files[] = d.listFiles();
for( File f : files ) {
if( f.isDirectory() || f.isHidden() )
continue;
if( prefix == null || f.getName().startsWith(prefix )) {
if( suffix ==null || f.getName().endsWith(suffix)) {
ret.add(f.getAbsolutePath());
}
}
}
return ret;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"listByPrefix",
"(",
"String",
"directory",
",",
"String",
"prefix",
",",
"String",
"suffix",
")",
"{",
"List",
"<",
"String",
">",
"ret",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"File",
"d",
"=",
... | Loads a list of files with the specified prefix.
@param directory Directory it looks inside of
@param prefix Prefix that the file must have
@param suffix
@return List of files that are in the directory and match the prefix. | [
"Loads",
"a",
"list",
"of",
"files",
"with",
"the",
"specified",
"prefix",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-io/src/main/java/boofcv/io/UtilIO.java#L506-L538 | train |
lessthanoptimal/BoofCV | main/boofcv-io/src/main/java/boofcv/io/UtilIO.java | UtilIO.listAllMime | public static List<String> listAllMime( String directory , String type ) {
List<String> ret = new ArrayList<>();
try {
// see if it's a URL or not
URL url = new URL(directory);
if( url.getProtocol().equals("file") ) {
directory = url.getFile();
} else if( url.getProtocol().equals("jar") ) {
return listJarMime(url,null,null);
} else {
throw new RuntimeException("Not sure what to do with this url. "+url.toString());
}
} catch (MalformedURLException ignore) {
}
File d = new File(directory);
if( !d.isDirectory() )
throw new IllegalArgumentException("Must specify an directory");
File []files = d.listFiles();
if( files == null )
return ret;
for( File f : files ) {
if( f.isDirectory() )
continue;
try {
String mimeType = Files.probeContentType(f.toPath());
if( mimeType.contains(type))
ret.add(f.getAbsolutePath());
} catch (IOException ignore) {}
}
Collections.sort(ret);
return ret;
} | java | public static List<String> listAllMime( String directory , String type ) {
List<String> ret = new ArrayList<>();
try {
// see if it's a URL or not
URL url = new URL(directory);
if( url.getProtocol().equals("file") ) {
directory = url.getFile();
} else if( url.getProtocol().equals("jar") ) {
return listJarMime(url,null,null);
} else {
throw new RuntimeException("Not sure what to do with this url. "+url.toString());
}
} catch (MalformedURLException ignore) {
}
File d = new File(directory);
if( !d.isDirectory() )
throw new IllegalArgumentException("Must specify an directory");
File []files = d.listFiles();
if( files == null )
return ret;
for( File f : files ) {
if( f.isDirectory() )
continue;
try {
String mimeType = Files.probeContentType(f.toPath());
if( mimeType.contains(type))
ret.add(f.getAbsolutePath());
} catch (IOException ignore) {}
}
Collections.sort(ret);
return ret;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"listAllMime",
"(",
"String",
"directory",
",",
"String",
"type",
")",
"{",
"List",
"<",
"String",
">",
"ret",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"try",
"{",
"// see if it's a URL or not",
"URL",
... | Lists all files in the directory with an MIME type that contains the string "type" | [
"Lists",
"all",
"files",
"in",
"the",
"directory",
"with",
"an",
"MIME",
"type",
"that",
"contains",
"the",
"string",
"type"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-io/src/main/java/boofcv/io/UtilIO.java#L608-L646 | train |
lessthanoptimal/BoofCV | main/boofcv-sfm/src/main/java/boofcv/alg/sfm/overhead/SelectOverheadParameters.java | SelectOverheadParameters.process | public boolean process(CameraPinholeBrown intrinsic , Se3_F64 planeToCamera )
{
proj.setPlaneToCamera(planeToCamera,true);
proj.setIntrinsic(intrinsic);
// find a bounding rectangle on the ground which is visible to the camera and at a high enough resolution
double x0 = Double.MAX_VALUE;
double y0 = Double.MAX_VALUE;
double x1 = -Double.MAX_VALUE;
double y1 = -Double.MAX_VALUE;
for( int y = 0; y < intrinsic.height; y++ ) {
for( int x = 0; x < intrinsic.width; x++ ) {
if( !checkValidPixel(x,y) )
continue;
if( plane0.x < x0 )
x0 = plane0.x;
if( plane0.x > x1 )
x1 = plane0.x;
if( plane0.y < y0 )
y0 = plane0.y;
if( plane0.y > y1 )
y1 = plane0.y;
}
}
if( x0 == Double.MAX_VALUE )
return false;
// compute parameters with the intent of maximizing viewing area
double mapWidth = x1-x0;
double mapHeight = y1-y0;
overheadWidth = (int)Math.floor(mapWidth/cellSize);
overheadHeight = (int)Math.floor(mapHeight* viewHeightFraction /cellSize);
centerX = -x0;
centerY = -(y0+mapHeight*(1- viewHeightFraction)/2.0);
return true;
} | java | public boolean process(CameraPinholeBrown intrinsic , Se3_F64 planeToCamera )
{
proj.setPlaneToCamera(planeToCamera,true);
proj.setIntrinsic(intrinsic);
// find a bounding rectangle on the ground which is visible to the camera and at a high enough resolution
double x0 = Double.MAX_VALUE;
double y0 = Double.MAX_VALUE;
double x1 = -Double.MAX_VALUE;
double y1 = -Double.MAX_VALUE;
for( int y = 0; y < intrinsic.height; y++ ) {
for( int x = 0; x < intrinsic.width; x++ ) {
if( !checkValidPixel(x,y) )
continue;
if( plane0.x < x0 )
x0 = plane0.x;
if( plane0.x > x1 )
x1 = plane0.x;
if( plane0.y < y0 )
y0 = plane0.y;
if( plane0.y > y1 )
y1 = plane0.y;
}
}
if( x0 == Double.MAX_VALUE )
return false;
// compute parameters with the intent of maximizing viewing area
double mapWidth = x1-x0;
double mapHeight = y1-y0;
overheadWidth = (int)Math.floor(mapWidth/cellSize);
overheadHeight = (int)Math.floor(mapHeight* viewHeightFraction /cellSize);
centerX = -x0;
centerY = -(y0+mapHeight*(1- viewHeightFraction)/2.0);
return true;
} | [
"public",
"boolean",
"process",
"(",
"CameraPinholeBrown",
"intrinsic",
",",
"Se3_F64",
"planeToCamera",
")",
"{",
"proj",
".",
"setPlaneToCamera",
"(",
"planeToCamera",
",",
"true",
")",
";",
"proj",
".",
"setIntrinsic",
"(",
"intrinsic",
")",
";",
"// find a b... | Computes the view's characteristics
@param intrinsic Intrinsic camera parameters
@param planeToCamera Extrinsic camera parameters which specify the plane
@return true if successful or false if it failed | [
"Computes",
"the",
"view",
"s",
"characteristics"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-sfm/src/main/java/boofcv/alg/sfm/overhead/SelectOverheadParameters.java#L81-L120 | train |
lessthanoptimal/BoofCV | main/boofcv-sfm/src/main/java/boofcv/alg/sfm/overhead/SelectOverheadParameters.java | SelectOverheadParameters.createOverhead | public <T extends ImageBase<T>> OverheadView createOverhead( ImageType<T> imageType ) {
OverheadView ret = new OverheadView();
ret.image = imageType.createImage(overheadWidth,overheadHeight);
ret.cellSize = cellSize;
ret.centerX = centerX;
ret.centerY = centerY;
return ret;
} | java | public <T extends ImageBase<T>> OverheadView createOverhead( ImageType<T> imageType ) {
OverheadView ret = new OverheadView();
ret.image = imageType.createImage(overheadWidth,overheadHeight);
ret.cellSize = cellSize;
ret.centerX = centerX;
ret.centerY = centerY;
return ret;
} | [
"public",
"<",
"T",
"extends",
"ImageBase",
"<",
"T",
">",
">",
"OverheadView",
"createOverhead",
"(",
"ImageType",
"<",
"T",
">",
"imageType",
")",
"{",
"OverheadView",
"ret",
"=",
"new",
"OverheadView",
"(",
")",
";",
"ret",
".",
"image",
"=",
"imageTy... | Creates a new instance of the overhead view | [
"Creates",
"a",
"new",
"instance",
"of",
"the",
"overhead",
"view"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-sfm/src/main/java/boofcv/alg/sfm/overhead/SelectOverheadParameters.java#L125-L133 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.