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-geo/src/main/java/boofcv/alg/geo/bundle/jacobians/JacobianSo3Numerical.java | JacobianSo3Numerical.init | public void init() {
N = getParameterLength();
jacR = new DMatrixRMaj[N];
for (int i = 0; i < N; i++) {
jacR[i] = new DMatrixRMaj(3,3);
}
jacobian = new DMatrixRMaj(N,9);
paramInternal = new double[N];
numericalJac = createNumericalAlgorithm(function);
} | java | public void init() {
N = getParameterLength();
jacR = new DMatrixRMaj[N];
for (int i = 0; i < N; i++) {
jacR[i] = new DMatrixRMaj(3,3);
}
jacobian = new DMatrixRMaj(N,9);
paramInternal = new double[N];
numericalJac = createNumericalAlgorithm(function);
} | [
"public",
"void",
"init",
"(",
")",
"{",
"N",
"=",
"getParameterLength",
"(",
")",
";",
"jacR",
"=",
"new",
"DMatrixRMaj",
"[",
"N",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"jacR",
"[",
"i",
... | Initializes data structures. Separate function to make it easier to extend the class | [
"Initializes",
"data",
"structures",
".",
"Separate",
"function",
"to",
"make",
"it",
"easier",
"to",
"extend",
"the",
"class"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/alg/geo/bundle/jacobians/JacobianSo3Numerical.java#L49-L58 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/abst/geo/bundle/SceneObservations.java | SceneObservations.checkOneObservationPerView | public void checkOneObservationPerView() {
for (int viewIdx = 0; viewIdx < views.length; viewIdx++) {
SceneObservations.View v = views[viewIdx];
for (int obsIdx = 0; obsIdx < v.size(); obsIdx++) {
int a = v.point.get(obsIdx);
for (int i = obsIdx+1; i < v.size(); i++) {
if( a == v.point.get(i)) {
new RuntimeException("Same point is viewed more than once in the same view");
}
}
}
}
} | java | public void checkOneObservationPerView() {
for (int viewIdx = 0; viewIdx < views.length; viewIdx++) {
SceneObservations.View v = views[viewIdx];
for (int obsIdx = 0; obsIdx < v.size(); obsIdx++) {
int a = v.point.get(obsIdx);
for (int i = obsIdx+1; i < v.size(); i++) {
if( a == v.point.get(i)) {
new RuntimeException("Same point is viewed more than once in the same view");
}
}
}
}
} | [
"public",
"void",
"checkOneObservationPerView",
"(",
")",
"{",
"for",
"(",
"int",
"viewIdx",
"=",
"0",
";",
"viewIdx",
"<",
"views",
".",
"length",
";",
"viewIdx",
"++",
")",
"{",
"SceneObservations",
".",
"View",
"v",
"=",
"views",
"[",
"viewIdx",
"]",
... | Makes sure that each feature is only observed in each view | [
"Makes",
"sure",
"that",
"each",
"feature",
"is",
"only",
"observed",
"in",
"each",
"view"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/abst/geo/bundle/SceneObservations.java#L166-L179 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/misc/ProfileOperation.java | ProfileOperation.profile | public static void profile( Performer performer , int num ) {
long deltaTime = measureTime(performer,num);
System.out.printf("%30s time = %8d ms per frame = %8.3f\n",
performer.getName(),deltaTime,(deltaTime/(double)num));
// System.out.println(performer.getClass().getSimpleName()+
// " time = "+deltaTime+" ms per frame "+(deltaTime/(double)num));
} | java | public static void profile( Performer performer , int num ) {
long deltaTime = measureTime(performer,num);
System.out.printf("%30s time = %8d ms per frame = %8.3f\n",
performer.getName(),deltaTime,(deltaTime/(double)num));
// System.out.println(performer.getClass().getSimpleName()+
// " time = "+deltaTime+" ms per frame "+(deltaTime/(double)num));
} | [
"public",
"static",
"void",
"profile",
"(",
"Performer",
"performer",
",",
"int",
"num",
")",
"{",
"long",
"deltaTime",
"=",
"measureTime",
"(",
"performer",
",",
"num",
")",
";",
"System",
".",
"out",
".",
"printf",
"(",
"\"%30s time = %8d ms per frame = %8.3... | See how long it takes to run the process 'num' times and print the results
to standard out | [
"See",
"how",
"long",
"it",
"takes",
"to",
"run",
"the",
"process",
"num",
"times",
"and",
"print",
"the",
"results",
"to",
"standard",
"out"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/misc/ProfileOperation.java#L31-L39 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/fh04/SegmentFelzenszwalbHuttenlocher04.java | SegmentFelzenszwalbHuttenlocher04.initialize | protected void initialize(T input , GrayS32 output ) {
this.graph = output;
final int N = input.width*input.height;
regionSize.resize(N);
threshold.resize(N);
for( int i = 0; i < N; i++ ) {
regionSize.data[i] = 1;
threshold.data[i] = K;
graph.data[i] = i; // assign a unique label to each pixel since they are all their own region initially
}
edges.reset();
edgesNotMatched.reset();
} | java | protected void initialize(T input , GrayS32 output ) {
this.graph = output;
final int N = input.width*input.height;
regionSize.resize(N);
threshold.resize(N);
for( int i = 0; i < N; i++ ) {
regionSize.data[i] = 1;
threshold.data[i] = K;
graph.data[i] = i; // assign a unique label to each pixel since they are all their own region initially
}
edges.reset();
edgesNotMatched.reset();
} | [
"protected",
"void",
"initialize",
"(",
"T",
"input",
",",
"GrayS32",
"output",
")",
"{",
"this",
".",
"graph",
"=",
"output",
";",
"final",
"int",
"N",
"=",
"input",
".",
"width",
"*",
"input",
".",
"height",
";",
"regionSize",
".",
"resize",
"(",
"... | Predeclares all memory required and sets data structures to their initial values | [
"Predeclares",
"all",
"memory",
"required",
"and",
"sets",
"data",
"structures",
"to",
"their",
"initial",
"values"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/fh04/SegmentFelzenszwalbHuttenlocher04.java#L170-L184 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/fh04/SegmentFelzenszwalbHuttenlocher04.java | SegmentFelzenszwalbHuttenlocher04.mergeSmallRegions | protected void mergeSmallRegions() {
for( int i = 0; i < edgesNotMatched.size(); i++ ) {
Edge e = edgesNotMatched.get(i);
int rootA = find(e.indexA);
int rootB = find(e.indexB);
// see if they are already part of the same segment
if( rootA == rootB )
continue;
int sizeA = regionSize.get(rootA);
int sizeB = regionSize.get(rootB);
// merge if one of the regions is too small
if( sizeA < minimumSize || sizeB < minimumSize ) {
// Point everything towards rootA
graph.data[e.indexB] = rootA;
graph.data[rootB] = rootA;
// Update the size of regionA
regionSize.data[rootA] = sizeA + sizeB;
}
}
} | java | protected void mergeSmallRegions() {
for( int i = 0; i < edgesNotMatched.size(); i++ ) {
Edge e = edgesNotMatched.get(i);
int rootA = find(e.indexA);
int rootB = find(e.indexB);
// see if they are already part of the same segment
if( rootA == rootB )
continue;
int sizeA = regionSize.get(rootA);
int sizeB = regionSize.get(rootB);
// merge if one of the regions is too small
if( sizeA < minimumSize || sizeB < minimumSize ) {
// Point everything towards rootA
graph.data[e.indexB] = rootA;
graph.data[rootB] = rootA;
// Update the size of regionA
regionSize.data[rootA] = sizeA + sizeB;
}
}
} | [
"protected",
"void",
"mergeSmallRegions",
"(",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"edgesNotMatched",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"Edge",
"e",
"=",
"edgesNotMatched",
".",
"get",
"(",
"i",
")",
";",
"in... | Look at the remaining regions and if there are any small ones marge them into a larger region | [
"Look",
"at",
"the",
"remaining",
"regions",
"and",
"if",
"there",
"are",
"any",
"small",
"ones",
"marge",
"them",
"into",
"a",
"larger",
"region"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/fh04/SegmentFelzenszwalbHuttenlocher04.java#L245-L269 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/fh04/SegmentFelzenszwalbHuttenlocher04.java | SegmentFelzenszwalbHuttenlocher04.find | protected int find( int child ) {
int root = graph.data[child];
if( root == graph.data[root] )
return root;
int inputChild = child;
while( root != child ) {
child = root;
root = graph.data[child];
}
graph.data[inputChild] = root;
return root;
} | java | protected int find( int child ) {
int root = graph.data[child];
if( root == graph.data[root] )
return root;
int inputChild = child;
while( root != child ) {
child = root;
root = graph.data[child];
}
graph.data[inputChild] = root;
return root;
} | [
"protected",
"int",
"find",
"(",
"int",
"child",
")",
"{",
"int",
"root",
"=",
"graph",
".",
"data",
"[",
"child",
"]",
";",
"if",
"(",
"root",
"==",
"graph",
".",
"data",
"[",
"root",
"]",
")",
"return",
"root",
";",
"int",
"inputChild",
"=",
"c... | Finds the root given child. If the child does not point directly to the parent find the parent and make
the child point directly towards it. | [
"Finds",
"the",
"root",
"given",
"child",
".",
"If",
"the",
"child",
"does",
"not",
"point",
"directly",
"to",
"the",
"parent",
"find",
"the",
"parent",
"and",
"make",
"the",
"child",
"point",
"directly",
"towards",
"it",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/fh04/SegmentFelzenszwalbHuttenlocher04.java#L275-L289 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/fh04/SegmentFelzenszwalbHuttenlocher04.java | SegmentFelzenszwalbHuttenlocher04.computeOutput | protected void computeOutput() {
outputRegionId.reset();
outputRegionSizes.reset();
for( int y = 0; y < graph.height; y++ ) {
int indexGraph = graph.startIndex + y*graph.stride;
for( int x = 0; x < graph.width; x++ , indexGraph++) {
int parent = graph.data[indexGraph];
if( parent == indexGraph ) {
outputRegionId.add(indexGraph);
outputRegionSizes.add(regionSize.get(indexGraph));
} else {
// find the parent and set the child to it
int child = indexGraph;
while( parent != child ) {
child = parent;
parent = graph.data[child];
}
graph.data[indexGraph] = parent;
}
}
}
} | java | protected void computeOutput() {
outputRegionId.reset();
outputRegionSizes.reset();
for( int y = 0; y < graph.height; y++ ) {
int indexGraph = graph.startIndex + y*graph.stride;
for( int x = 0; x < graph.width; x++ , indexGraph++) {
int parent = graph.data[indexGraph];
if( parent == indexGraph ) {
outputRegionId.add(indexGraph);
outputRegionSizes.add(regionSize.get(indexGraph));
} else {
// find the parent and set the child to it
int child = indexGraph;
while( parent != child ) {
child = parent;
parent = graph.data[child];
}
graph.data[indexGraph] = parent;
}
}
}
} | [
"protected",
"void",
"computeOutput",
"(",
")",
"{",
"outputRegionId",
".",
"reset",
"(",
")",
";",
"outputRegionSizes",
".",
"reset",
"(",
")",
";",
"for",
"(",
"int",
"y",
"=",
"0",
";",
"y",
"<",
"graph",
".",
"height",
";",
"y",
"++",
")",
"{",... | Searches for root nodes in the graph and adds their size to the list of region sizes. Makes sure all
other nodes in the graph point directly at their root. | [
"Searches",
"for",
"root",
"nodes",
"in",
"the",
"graph",
"and",
"adds",
"their",
"size",
"to",
"the",
"list",
"of",
"region",
"sizes",
".",
"Makes",
"sure",
"all",
"other",
"nodes",
"in",
"the",
"graph",
"point",
"directly",
"at",
"their",
"root",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/fh04/SegmentFelzenszwalbHuttenlocher04.java#L295-L316 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/alg/geo/NormalizationPoint2D.java | NormalizationPoint2D.apply | public void apply( DMatrixRMaj H , DMatrixRMaj output ) {
output.reshape(3,H.numCols);
int stride = H.numCols;
for (int col = 0; col < H.numCols; col++) {
// This column in H
double h1 = H.data[col], h2 = H.data[col+stride], h3 = H.data[col+2*stride];
output.data[col] = h1/stdX - meanX*h3/stdX;
output.data[col+stride] = h2/stdY - meanY*h3/stdY;
output.data[col+2*stride] = h3;
}
} | java | public void apply( DMatrixRMaj H , DMatrixRMaj output ) {
output.reshape(3,H.numCols);
int stride = H.numCols;
for (int col = 0; col < H.numCols; col++) {
// This column in H
double h1 = H.data[col], h2 = H.data[col+stride], h3 = H.data[col+2*stride];
output.data[col] = h1/stdX - meanX*h3/stdX;
output.data[col+stride] = h2/stdY - meanY*h3/stdY;
output.data[col+2*stride] = h3;
}
} | [
"public",
"void",
"apply",
"(",
"DMatrixRMaj",
"H",
",",
"DMatrixRMaj",
"output",
")",
"{",
"output",
".",
"reshape",
"(",
"3",
",",
"H",
".",
"numCols",
")",
";",
"int",
"stride",
"=",
"H",
".",
"numCols",
";",
"for",
"(",
"int",
"col",
"=",
"0",
... | Applies normalization to a H=3xN matrix
out = Norm*H
@param H 3xN matrix. Can be same as input matrix | [
"Applies",
"normalization",
"to",
"a",
"H",
"=",
"3xN",
"matrix"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/alg/geo/NormalizationPoint2D.java#L76-L87 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/alg/geo/NormalizationPoint2D.java | NormalizationPoint2D.apply | public void apply(DMatrix3x3 C, DMatrix3x3 output) {
DMatrix3x3 Hinv = matrixInv3(work);
PerspectiveOps.multTranA(Hinv,C,Hinv,output);
} | java | public void apply(DMatrix3x3 C, DMatrix3x3 output) {
DMatrix3x3 Hinv = matrixInv3(work);
PerspectiveOps.multTranA(Hinv,C,Hinv,output);
} | [
"public",
"void",
"apply",
"(",
"DMatrix3x3",
"C",
",",
"DMatrix3x3",
"output",
")",
"{",
"DMatrix3x3",
"Hinv",
"=",
"matrixInv3",
"(",
"work",
")",
";",
"PerspectiveOps",
".",
"multTranA",
"(",
"Hinv",
",",
"C",
",",
"Hinv",
",",
"output",
")",
";",
"... | Apply transform to conic in 3x3 matrix format. | [
"Apply",
"transform",
"to",
"conic",
"in",
"3x3",
"matrix",
"format",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/alg/geo/NormalizationPoint2D.java#L132-L135 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/factory/transform/wavelet/FactoryWaveletHaar.java | FactoryWaveletHaar.generateInv_I32 | private static WlCoef_I32 generateInv_I32() {
WlCoef_I32 ret = new WlCoef_I32();
ret.scaling = new int[]{1,1};
ret.wavelet = new int[]{ret.scaling[0],-ret.scaling[0]};
ret.denominatorScaling = 2;
ret.denominatorWavelet = 2;
return ret;
} | java | private static WlCoef_I32 generateInv_I32() {
WlCoef_I32 ret = new WlCoef_I32();
ret.scaling = new int[]{1,1};
ret.wavelet = new int[]{ret.scaling[0],-ret.scaling[0]};
ret.denominatorScaling = 2;
ret.denominatorWavelet = 2;
return ret;
} | [
"private",
"static",
"WlCoef_I32",
"generateInv_I32",
"(",
")",
"{",
"WlCoef_I32",
"ret",
"=",
"new",
"WlCoef_I32",
"(",
")",
";",
"ret",
".",
"scaling",
"=",
"new",
"int",
"[",
"]",
"{",
"1",
",",
"1",
"}",
";",
"ret",
".",
"wavelet",
"=",
"new",
... | Create a description for the inverse transform. Note that this will NOT produce
an exact copy of the original due to rounding error.
@return Wavelet inverse coefficient description. | [
"Create",
"a",
"description",
"for",
"the",
"inverse",
"transform",
".",
"Note",
"that",
"this",
"will",
"NOT",
"produce",
"an",
"exact",
"copy",
"of",
"the",
"original",
"due",
"to",
"rounding",
"error",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/factory/transform/wavelet/FactoryWaveletHaar.java#L69-L78 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java | CombinedTrackerScalePoint.updateTracks | public void updateTracks( I input ,
PyramidDiscrete<I> pyramid ,
D[] derivX,
D[] derivY ) {
// forget recently dropped or spawned tracks
tracksSpawned.clear();
// save references
this.input = input;
trackerKlt.setInputs(pyramid, derivX, derivY);
trackUsingKlt(tracksPureKlt);
trackUsingKlt(tracksReactivated);
} | java | public void updateTracks( I input ,
PyramidDiscrete<I> pyramid ,
D[] derivX,
D[] derivY ) {
// forget recently dropped or spawned tracks
tracksSpawned.clear();
// save references
this.input = input;
trackerKlt.setInputs(pyramid, derivX, derivY);
trackUsingKlt(tracksPureKlt);
trackUsingKlt(tracksReactivated);
} | [
"public",
"void",
"updateTracks",
"(",
"I",
"input",
",",
"PyramidDiscrete",
"<",
"I",
">",
"pyramid",
",",
"D",
"[",
"]",
"derivX",
",",
"D",
"[",
"]",
"derivY",
")",
"{",
"// forget recently dropped or spawned tracks",
"tracksSpawned",
".",
"clear",
"(",
"... | Updates the location and description of tracks using KLT. Saves a reference
to the input image for future processing.
@param input Input image.
@param pyramid Image pyramid of input.
@param derivX Derivative pyramid of input x-axis
@param derivY Derivative pyramid of input y-axis | [
"Updates",
"the",
"location",
"and",
"description",
"of",
"tracks",
"using",
"KLT",
".",
"Saves",
"a",
"reference",
"to",
"the",
"input",
"image",
"for",
"future",
"processing",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java#L123-L137 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java | CombinedTrackerScalePoint.trackUsingKlt | private void trackUsingKlt(List<CombinedTrack<TD>> tracks) {
for( int i = 0; i < tracks.size(); ) {
CombinedTrack<TD> track = tracks.get(i);
if( !trackerKlt.performTracking(track.track) ) {
// handle the dropped track
tracks.remove(i);
tracksDormant.add(track);
} else {
track.set(track.track.x,track.track.y);
i++;
}
}
} | java | private void trackUsingKlt(List<CombinedTrack<TD>> tracks) {
for( int i = 0; i < tracks.size(); ) {
CombinedTrack<TD> track = tracks.get(i);
if( !trackerKlt.performTracking(track.track) ) {
// handle the dropped track
tracks.remove(i);
tracksDormant.add(track);
} else {
track.set(track.track.x,track.track.y);
i++;
}
}
} | [
"private",
"void",
"trackUsingKlt",
"(",
"List",
"<",
"CombinedTrack",
"<",
"TD",
">",
">",
"tracks",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"tracks",
".",
"size",
"(",
")",
";",
")",
"{",
"CombinedTrack",
"<",
"TD",
">",
"tra... | Tracks features in the list using KLT and update their state | [
"Tracks",
"features",
"in",
"the",
"list",
"using",
"KLT",
"and",
"update",
"their",
"state"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java#L142-L155 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java | CombinedTrackerScalePoint.spawnTracksFromDetected | public void spawnTracksFromDetected() {
// mark detected features with no matches as available
FastQueue<AssociatedIndex> matches = associate.getMatches();
int N = detector.getNumberOfFeatures();
for( int i = 0; i < N; i++ )
associated[i] = false;
for( AssociatedIndex i : matches.toList() ) {
associated[i.dst] = true;
}
// spawn new tracks for unassociated detected features
for( int i = 0; i < N; i++ ) {
if( associated[i])
continue;
Point2D_F64 p = detector.getLocation(i);
TD d = detectedDesc.get(i);
CombinedTrack<TD> track;
if( tracksUnused.size() > 0 ) {
track = tracksUnused.pop();
} else {
track = new CombinedTrack<>();
track.desc = detector.createDescription();
track.track = trackerKlt.createNewTrack();
}
// create the descriptor for tracking
trackerKlt.setDescription((float)p.x,(float)p.y,track.track);
// set track ID and location
track.featureId = totalTracks++;
track.desc.setTo(d);
track.set(p);
// update list of active tracks
tracksPureKlt.add(track);
tracksSpawned.add(track);
}
} | java | public void spawnTracksFromDetected() {
// mark detected features with no matches as available
FastQueue<AssociatedIndex> matches = associate.getMatches();
int N = detector.getNumberOfFeatures();
for( int i = 0; i < N; i++ )
associated[i] = false;
for( AssociatedIndex i : matches.toList() ) {
associated[i.dst] = true;
}
// spawn new tracks for unassociated detected features
for( int i = 0; i < N; i++ ) {
if( associated[i])
continue;
Point2D_F64 p = detector.getLocation(i);
TD d = detectedDesc.get(i);
CombinedTrack<TD> track;
if( tracksUnused.size() > 0 ) {
track = tracksUnused.pop();
} else {
track = new CombinedTrack<>();
track.desc = detector.createDescription();
track.track = trackerKlt.createNewTrack();
}
// create the descriptor for tracking
trackerKlt.setDescription((float)p.x,(float)p.y,track.track);
// set track ID and location
track.featureId = totalTracks++;
track.desc.setTo(d);
track.set(p);
// update list of active tracks
tracksPureKlt.add(track);
tracksSpawned.add(track);
}
} | [
"public",
"void",
"spawnTracksFromDetected",
"(",
")",
"{",
"// mark detected features with no matches as available",
"FastQueue",
"<",
"AssociatedIndex",
">",
"matches",
"=",
"associate",
".",
"getMatches",
"(",
")",
";",
"int",
"N",
"=",
"detector",
".",
"getNumberO... | From the found interest points create new tracks. Tracks are only created at points
where there are no existing tracks.
Note: Must be called after {@link #associateAllToDetected}. | [
"From",
"the",
"found",
"interest",
"points",
"create",
"new",
"tracks",
".",
"Tracks",
"are",
"only",
"created",
"at",
"points",
"where",
"there",
"are",
"no",
"existing",
"tracks",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java#L163-L205 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java | CombinedTrackerScalePoint.associateToDetected | private void associateToDetected( List<CombinedTrack<TD>> known ) {
// initialize data structures
detectedDesc.reset();
knownDesc.reset();
// create a list of detected feature descriptions
int N = detector.getNumberOfFeatures();
for( int i = 0; i < N; i++ ) {
detectedDesc.add(detector.getDescription(i));
}
// create a list of previously created track descriptions
for( CombinedTrack<TD> t : known ) {
knownDesc.add(t.desc);
}
// associate features
associate.setSource(knownDesc);
associate.setDestination(detectedDesc);
associate.associate();
N = Math.max(known.size(),detector.getNumberOfFeatures());
if( associated.length < N )
associated = new boolean[N];
} | java | private void associateToDetected( List<CombinedTrack<TD>> known ) {
// initialize data structures
detectedDesc.reset();
knownDesc.reset();
// create a list of detected feature descriptions
int N = detector.getNumberOfFeatures();
for( int i = 0; i < N; i++ ) {
detectedDesc.add(detector.getDescription(i));
}
// create a list of previously created track descriptions
for( CombinedTrack<TD> t : known ) {
knownDesc.add(t.desc);
}
// associate features
associate.setSource(knownDesc);
associate.setDestination(detectedDesc);
associate.associate();
N = Math.max(known.size(),detector.getNumberOfFeatures());
if( associated.length < N )
associated = new boolean[N];
} | [
"private",
"void",
"associateToDetected",
"(",
"List",
"<",
"CombinedTrack",
"<",
"TD",
">",
">",
"known",
")",
"{",
"// initialize data structures",
"detectedDesc",
".",
"reset",
"(",
")",
";",
"knownDesc",
".",
"reset",
"(",
")",
";",
"// create a list of dete... | Associates pre-existing tracks to newly detected features
@param known List of known tracks | [
"Associates",
"pre",
"-",
"existing",
"tracks",
"to",
"newly",
"detected",
"features"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java#L213-L237 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java | CombinedTrackerScalePoint.associateAllToDetected | public void associateAllToDetected() {
// initialize data structures
List<CombinedTrack<TD>> all = new ArrayList<>();
all.addAll(tracksReactivated);
all.addAll(tracksDormant);
all.addAll(tracksPureKlt);
int numTainted = tracksReactivated.size() + tracksDormant.size();
tracksReactivated.clear();
tracksDormant.clear();
// detect features
detector.detect(input);
// associate features
associateToDetected(all);
FastQueue<AssociatedIndex> matches = associate.getMatches();
// See which features got respawned and which ones are made dormant
for( int i = 0; i < numTainted; i++ ) {
associated[i] = false;
}
for( AssociatedIndex a : matches.toList() ) {
// don't mess with pure-KLT tracks
if( a.src >= numTainted )
continue;
CombinedTrack<TD> t = all.get(a.src);
t.set(detector.getLocation(a.dst));
trackerKlt.setDescription((float) t.x, (float) t.y, t.track);
tracksReactivated.add(t);
associated[a.src] = true;
}
for( int i = 0; i < numTainted; i++ ) {
if( !associated[i] ) {
tracksDormant.add(all.get(i));
}
}
} | java | public void associateAllToDetected() {
// initialize data structures
List<CombinedTrack<TD>> all = new ArrayList<>();
all.addAll(tracksReactivated);
all.addAll(tracksDormant);
all.addAll(tracksPureKlt);
int numTainted = tracksReactivated.size() + tracksDormant.size();
tracksReactivated.clear();
tracksDormant.clear();
// detect features
detector.detect(input);
// associate features
associateToDetected(all);
FastQueue<AssociatedIndex> matches = associate.getMatches();
// See which features got respawned and which ones are made dormant
for( int i = 0; i < numTainted; i++ ) {
associated[i] = false;
}
for( AssociatedIndex a : matches.toList() ) {
// don't mess with pure-KLT tracks
if( a.src >= numTainted )
continue;
CombinedTrack<TD> t = all.get(a.src);
t.set(detector.getLocation(a.dst));
trackerKlt.setDescription((float) t.x, (float) t.y, t.track);
tracksReactivated.add(t);
associated[a.src] = true;
}
for( int i = 0; i < numTainted; i++ ) {
if( !associated[i] ) {
tracksDormant.add(all.get(i));
}
}
} | [
"public",
"void",
"associateAllToDetected",
"(",
")",
"{",
"// initialize data structures",
"List",
"<",
"CombinedTrack",
"<",
"TD",
">>",
"all",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"all",
".",
"addAll",
"(",
"tracksReactivated",
")",
";",
"all",
"... | Associate all tracks in any state to the latest observations. If a dormant track is associated it
will be reactivated. If a reactivated track is associated it's state will be updated. PureKLT
tracks are left unmodified. | [
"Associate",
"all",
"tracks",
"in",
"any",
"state",
"to",
"the",
"latest",
"observations",
".",
"If",
"a",
"dormant",
"track",
"is",
"associated",
"it",
"will",
"be",
"reactivated",
".",
"If",
"a",
"reactivated",
"track",
"is",
"associated",
"it",
"s",
"st... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java#L244-L286 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java | CombinedTrackerScalePoint.dropTrack | public boolean dropTrack( CombinedTrack<TD> track ) {
if( !tracksPureKlt.remove(track) )
if( !tracksReactivated.remove(track) )
if( !tracksDormant.remove(track) )
return false;
tracksUnused.add(track);
return true;
} | java | public boolean dropTrack( CombinedTrack<TD> track ) {
if( !tracksPureKlt.remove(track) )
if( !tracksReactivated.remove(track) )
if( !tracksDormant.remove(track) )
return false;
tracksUnused.add(track);
return true;
} | [
"public",
"boolean",
"dropTrack",
"(",
"CombinedTrack",
"<",
"TD",
">",
"track",
")",
"{",
"if",
"(",
"!",
"tracksPureKlt",
".",
"remove",
"(",
"track",
")",
")",
"if",
"(",
"!",
"tracksReactivated",
".",
"remove",
"(",
"track",
")",
")",
"if",
"(",
... | Stops tracking the specified track and recycles its data.
@param track The track being dropped
@return true if the track was being tracked and data was recycled false if not. | [
"Stops",
"tracking",
"the",
"specified",
"track",
"and",
"recycles",
"its",
"data",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java#L294-L302 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java | CombinedTrackerScalePoint.dropAllTracks | public void dropAllTracks() {
tracksUnused.addAll(tracksDormant);
tracksUnused.addAll(tracksPureKlt);
tracksUnused.addAll(tracksReactivated);
tracksSpawned.clear();
tracksPureKlt.clear();
tracksReactivated.clear();
tracksSpawned.clear();
tracksDormant.clear();
} | java | public void dropAllTracks() {
tracksUnused.addAll(tracksDormant);
tracksUnused.addAll(tracksPureKlt);
tracksUnused.addAll(tracksReactivated);
tracksSpawned.clear();
tracksPureKlt.clear();
tracksReactivated.clear();
tracksSpawned.clear();
tracksDormant.clear();
} | [
"public",
"void",
"dropAllTracks",
"(",
")",
"{",
"tracksUnused",
".",
"addAll",
"(",
"tracksDormant",
")",
";",
"tracksUnused",
".",
"addAll",
"(",
"tracksPureKlt",
")",
";",
"tracksUnused",
".",
"addAll",
"(",
"tracksReactivated",
")",
";",
"tracksSpawned",
... | Drops all tracks and recycles the data | [
"Drops",
"all",
"tracks",
"and",
"recycles",
"the",
"data"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/tracker/combined/CombinedTrackerScalePoint.java#L331-L341 | train |
lessthanoptimal/BoofCV | demonstrations/src/main/java/boofcv/demonstrations/feature/associate/VisualizeAssociationScoreApp.java | VisualizeAssociationScoreApp.processImage | private void processImage() {
final List<Point2D_F64> leftPts = new ArrayList<>();
final List<Point2D_F64> rightPts = new ArrayList<>();
final List<TupleDesc> leftDesc = new ArrayList<>();
final List<TupleDesc> rightDesc = new ArrayList<>();
final ProgressMonitor progressMonitor = new ProgressMonitor(this,
"Compute Feature Information",
"", 0, 4);
extractImageFeatures(progressMonitor, 0, imageLeft, leftDesc, leftPts);
extractImageFeatures(progressMonitor, 2, imageRight, rightDesc, rightPts);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressMonitor.close();
scorePanel.setScorer(controlPanel.getSelected());
scorePanel.setLocation(leftPts, rightPts, leftDesc, rightDesc);
repaint();
}
});
} | java | private void processImage() {
final List<Point2D_F64> leftPts = new ArrayList<>();
final List<Point2D_F64> rightPts = new ArrayList<>();
final List<TupleDesc> leftDesc = new ArrayList<>();
final List<TupleDesc> rightDesc = new ArrayList<>();
final ProgressMonitor progressMonitor = new ProgressMonitor(this,
"Compute Feature Information",
"", 0, 4);
extractImageFeatures(progressMonitor, 0, imageLeft, leftDesc, leftPts);
extractImageFeatures(progressMonitor, 2, imageRight, rightDesc, rightPts);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressMonitor.close();
scorePanel.setScorer(controlPanel.getSelected());
scorePanel.setLocation(leftPts, rightPts, leftDesc, rightDesc);
repaint();
}
});
} | [
"private",
"void",
"processImage",
"(",
")",
"{",
"final",
"List",
"<",
"Point2D_F64",
">",
"leftPts",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"final",
"List",
"<",
"Point2D_F64",
">",
"rightPts",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"fi... | Extracts image information and then passes that info onto scorePanel for display. Data is not
recycled to avoid threading issues. | [
"Extracts",
"image",
"information",
"and",
"then",
"passes",
"that",
"info",
"onto",
"scorePanel",
"for",
"display",
".",
"Data",
"is",
"not",
"recycled",
"to",
"avoid",
"threading",
"issues",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/demonstrations/src/main/java/boofcv/demonstrations/feature/associate/VisualizeAssociationScoreApp.java#L172-L192 | train |
lessthanoptimal/BoofCV | demonstrations/src/main/java/boofcv/demonstrations/feature/associate/VisualizeAssociationScoreApp.java | VisualizeAssociationScoreApp.extractImageFeatures | private void extractImageFeatures(final ProgressMonitor progressMonitor, final int progress,
T image,
List<TupleDesc> descs, List<Point2D_F64> locs) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressMonitor.setNote("Detecting");
}
});
detector.detect(image);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressMonitor.setProgress(progress + 1);
progressMonitor.setNote("Describing");
}
});
describe.setImage(image);
orientation.setImage(image);
// See if the detector can detect the feature's scale
if (detector.hasScale()) {
for (int i = 0; i < detector.getNumberOfFeatures(); i++) {
double yaw = 0;
Point2D_F64 pt = detector.getLocation(i);
double radius = detector.getRadius(i);
if (describe.requiresOrientation()) {
orientation.setObjectRadius(radius);
yaw = orientation.compute(pt.x, pt.y);
}
TupleDesc d = describe.createDescription();
if ( describe.process(pt.x, pt.y, yaw, radius, d) ) {
descs.add(d);
locs.add(pt.copy());
}
}
} else {
// just set the radius to one in this case
orientation.setObjectRadius(1);
for (int i = 0; i < detector.getNumberOfFeatures(); i++) {
double yaw = 0;
Point2D_F64 pt = detector.getLocation(i);
if (describe.requiresOrientation()) {
yaw = orientation.compute(pt.x, pt.y);
}
TupleDesc d = describe.createDescription();
if (describe.process(pt.x, pt.y, yaw, 1, d)) {
descs.add(d);
locs.add(pt.copy());
}
}
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressMonitor.setProgress(progress + 2);
}
});
} | java | private void extractImageFeatures(final ProgressMonitor progressMonitor, final int progress,
T image,
List<TupleDesc> descs, List<Point2D_F64> locs) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressMonitor.setNote("Detecting");
}
});
detector.detect(image);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressMonitor.setProgress(progress + 1);
progressMonitor.setNote("Describing");
}
});
describe.setImage(image);
orientation.setImage(image);
// See if the detector can detect the feature's scale
if (detector.hasScale()) {
for (int i = 0; i < detector.getNumberOfFeatures(); i++) {
double yaw = 0;
Point2D_F64 pt = detector.getLocation(i);
double radius = detector.getRadius(i);
if (describe.requiresOrientation()) {
orientation.setObjectRadius(radius);
yaw = orientation.compute(pt.x, pt.y);
}
TupleDesc d = describe.createDescription();
if ( describe.process(pt.x, pt.y, yaw, radius, d) ) {
descs.add(d);
locs.add(pt.copy());
}
}
} else {
// just set the radius to one in this case
orientation.setObjectRadius(1);
for (int i = 0; i < detector.getNumberOfFeatures(); i++) {
double yaw = 0;
Point2D_F64 pt = detector.getLocation(i);
if (describe.requiresOrientation()) {
yaw = orientation.compute(pt.x, pt.y);
}
TupleDesc d = describe.createDescription();
if (describe.process(pt.x, pt.y, yaw, 1, d)) {
descs.add(d);
locs.add(pt.copy());
}
}
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressMonitor.setProgress(progress + 2);
}
});
} | [
"private",
"void",
"extractImageFeatures",
"(",
"final",
"ProgressMonitor",
"progressMonitor",
",",
"final",
"int",
"progress",
",",
"T",
"image",
",",
"List",
"<",
"TupleDesc",
">",
"descs",
",",
"List",
"<",
"Point2D_F64",
">",
"locs",
")",
"{",
"SwingUtilit... | Detects the locations of the features in the image and extracts descriptions of each of
the features. | [
"Detects",
"the",
"locations",
"of",
"the",
"features",
"in",
"the",
"image",
"and",
"extracts",
"descriptions",
"of",
"each",
"of",
"the",
"features",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/demonstrations/src/main/java/boofcv/demonstrations/feature/associate/VisualizeAssociationScoreApp.java#L198-L257 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/flow/BroxWarpingSpacial.java | BroxWarpingSpacial.resizeForLayer | protected void resizeForLayer( int width , int height ) {
deriv1X.reshape(width,height);
deriv1Y.reshape(width,height);
deriv2X.reshape(width,height);
deriv2Y.reshape(width,height);
deriv2XX.reshape(width,height);
deriv2YY.reshape(width,height);
deriv2XY.reshape(width,height);
warpImage2.reshape(width,height);
warpDeriv2X.reshape(width,height);
warpDeriv2Y.reshape(width,height);
warpDeriv2XX.reshape(width,height);
warpDeriv2YY.reshape(width,height);
warpDeriv2XY.reshape(width,height);
derivFlowUX.reshape(width,height);
derivFlowUY.reshape(width,height);
derivFlowVX.reshape(width,height);
derivFlowVY.reshape(width,height);
psiData.reshape(width,height);
psiGradient.reshape(width,height);
psiSmooth.reshape(width,height);
divU.reshape(width,height);
divV.reshape(width,height);
divD.reshape(width,height);
du.reshape(width,height);
dv.reshape(width,height);
} | java | protected void resizeForLayer( int width , int height ) {
deriv1X.reshape(width,height);
deriv1Y.reshape(width,height);
deriv2X.reshape(width,height);
deriv2Y.reshape(width,height);
deriv2XX.reshape(width,height);
deriv2YY.reshape(width,height);
deriv2XY.reshape(width,height);
warpImage2.reshape(width,height);
warpDeriv2X.reshape(width,height);
warpDeriv2Y.reshape(width,height);
warpDeriv2XX.reshape(width,height);
warpDeriv2YY.reshape(width,height);
warpDeriv2XY.reshape(width,height);
derivFlowUX.reshape(width,height);
derivFlowUY.reshape(width,height);
derivFlowVX.reshape(width,height);
derivFlowVY.reshape(width,height);
psiData.reshape(width,height);
psiGradient.reshape(width,height);
psiSmooth.reshape(width,height);
divU.reshape(width,height);
divV.reshape(width,height);
divD.reshape(width,height);
du.reshape(width,height);
dv.reshape(width,height);
} | [
"protected",
"void",
"resizeForLayer",
"(",
"int",
"width",
",",
"int",
"height",
")",
"{",
"deriv1X",
".",
"reshape",
"(",
"width",
",",
"height",
")",
";",
"deriv1Y",
".",
"reshape",
"(",
"width",
",",
"height",
")",
";",
"deriv2X",
".",
"reshape",
"... | Resize images for the current layer being processed | [
"Resize",
"images",
"for",
"the",
"current",
"layer",
"being",
"processed"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/flow/BroxWarpingSpacial.java#L182-L213 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/flow/BroxWarpingSpacial.java | BroxWarpingSpacial.computePsiSmooth | private void computePsiSmooth(GrayF32 ux , GrayF32 uy , GrayF32 vx , GrayF32 vy ,
GrayF32 psiSmooth ) {
int N = derivFlowUX.width * derivFlowUX.height;
for( int i = 0; i < N; i++ ) {
float vux = ux.data[i];
float vuy = uy.data[i];
float vvx = vx.data[i];
float vvy = vy.data[i];
float mu = vux*vux + vuy*vuy;
float mv = vvx*vvx + vvy*vvy;
psiSmooth.data[i] = (float)(1.0/(2.0*Math.sqrt(mu + mv + EPSILON*EPSILON)));
}
} | java | private void computePsiSmooth(GrayF32 ux , GrayF32 uy , GrayF32 vx , GrayF32 vy ,
GrayF32 psiSmooth ) {
int N = derivFlowUX.width * derivFlowUX.height;
for( int i = 0; i < N; i++ ) {
float vux = ux.data[i];
float vuy = uy.data[i];
float vvx = vx.data[i];
float vvy = vy.data[i];
float mu = vux*vux + vuy*vuy;
float mv = vvx*vvx + vvy*vvy;
psiSmooth.data[i] = (float)(1.0/(2.0*Math.sqrt(mu + mv + EPSILON*EPSILON)));
}
} | [
"private",
"void",
"computePsiSmooth",
"(",
"GrayF32",
"ux",
",",
"GrayF32",
"uy",
",",
"GrayF32",
"vx",
",",
"GrayF32",
"vy",
",",
"GrayF32",
"psiSmooth",
")",
"{",
"int",
"N",
"=",
"derivFlowUX",
".",
"width",
"*",
"derivFlowUX",
".",
"height",
";",
"f... | Equation 5. Psi_s | [
"Equation",
"5",
".",
"Psi_s"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/flow/BroxWarpingSpacial.java#L377-L392 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/flow/BroxWarpingSpacial.java | BroxWarpingSpacial.computePsiDataPsiGradient | protected void computePsiDataPsiGradient(GrayF32 image1, GrayF32 image2,
GrayF32 deriv1x, GrayF32 deriv1y,
GrayF32 deriv2x, GrayF32 deriv2y,
GrayF32 deriv2xx, GrayF32 deriv2yy, GrayF32 deriv2xy,
GrayF32 du, GrayF32 dv,
GrayF32 psiData, GrayF32 psiGradient ) {
int N = image1.width * image1.height;
for( int i = 0; i < N; i++ ) {
float du_ = du.data[i];
float dv_ = dv.data[i];
// compute Psi-data
float taylor2 = image2.data[i] + deriv2x.data[i]*du_ + deriv2y.data[i]*dv_;
float v = taylor2 - image1.data[i];
psiData.data[i] = (float)(1.0/(2.0*Math.sqrt(v*v + EPSILON*EPSILON)));
// compute Psi-gradient
float dIx = deriv2x.data[i] + deriv2xx.data[i]*du_ + deriv2xy.data[i]*dv_ - deriv1x.data[i];
float dIy = deriv2y.data[i] + deriv2xy.data[i]*du_ + deriv2yy.data[i]*dv_ - deriv1y.data[i];
float dI2 = dIx*dIx + dIy*dIy;
psiGradient.data[i] = (float)(1.0/(2.0*Math.sqrt(dI2 + EPSILON*EPSILON)));
}
} | java | protected void computePsiDataPsiGradient(GrayF32 image1, GrayF32 image2,
GrayF32 deriv1x, GrayF32 deriv1y,
GrayF32 deriv2x, GrayF32 deriv2y,
GrayF32 deriv2xx, GrayF32 deriv2yy, GrayF32 deriv2xy,
GrayF32 du, GrayF32 dv,
GrayF32 psiData, GrayF32 psiGradient ) {
int N = image1.width * image1.height;
for( int i = 0; i < N; i++ ) {
float du_ = du.data[i];
float dv_ = dv.data[i];
// compute Psi-data
float taylor2 = image2.data[i] + deriv2x.data[i]*du_ + deriv2y.data[i]*dv_;
float v = taylor2 - image1.data[i];
psiData.data[i] = (float)(1.0/(2.0*Math.sqrt(v*v + EPSILON*EPSILON)));
// compute Psi-gradient
float dIx = deriv2x.data[i] + deriv2xx.data[i]*du_ + deriv2xy.data[i]*dv_ - deriv1x.data[i];
float dIy = deriv2y.data[i] + deriv2xy.data[i]*du_ + deriv2yy.data[i]*dv_ - deriv1y.data[i];
float dI2 = dIx*dIx + dIy*dIy;
psiGradient.data[i] = (float)(1.0/(2.0*Math.sqrt(dI2 + EPSILON*EPSILON)));
}
} | [
"protected",
"void",
"computePsiDataPsiGradient",
"(",
"GrayF32",
"image1",
",",
"GrayF32",
"image2",
",",
"GrayF32",
"deriv1x",
",",
"GrayF32",
"deriv1y",
",",
"GrayF32",
"deriv2x",
",",
"GrayF32",
"deriv2y",
",",
"GrayF32",
"deriv2xx",
",",
"GrayF32",
"deriv2yy"... | Compute Psi-data using equation 6 and approximation in equation 5 | [
"Compute",
"Psi",
"-",
"data",
"using",
"equation",
"6",
"and",
"approximation",
"in",
"equation",
"5"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/flow/BroxWarpingSpacial.java#L397-L423 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/flow/BroxWarpingSpacial.java | BroxWarpingSpacial.computeDivUVD | private void computeDivUVD(GrayF32 u , GrayF32 v , GrayF32 psi ,
GrayF32 divU , GrayF32 divV , GrayF32 divD ) {
final int stride = psi.stride;
// compute the inside pixel
for (int y = 1; y < psi.height-1; y++) {
// index of the current pixel
int index = y*stride + 1;
for (int x = 1; x < psi.width-1; x++ , index++) {
float psi_index = psi.data[index];
float coef0 = 0.5f*(psi.data[index+1] + psi_index);
float coef1 = 0.5f*(psi.data[index-1] + psi_index);
float coef2 = 0.5f*(psi.data[index+stride] + psi_index);
float coef3 = 0.5f*(psi.data[index-stride] + psi_index);
float u_index = u.data[index];
divU.data[index] = coef0*(u.data[index+1] - u_index) + coef1*(u.data[index-1] - u_index) +
coef2*(u.data[index+stride] - u_index) + coef3*(u.data[index-stride] - u_index);
float v_index = v.data[index];
divV.data[index] = coef0*(v.data[index+1] - v_index) + coef1*(v.data[index-1] - v_index) +
coef2*(v.data[index+stride] - v_index) + coef3*(v.data[index-stride] - v_index);
divD.data[index] = coef0 + coef1 + coef2 + coef3;
}
}
// handle the image borders
for( int x = 0; x < psi.width; x++ ) {
computeDivUVD_safe(x,0,u,v,psi,divU,divV,divD);
computeDivUVD_safe(x,psi.height-1,u,v,psi,divU,divV,divD);
}
for( int y = 1; y < psi.height-1; y++ ) {
computeDivUVD_safe(0,y,u,v,psi,divU,divV,divD);
computeDivUVD_safe(psi.width-1,y,u,v,psi,divU,divV,divD);
}
} | java | private void computeDivUVD(GrayF32 u , GrayF32 v , GrayF32 psi ,
GrayF32 divU , GrayF32 divV , GrayF32 divD ) {
final int stride = psi.stride;
// compute the inside pixel
for (int y = 1; y < psi.height-1; y++) {
// index of the current pixel
int index = y*stride + 1;
for (int x = 1; x < psi.width-1; x++ , index++) {
float psi_index = psi.data[index];
float coef0 = 0.5f*(psi.data[index+1] + psi_index);
float coef1 = 0.5f*(psi.data[index-1] + psi_index);
float coef2 = 0.5f*(psi.data[index+stride] + psi_index);
float coef3 = 0.5f*(psi.data[index-stride] + psi_index);
float u_index = u.data[index];
divU.data[index] = coef0*(u.data[index+1] - u_index) + coef1*(u.data[index-1] - u_index) +
coef2*(u.data[index+stride] - u_index) + coef3*(u.data[index-stride] - u_index);
float v_index = v.data[index];
divV.data[index] = coef0*(v.data[index+1] - v_index) + coef1*(v.data[index-1] - v_index) +
coef2*(v.data[index+stride] - v_index) + coef3*(v.data[index-stride] - v_index);
divD.data[index] = coef0 + coef1 + coef2 + coef3;
}
}
// handle the image borders
for( int x = 0; x < psi.width; x++ ) {
computeDivUVD_safe(x,0,u,v,psi,divU,divV,divD);
computeDivUVD_safe(x,psi.height-1,u,v,psi,divU,divV,divD);
}
for( int y = 1; y < psi.height-1; y++ ) {
computeDivUVD_safe(0,y,u,v,psi,divU,divV,divD);
computeDivUVD_safe(psi.width-1,y,u,v,psi,divU,divV,divD);
}
} | [
"private",
"void",
"computeDivUVD",
"(",
"GrayF32",
"u",
",",
"GrayF32",
"v",
",",
"GrayF32",
"psi",
",",
"GrayF32",
"divU",
",",
"GrayF32",
"divV",
",",
"GrayF32",
"divD",
")",
"{",
"final",
"int",
"stride",
"=",
"psi",
".",
"stride",
";",
"// compute t... | Computes the divergence for u,v, and d. Equation 8 and Equation 10. | [
"Computes",
"the",
"divergence",
"for",
"u",
"v",
"and",
"d",
".",
"Equation",
"8",
"and",
"Equation",
"10",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/flow/BroxWarpingSpacial.java#L428-L471 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java | TldTemplateMatching.reset | public void reset() {
unused.addAll(templateNegative);
unused.addAll(templatePositive);
templateNegative.clear();
templatePositive.clear();
} | java | public void reset() {
unused.addAll(templateNegative);
unused.addAll(templatePositive);
templateNegative.clear();
templatePositive.clear();
} | [
"public",
"void",
"reset",
"(",
")",
"{",
"unused",
".",
"addAll",
"(",
"templateNegative",
")",
";",
"unused",
".",
"addAll",
"(",
"templatePositive",
")",
";",
"templateNegative",
".",
"clear",
"(",
")",
";",
"templatePositive",
".",
"clear",
"(",
")",
... | Discard previous results and puts it back into its initial state | [
"Discard",
"previous",
"results",
"and",
"puts",
"it",
"back",
"into",
"its",
"initial",
"state"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java#L63-L68 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java | TldTemplateMatching.addDescriptor | public void addDescriptor( boolean positive , ImageRectangle rect ) {
addDescriptor(positive, rect.x0, rect.y0, rect.x1, rect.y1);
} | java | public void addDescriptor( boolean positive , ImageRectangle rect ) {
addDescriptor(positive, rect.x0, rect.y0, rect.x1, rect.y1);
} | [
"public",
"void",
"addDescriptor",
"(",
"boolean",
"positive",
",",
"ImageRectangle",
"rect",
")",
"{",
"addDescriptor",
"(",
"positive",
",",
"rect",
".",
"x0",
",",
"rect",
".",
"y0",
",",
"rect",
".",
"x1",
",",
"rect",
".",
"y1",
")",
";",
"}"
] | Creates a new descriptor for the specified region
@param positive if it is a positive or negative example | [
"Creates",
"a",
"new",
"descriptor",
"for",
"the",
"specified",
"region"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java#L84-L87 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java | TldTemplateMatching.addDescriptor | private void addDescriptor(boolean positive, NccFeature f) {
// avoid adding the same descriptor twice or adding contradicting results
if( positive)
if( distance(f,templatePositive) < 0.05 ) {
return;
}
if( !positive) {
if( distance(f,templateNegative) < 0.05 ) {
return;
}
// a positive positive can have very bad affects on tracking, try to avoid learning a positive
// example as a negative one
if( distance(f,templatePositive) < 0.05 ) {
return;
}
}
if( positive )
templatePositive.add(f);
else
templateNegative.add(f);
} | java | private void addDescriptor(boolean positive, NccFeature f) {
// avoid adding the same descriptor twice or adding contradicting results
if( positive)
if( distance(f,templatePositive) < 0.05 ) {
return;
}
if( !positive) {
if( distance(f,templateNegative) < 0.05 ) {
return;
}
// a positive positive can have very bad affects on tracking, try to avoid learning a positive
// example as a negative one
if( distance(f,templatePositive) < 0.05 ) {
return;
}
}
if( positive )
templatePositive.add(f);
else
templateNegative.add(f);
} | [
"private",
"void",
"addDescriptor",
"(",
"boolean",
"positive",
",",
"NccFeature",
"f",
")",
"{",
"// avoid adding the same descriptor twice or adding contradicting results",
"if",
"(",
"positive",
")",
"if",
"(",
"distance",
"(",
"f",
",",
"templatePositive",
")",
"<... | Adds a descriptor to the positive or negative list. If it is very similar to an existing one it is not
added. Look at code for details
@param positive true for positive list and false for negative list
@param f The feature which is to be added | [
"Adds",
"a",
"descriptor",
"to",
"the",
"positive",
"or",
"negative",
"list",
".",
"If",
"it",
"is",
"very",
"similar",
"to",
"an",
"existing",
"one",
"it",
"is",
"not",
"added",
".",
"Look",
"at",
"code",
"for",
"details"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java#L103-L124 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java | TldTemplateMatching.computeNccDescriptor | public void computeNccDescriptor( NccFeature f , float x0 , float y0 , float x1 , float y1 ) {
double mean = 0;
float widthStep = (x1-x0)/15.0f;
float heightStep = (y1-y0)/15.0f;
// compute the mean value
int index = 0;
for( int y = 0; y < 15; y++ ) {
float sampleY = y0 + y*heightStep;
for( int x = 0; x < 15; x++ ) {
mean += f.value[index++] = interpolate.get_fast(x0 + x * widthStep, sampleY);
}
}
mean /= 15*15;
// compute the variance and save the difference from the mean
double variance = 0;
index = 0;
for( int y = 0; y < 15; y++ ) {
for( int x = 0; x < 15; x++ ) {
double v = f.value[index++] -= mean;
variance += v*v;
}
}
variance /= 15*15;
f.mean = mean;
f.sigma = Math.sqrt(variance);
} | java | public void computeNccDescriptor( NccFeature f , float x0 , float y0 , float x1 , float y1 ) {
double mean = 0;
float widthStep = (x1-x0)/15.0f;
float heightStep = (y1-y0)/15.0f;
// compute the mean value
int index = 0;
for( int y = 0; y < 15; y++ ) {
float sampleY = y0 + y*heightStep;
for( int x = 0; x < 15; x++ ) {
mean += f.value[index++] = interpolate.get_fast(x0 + x * widthStep, sampleY);
}
}
mean /= 15*15;
// compute the variance and save the difference from the mean
double variance = 0;
index = 0;
for( int y = 0; y < 15; y++ ) {
for( int x = 0; x < 15; x++ ) {
double v = f.value[index++] -= mean;
variance += v*v;
}
}
variance /= 15*15;
f.mean = mean;
f.sigma = Math.sqrt(variance);
} | [
"public",
"void",
"computeNccDescriptor",
"(",
"NccFeature",
"f",
",",
"float",
"x0",
",",
"float",
"y0",
",",
"float",
"x1",
",",
"float",
"y1",
")",
"{",
"double",
"mean",
"=",
"0",
";",
"float",
"widthStep",
"=",
"(",
"x1",
"-",
"x0",
")",
"/",
... | Computes the NCC descriptor by sample points at evenly spaced distances inside the rectangle | [
"Computes",
"the",
"NCC",
"descriptor",
"by",
"sample",
"points",
"at",
"evenly",
"spaced",
"distances",
"inside",
"the",
"rectangle"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java#L129-L156 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java | TldTemplateMatching.createDescriptor | public NccFeature createDescriptor() {
NccFeature f;
if( unused.isEmpty() )
f = new NccFeature(15*15);
else
f = unused.pop();
return f;
} | java | public NccFeature createDescriptor() {
NccFeature f;
if( unused.isEmpty() )
f = new NccFeature(15*15);
else
f = unused.pop();
return f;
} | [
"public",
"NccFeature",
"createDescriptor",
"(",
")",
"{",
"NccFeature",
"f",
";",
"if",
"(",
"unused",
".",
"isEmpty",
"(",
")",
")",
"f",
"=",
"new",
"NccFeature",
"(",
"15",
"*",
"15",
")",
";",
"else",
"f",
"=",
"unused",
".",
"pop",
"(",
")",
... | Creates a new descriptor or recycles an old one | [
"Creates",
"a",
"new",
"descriptor",
"or",
"recycles",
"an",
"old",
"one"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java#L161-L168 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java | TldTemplateMatching.computeConfidence | public double computeConfidence( int x0 , int y0 , int x1 , int y1 ) {
computeNccDescriptor(observed,x0,y0,x1,y1);
// distance from each set of templates
if( templateNegative.size() > 0 && templatePositive.size() > 0 ) {
double distancePositive = distance(observed,templatePositive);
double distanceNegative = distance(observed,templateNegative);
return distanceNegative/(distanceNegative + distancePositive);
} else if( templatePositive.size() > 0 ) {
return 1.0-distance(observed,templatePositive);
} else {
return distance(observed,templateNegative);
}
} | java | public double computeConfidence( int x0 , int y0 , int x1 , int y1 ) {
computeNccDescriptor(observed,x0,y0,x1,y1);
// distance from each set of templates
if( templateNegative.size() > 0 && templatePositive.size() > 0 ) {
double distancePositive = distance(observed,templatePositive);
double distanceNegative = distance(observed,templateNegative);
return distanceNegative/(distanceNegative + distancePositive);
} else if( templatePositive.size() > 0 ) {
return 1.0-distance(observed,templatePositive);
} else {
return distance(observed,templateNegative);
}
} | [
"public",
"double",
"computeConfidence",
"(",
"int",
"x0",
",",
"int",
"y0",
",",
"int",
"x1",
",",
"int",
"y1",
")",
"{",
"computeNccDescriptor",
"(",
"observed",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
")",
";",
"// distance from each set of template... | Compute a value which indicates how confident the specified region is to be a member of the positive set.
The confidence value is from 0 to 1. 1 indicates 100% confidence.
Positive and negative templates are used to compute the confidence value. Only the point in each set
which is closest to the specified region are used in the calculation.
@return value from 0 to 1, where higher values are more confident | [
"Compute",
"a",
"value",
"which",
"indicates",
"how",
"confident",
"the",
"specified",
"region",
"is",
"to",
"be",
"a",
"member",
"of",
"the",
"positive",
"set",
".",
"The",
"confidence",
"value",
"is",
"from",
"0",
"to",
"1",
".",
"1",
"indicates",
"100... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java#L179-L194 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java | TldTemplateMatching.computeConfidence | public double computeConfidence( ImageRectangle r ) {
return computeConfidence(r.x0,r.y0,r.x1,r.y1);
} | java | public double computeConfidence( ImageRectangle r ) {
return computeConfidence(r.x0,r.y0,r.x1,r.y1);
} | [
"public",
"double",
"computeConfidence",
"(",
"ImageRectangle",
"r",
")",
"{",
"return",
"computeConfidence",
"(",
"r",
".",
"x0",
",",
"r",
".",
"y0",
",",
"r",
".",
"x1",
",",
"r",
".",
"y1",
")",
";",
"}"
] | see the other function with the same name | [
"see",
"the",
"other",
"function",
"with",
"the",
"same",
"name"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java#L199-L201 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java | TldTemplateMatching.distance | public double distance( NccFeature observed , List<NccFeature> candidates ) {
double maximum = -Double.MAX_VALUE;
// The feature which has the best fit will maximize the score
for( NccFeature f : candidates ) {
double score = DescriptorDistance.ncc(observed, f);
if( score > maximum )
maximum = score;
}
return 1-0.5*(maximum + 1);
} | java | public double distance( NccFeature observed , List<NccFeature> candidates ) {
double maximum = -Double.MAX_VALUE;
// The feature which has the best fit will maximize the score
for( NccFeature f : candidates ) {
double score = DescriptorDistance.ncc(observed, f);
if( score > maximum )
maximum = score;
}
return 1-0.5*(maximum + 1);
} | [
"public",
"double",
"distance",
"(",
"NccFeature",
"observed",
",",
"List",
"<",
"NccFeature",
">",
"candidates",
")",
"{",
"double",
"maximum",
"=",
"-",
"Double",
".",
"MAX_VALUE",
";",
"// The feature which has the best fit will maximize the score",
"for",
"(",
"... | Computes the best distance to 'observed' from the candidate list.
@param observed Feature being matched
@param candidates Set of candidate matches
@return score from 0 to 1, where lower is closer | [
"Computes",
"the",
"best",
"distance",
"to",
"observed",
"from",
"the",
"candidate",
"list",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldTemplateMatching.java#L209-L221 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/chess/DetectChessboardCornersPyramid.java | DetectChessboardCornersPyramid.process | public void process(GrayF32 input ) {
constructPyramid(input);
corners.reset();
// top to bottom. This way the intensity image is at the input image's scale. Which is useful
// for visualiztion purposes
double scale = Math.pow(2.0,pyramid.size()-1);
for (int level = pyramid.size()-1; level >= 0; level--) {
// find the corners
detector.process(pyramid.get(level));
// Add found corners to this level's list
PyramidLevel featsLevel = featureLevels.get(level);
FastQueue<ChessboardCorner> corners = detector.getCorners();
featsLevel.corners.reset();
for (int i = 0; i < corners.size; i++) {
ChessboardCorner cf = corners.get(i);
// convert the coordinate into input image coordinates
double x = cf.x*scale;
double y = cf.y*scale;
// Compensate for how the pyramid was computed using an average down sample. It shifts
// the coordinate system.
// if( scale > 1 ) {
// x += 0.5*scale;
// y += 0.5*scale;
// }
ChessboardCorner cl = featsLevel.corners.grow();
cl.first = true;
cl.set(x,y,cf.orientation,cf.intensity);
}
scale /= 2.0;
}
// Create a combined set of features from all the levels. Only add each feature once by searching
// for it in the next level down
for (int levelIdx = 0; levelIdx < pyramid.size(); levelIdx++) {
PyramidLevel level0 = featureLevels.get(levelIdx);
// mark features in the next level as seen if they match ones in this level
if( levelIdx+1< pyramid.size() ) {
PyramidLevel level1 = featureLevels.get(levelIdx+1);
markSeenAsFalse(level0.corners,level1.corners);
}
}
for (int levelIdx = 0; levelIdx < pyramid.size(); levelIdx++) {
PyramidLevel level = featureLevels.get(levelIdx);
// only add corners if they were first seen in this level
for (int i = 0; i < level.corners.size; i++) {
ChessboardCorner c = level.corners.get(i);
if( c.first )
corners.grow().set(c);
}
}
} | java | public void process(GrayF32 input ) {
constructPyramid(input);
corners.reset();
// top to bottom. This way the intensity image is at the input image's scale. Which is useful
// for visualiztion purposes
double scale = Math.pow(2.0,pyramid.size()-1);
for (int level = pyramid.size()-1; level >= 0; level--) {
// find the corners
detector.process(pyramid.get(level));
// Add found corners to this level's list
PyramidLevel featsLevel = featureLevels.get(level);
FastQueue<ChessboardCorner> corners = detector.getCorners();
featsLevel.corners.reset();
for (int i = 0; i < corners.size; i++) {
ChessboardCorner cf = corners.get(i);
// convert the coordinate into input image coordinates
double x = cf.x*scale;
double y = cf.y*scale;
// Compensate for how the pyramid was computed using an average down sample. It shifts
// the coordinate system.
// if( scale > 1 ) {
// x += 0.5*scale;
// y += 0.5*scale;
// }
ChessboardCorner cl = featsLevel.corners.grow();
cl.first = true;
cl.set(x,y,cf.orientation,cf.intensity);
}
scale /= 2.0;
}
// Create a combined set of features from all the levels. Only add each feature once by searching
// for it in the next level down
for (int levelIdx = 0; levelIdx < pyramid.size(); levelIdx++) {
PyramidLevel level0 = featureLevels.get(levelIdx);
// mark features in the next level as seen if they match ones in this level
if( levelIdx+1< pyramid.size() ) {
PyramidLevel level1 = featureLevels.get(levelIdx+1);
markSeenAsFalse(level0.corners,level1.corners);
}
}
for (int levelIdx = 0; levelIdx < pyramid.size(); levelIdx++) {
PyramidLevel level = featureLevels.get(levelIdx);
// only add corners if they were first seen in this level
for (int i = 0; i < level.corners.size; i++) {
ChessboardCorner c = level.corners.get(i);
if( c.first )
corners.grow().set(c);
}
}
} | [
"public",
"void",
"process",
"(",
"GrayF32",
"input",
")",
"{",
"constructPyramid",
"(",
"input",
")",
";",
"corners",
".",
"reset",
"(",
")",
";",
"// top to bottom. This way the intensity image is at the input image's scale. Which is useful",
"// for visualiztion purposes",... | Detects corner features inside the input gray scale image. | [
"Detects",
"corner",
"features",
"inside",
"the",
"input",
"gray",
"scale",
"image",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/chess/DetectChessboardCornersPyramid.java#L73-L131 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/chess/DetectChessboardCornersPyramid.java | DetectChessboardCornersPyramid.markSeenAsFalse | void markSeenAsFalse(FastQueue<ChessboardCorner> corners0 , FastQueue<ChessboardCorner> corners1 ) {
nn.setPoints(corners1.toList(),false);
// radius of the blob in the intensity image is 2*kernelRadius
int radius = detector.shiRadius *2+1;
for (int i = 0; i < corners0.size; i++) {
ChessboardCorner c0 = corners0.get(i);
nnSearch.findNearest(c0,radius,5,nnResults);
// TODO does it ever find multiple matches?
// Could make this smarter by looking at the orientation too
for (int j = 0; j < nnResults.size; j++) {
ChessboardCorner c1 = nnResults.get(j).point;
// if the current one wasn't first then none of its children can be first
if( !c0.first ) {
c1.first = false;
} else if( c1.intensity < c0.intensity ) {
// keeping the one with the best intensity score seems to help. Formally test this idea
c1.first = false;
} else {
c0.first = false;
}
}
}
} | java | void markSeenAsFalse(FastQueue<ChessboardCorner> corners0 , FastQueue<ChessboardCorner> corners1 ) {
nn.setPoints(corners1.toList(),false);
// radius of the blob in the intensity image is 2*kernelRadius
int radius = detector.shiRadius *2+1;
for (int i = 0; i < corners0.size; i++) {
ChessboardCorner c0 = corners0.get(i);
nnSearch.findNearest(c0,radius,5,nnResults);
// TODO does it ever find multiple matches?
// Could make this smarter by looking at the orientation too
for (int j = 0; j < nnResults.size; j++) {
ChessboardCorner c1 = nnResults.get(j).point;
// if the current one wasn't first then none of its children can be first
if( !c0.first ) {
c1.first = false;
} else if( c1.intensity < c0.intensity ) {
// keeping the one with the best intensity score seems to help. Formally test this idea
c1.first = false;
} else {
c0.first = false;
}
}
}
} | [
"void",
"markSeenAsFalse",
"(",
"FastQueue",
"<",
"ChessboardCorner",
">",
"corners0",
",",
"FastQueue",
"<",
"ChessboardCorner",
">",
"corners1",
")",
"{",
"nn",
".",
"setPoints",
"(",
"corners1",
".",
"toList",
"(",
")",
",",
"false",
")",
";",
"// radius ... | Finds corners in list 1 which match corners in list 0. If the feature in list 0 has already been
seen then the feature in list 1 will be marked as seen. Otherwise the feature which is the most intense
is marked as first. | [
"Finds",
"corners",
"in",
"list",
"1",
"which",
"match",
"corners",
"in",
"list",
"0",
".",
"If",
"the",
"feature",
"in",
"list",
"0",
"has",
"already",
"been",
"seen",
"then",
"the",
"feature",
"in",
"list",
"1",
"will",
"be",
"marked",
"as",
"seen",
... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/chess/DetectChessboardCornersPyramid.java#L138-L162 | train |
lessthanoptimal/BoofCV | demonstrations/src/main/java/boofcv/demonstrations/fiducial/DetectQrCodeApp.java | DetectQrCodeApp.processImage | @Override
public void processImage(int sourceID, long frameID, final BufferedImage buffered, ImageBase input) {
System.out.flush();
synchronized (bufferedImageLock) {
original = ConvertBufferedImage.checkCopy(buffered, original);
work = ConvertBufferedImage.checkDeclare(buffered, work);
}
if( saveRequested ) {
saveInputImage();
saveRequested = false;
}
final double timeInSeconds;
// TODO Copy all data that's visualized outside so that GUI doesn't lock
synchronized (this) {
long before = System.nanoTime();
detector.process((T)input);
long after = System.nanoTime();
timeInSeconds = (after-before)*1e-9;
}
// create a local copy so that gui and processing thread's dont conflict
synchronized (detected) {
this.detected.reset();
for (QrCode d : detector.getDetections()) {
this.detected.grow().set(d);
}
this.failures.reset();
for (QrCode d : detector.getFailures()) {
if( d.failureCause.ordinal() >= QrCode.Failure.READING_BITS.ordinal())
this.failures.grow().set(d);
}
// System.out.println("Failed "+failures.size());
// for( QrCode qr : failures.toList() ) {
// System.out.println(" cause "+qr.failureCause);
// }
}
controlPanel.polygonPanel.thresholdPanel.updateHistogram((T)input);
SwingUtilities.invokeLater(() -> {
controls.setProcessingTimeS(timeInSeconds);
viewUpdated();
synchronized (detected) {
controlPanel.messagePanel.updateList(detected.toList(),failures.toList());
}
});
} | java | @Override
public void processImage(int sourceID, long frameID, final BufferedImage buffered, ImageBase input) {
System.out.flush();
synchronized (bufferedImageLock) {
original = ConvertBufferedImage.checkCopy(buffered, original);
work = ConvertBufferedImage.checkDeclare(buffered, work);
}
if( saveRequested ) {
saveInputImage();
saveRequested = false;
}
final double timeInSeconds;
// TODO Copy all data that's visualized outside so that GUI doesn't lock
synchronized (this) {
long before = System.nanoTime();
detector.process((T)input);
long after = System.nanoTime();
timeInSeconds = (after-before)*1e-9;
}
// create a local copy so that gui and processing thread's dont conflict
synchronized (detected) {
this.detected.reset();
for (QrCode d : detector.getDetections()) {
this.detected.grow().set(d);
}
this.failures.reset();
for (QrCode d : detector.getFailures()) {
if( d.failureCause.ordinal() >= QrCode.Failure.READING_BITS.ordinal())
this.failures.grow().set(d);
}
// System.out.println("Failed "+failures.size());
// for( QrCode qr : failures.toList() ) {
// System.out.println(" cause "+qr.failureCause);
// }
}
controlPanel.polygonPanel.thresholdPanel.updateHistogram((T)input);
SwingUtilities.invokeLater(() -> {
controls.setProcessingTimeS(timeInSeconds);
viewUpdated();
synchronized (detected) {
controlPanel.messagePanel.updateList(detected.toList(),failures.toList());
}
});
} | [
"@",
"Override",
"public",
"void",
"processImage",
"(",
"int",
"sourceID",
",",
"long",
"frameID",
",",
"final",
"BufferedImage",
"buffered",
",",
"ImageBase",
"input",
")",
"{",
"System",
".",
"out",
".",
"flush",
"(",
")",
";",
"synchronized",
"(",
"buff... | Override this function so that it doesn't threshold the image twice | [
"Override",
"this",
"function",
"so",
"that",
"it",
"doesn",
"t",
"threshold",
"the",
"image",
"twice"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/demonstrations/src/main/java/boofcv/demonstrations/fiducial/DetectQrCodeApp.java#L191-L241 | train |
lessthanoptimal/BoofCV | main/boofcv-calibration/src/main/java/boofcv/alg/geo/calibration/Zhang99ComputeTargetHomography.java | Zhang99ComputeTargetHomography.computeHomography | public boolean computeHomography( CalibrationObservation observedPoints )
{
if( observedPoints.size() < 4)
throw new IllegalArgumentException("At least 4 points needed in each set of observations. " +
" Filter these first please");
List<AssociatedPair> pairs = new ArrayList<>();
for( int i = 0; i < observedPoints.size(); i++ ) {
int which = observedPoints.get(i).index;
Point2D_F64 obs = observedPoints.get(i);
pairs.add( new AssociatedPair(worldPoints.get(which),obs,true));
}
if( !computeHomography.process(pairs,found) )
return false;
// todo do non-linear refinement. Take advantage of coordinates being fixed
return true;
} | java | public boolean computeHomography( CalibrationObservation observedPoints )
{
if( observedPoints.size() < 4)
throw new IllegalArgumentException("At least 4 points needed in each set of observations. " +
" Filter these first please");
List<AssociatedPair> pairs = new ArrayList<>();
for( int i = 0; i < observedPoints.size(); i++ ) {
int which = observedPoints.get(i).index;
Point2D_F64 obs = observedPoints.get(i);
pairs.add( new AssociatedPair(worldPoints.get(which),obs,true));
}
if( !computeHomography.process(pairs,found) )
return false;
// todo do non-linear refinement. Take advantage of coordinates being fixed
return true;
} | [
"public",
"boolean",
"computeHomography",
"(",
"CalibrationObservation",
"observedPoints",
")",
"{",
"if",
"(",
"observedPoints",
".",
"size",
"(",
")",
"<",
"4",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"At least 4 points needed in each set of observations... | Computes the homography from a list of detected grid points in the image. The
order of the grid points is important and must follow the expected row major
starting at the top left.
@param observedPoints List of ordered detected grid points in image pixels.
@return True if it computed a Homography and false if it failed to compute a homography matrix. | [
"Computes",
"the",
"homography",
"from",
"a",
"list",
"of",
"detected",
"grid",
"points",
"in",
"the",
"image",
".",
"The",
"order",
"of",
"the",
"grid",
"points",
"is",
"important",
"and",
"must",
"follow",
"the",
"expected",
"row",
"major",
"starting",
"... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-calibration/src/main/java/boofcv/alg/geo/calibration/Zhang99ComputeTargetHomography.java#L65-L85 | train |
lessthanoptimal/BoofCV | main/boofcv-types/src/main/java/boofcv/concurrency/FWorkArrays.java | FWorkArrays.recycle | public synchronized void recycle( float[] array ) {
if( array.length != length ) {
throw new IllegalArgumentException("Unexpected array length. Expected "+length+" found "+array.length);
}
storage.add(array);
} | java | public synchronized void recycle( float[] array ) {
if( array.length != length ) {
throw new IllegalArgumentException("Unexpected array length. Expected "+length+" found "+array.length);
}
storage.add(array);
} | [
"public",
"synchronized",
"void",
"recycle",
"(",
"float",
"[",
"]",
"array",
")",
"{",
"if",
"(",
"array",
".",
"length",
"!=",
"length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unexpected array length. Expected \"",
"+",
"length",
"+",
... | Adds the array to storage. if the array length is unexpected an exception is thrown
@param array array to be recycled. | [
"Adds",
"the",
"array",
"to",
"storage",
".",
"if",
"the",
"array",
"length",
"is",
"unexpected",
"an",
"exception",
"is",
"thrown"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-types/src/main/java/boofcv/concurrency/FWorkArrays.java#L67-L72 | train |
lessthanoptimal/BoofCV | examples/src/main/java/boofcv/examples/sfm/ExampleMultiviewSceneReconstruction.java | ExampleMultiviewSceneReconstruction.visualizeResults | private void visualizeResults( SceneStructureMetric structure,
List<BufferedImage> colorImages ) {
List<Point3D_F64> cloudXyz = new ArrayList<>();
GrowQueue_I32 cloudRgb = new GrowQueue_I32();
Point3D_F64 world = new Point3D_F64();
Point3D_F64 camera = new Point3D_F64();
Point2D_F64 pixel = new Point2D_F64();
for( int i = 0; i < structure.points.length; i++ ) {
// Get 3D location
SceneStructureMetric.Point p = structure.points[i];
p.get(world);
// Project point into an arbitrary view
for (int j = 0; j < p.views.size; j++) {
int viewIdx = p.views.get(j);
SePointOps_F64.transform(structure.views[viewIdx].worldToView,world,camera);
int cameraIdx = structure.views[viewIdx].camera;
structure.cameras[cameraIdx].model.project(camera.x,camera.y,camera.z,pixel);
// Get the points color
BufferedImage image = colorImages.get(viewIdx);
int x = (int)pixel.x;
int y = (int)pixel.y;
// After optimization it might have been moved out of the camera's original FOV.
// hopefully this isn't too common
if( x < 0 || y < 0 || x >= image.getWidth() || y >= image.getHeight() )
continue;
cloudXyz.add( world.copy() );
cloudRgb.add(image.getRGB((int)pixel.x,(int)pixel.y));
break;
}
}
PointCloudViewer viewer = VisualizeData.createPointCloudViewer();
viewer.setTranslationStep(0.05);
viewer.addCloud(cloudXyz,cloudRgb.data);
viewer.setCameraHFov(UtilAngle.radian(60));
SwingUtilities.invokeLater(()->{
viewer.getComponent().setPreferredSize(new Dimension(500,500));
ShowImages.showWindow(viewer.getComponent(), "Reconstruction Points", true);
});
} | java | private void visualizeResults( SceneStructureMetric structure,
List<BufferedImage> colorImages ) {
List<Point3D_F64> cloudXyz = new ArrayList<>();
GrowQueue_I32 cloudRgb = new GrowQueue_I32();
Point3D_F64 world = new Point3D_F64();
Point3D_F64 camera = new Point3D_F64();
Point2D_F64 pixel = new Point2D_F64();
for( int i = 0; i < structure.points.length; i++ ) {
// Get 3D location
SceneStructureMetric.Point p = structure.points[i];
p.get(world);
// Project point into an arbitrary view
for (int j = 0; j < p.views.size; j++) {
int viewIdx = p.views.get(j);
SePointOps_F64.transform(structure.views[viewIdx].worldToView,world,camera);
int cameraIdx = structure.views[viewIdx].camera;
structure.cameras[cameraIdx].model.project(camera.x,camera.y,camera.z,pixel);
// Get the points color
BufferedImage image = colorImages.get(viewIdx);
int x = (int)pixel.x;
int y = (int)pixel.y;
// After optimization it might have been moved out of the camera's original FOV.
// hopefully this isn't too common
if( x < 0 || y < 0 || x >= image.getWidth() || y >= image.getHeight() )
continue;
cloudXyz.add( world.copy() );
cloudRgb.add(image.getRGB((int)pixel.x,(int)pixel.y));
break;
}
}
PointCloudViewer viewer = VisualizeData.createPointCloudViewer();
viewer.setTranslationStep(0.05);
viewer.addCloud(cloudXyz,cloudRgb.data);
viewer.setCameraHFov(UtilAngle.radian(60));
SwingUtilities.invokeLater(()->{
viewer.getComponent().setPreferredSize(new Dimension(500,500));
ShowImages.showWindow(viewer.getComponent(), "Reconstruction Points", true);
});
} | [
"private",
"void",
"visualizeResults",
"(",
"SceneStructureMetric",
"structure",
",",
"List",
"<",
"BufferedImage",
">",
"colorImages",
")",
"{",
"List",
"<",
"Point3D_F64",
">",
"cloudXyz",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"GrowQueue_I32",
"cloudRg... | Opens a window showing the found point cloud. Points are colorized using the pixel value inside
one of the input images | [
"Opens",
"a",
"window",
"showing",
"the",
"found",
"point",
"cloud",
".",
"Points",
"are",
"colorized",
"using",
"the",
"pixel",
"value",
"inside",
"one",
"of",
"the",
"input",
"images"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/examples/src/main/java/boofcv/examples/sfm/ExampleMultiviewSceneReconstruction.java#L153-L198 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/QrCodePolynomialMath.java | QrCodePolynomialMath.decodeFormatMessage | public static void decodeFormatMessage(int message , QrCode qr ) {
int error = message >> 3;
qr.error = QrCode.ErrorLevel.lookup(error);
qr.mask = QrCodeMaskPattern.lookupMask(message&0x07);
} | java | public static void decodeFormatMessage(int message , QrCode qr ) {
int error = message >> 3;
qr.error = QrCode.ErrorLevel.lookup(error);
qr.mask = QrCodeMaskPattern.lookupMask(message&0x07);
} | [
"public",
"static",
"void",
"decodeFormatMessage",
"(",
"int",
"message",
",",
"QrCode",
"qr",
")",
"{",
"int",
"error",
"=",
"message",
">>",
"3",
";",
"qr",
".",
"error",
"=",
"QrCode",
".",
"ErrorLevel",
".",
"lookup",
"(",
"error",
")",
";",
"qr",
... | Assumes that the format message has no errors in it and decodes its data and saves it into the qr code
@param message format data bits after the mask has been remove and shifted over 10 bits
@param qr Where the results are written to | [
"Assumes",
"that",
"the",
"format",
"message",
"has",
"no",
"errors",
"in",
"it",
"and",
"decodes",
"its",
"data",
"and",
"saves",
"it",
"into",
"the",
"qr",
"code"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/QrCodePolynomialMath.java#L94-L99 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/QrCodePolynomialMath.java | QrCodePolynomialMath.correctDCH | public static int correctDCH( int N , int messageNoMask , int generator , int totalBits, int dataBits) {
int bestHamming = 255;
int bestMessage = -1;
int errorBits = totalBits-dataBits;
// exhaustively check all possibilities
for (int i = 0; i < N; i++) {
int test = i << errorBits;
test = test ^ bitPolyModulus(test,generator,totalBits,dataBits);
int distance = DescriptorDistance.hamming(test^messageNoMask);
// see if it found a better match
if( distance < bestHamming ) {
bestHamming = distance;
bestMessage = i;
} else if( distance == bestHamming ) {
// ambiguous so reject
bestMessage = -1;
}
}
return bestMessage;
} | java | public static int correctDCH( int N , int messageNoMask , int generator , int totalBits, int dataBits) {
int bestHamming = 255;
int bestMessage = -1;
int errorBits = totalBits-dataBits;
// exhaustively check all possibilities
for (int i = 0; i < N; i++) {
int test = i << errorBits;
test = test ^ bitPolyModulus(test,generator,totalBits,dataBits);
int distance = DescriptorDistance.hamming(test^messageNoMask);
// see if it found a better match
if( distance < bestHamming ) {
bestHamming = distance;
bestMessage = i;
} else if( distance == bestHamming ) {
// ambiguous so reject
bestMessage = -1;
}
}
return bestMessage;
} | [
"public",
"static",
"int",
"correctDCH",
"(",
"int",
"N",
",",
"int",
"messageNoMask",
",",
"int",
"generator",
",",
"int",
"totalBits",
",",
"int",
"dataBits",
")",
"{",
"int",
"bestHamming",
"=",
"255",
";",
"int",
"bestMessage",
"=",
"-",
"1",
";",
... | Applies a brute force algorithm to find the message which has the smallest hamming distance. if two
messages have the same distance -1 is returned.
@param N Number of possible messages. 32 or 64
@param messageNoMask The observed message with mask removed
@param generator Generator polynomial
@param totalBits Total number of bits in the message.
@param dataBits Total number of data bits in the message
@return The error corrected message or -1 if it can't be determined. | [
"Applies",
"a",
"brute",
"force",
"algorithm",
"to",
"find",
"the",
"message",
"which",
"has",
"the",
"smallest",
"hamming",
"distance",
".",
"if",
"two",
"messages",
"have",
"the",
"same",
"distance",
"-",
"1",
"is",
"returned",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/qrcode/QrCodePolynomialMath.java#L120-L143 | train |
lessthanoptimal/BoofCV | examples/src/main/java/boofcv/examples/calibration/ExampleRemoveLensDistortion.java | ExampleRemoveLensDistortion.displayResults | private static void displayResults(BufferedImage orig,
Planar<GrayF32> distortedImg,
ImageDistort allInside, ImageDistort fullView ) {
// render the results
Planar<GrayF32> undistortedImg = new Planar<>(GrayF32.class,
distortedImg.getWidth(),distortedImg.getHeight(),distortedImg.getNumBands());
allInside.apply(distortedImg, undistortedImg);
BufferedImage out1 = ConvertBufferedImage.convertTo(undistortedImg, null,true);
fullView.apply(distortedImg,undistortedImg);
BufferedImage out2 = ConvertBufferedImage.convertTo(undistortedImg, null,true);
// display in a single window where the user can easily switch between images
ListDisplayPanel panel = new ListDisplayPanel();
panel.addItem(new ImagePanel(orig), "Original");
panel.addItem(new ImagePanel(out1), "Undistorted All Inside");
panel.addItem(new ImagePanel(out2), "Undistorted Full View");
ShowImages.showWindow(panel, "Removing Lens Distortion", true);
} | java | private static void displayResults(BufferedImage orig,
Planar<GrayF32> distortedImg,
ImageDistort allInside, ImageDistort fullView ) {
// render the results
Planar<GrayF32> undistortedImg = new Planar<>(GrayF32.class,
distortedImg.getWidth(),distortedImg.getHeight(),distortedImg.getNumBands());
allInside.apply(distortedImg, undistortedImg);
BufferedImage out1 = ConvertBufferedImage.convertTo(undistortedImg, null,true);
fullView.apply(distortedImg,undistortedImg);
BufferedImage out2 = ConvertBufferedImage.convertTo(undistortedImg, null,true);
// display in a single window where the user can easily switch between images
ListDisplayPanel panel = new ListDisplayPanel();
panel.addItem(new ImagePanel(orig), "Original");
panel.addItem(new ImagePanel(out1), "Undistorted All Inside");
panel.addItem(new ImagePanel(out2), "Undistorted Full View");
ShowImages.showWindow(panel, "Removing Lens Distortion", true);
} | [
"private",
"static",
"void",
"displayResults",
"(",
"BufferedImage",
"orig",
",",
"Planar",
"<",
"GrayF32",
">",
"distortedImg",
",",
"ImageDistort",
"allInside",
",",
"ImageDistort",
"fullView",
")",
"{",
"// render the results",
"Planar",
"<",
"GrayF32",
">",
"u... | Displays results in a window for easy comparison.. | [
"Displays",
"results",
"in",
"a",
"window",
"for",
"easy",
"comparison",
".."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/examples/src/main/java/boofcv/examples/calibration/ExampleRemoveLensDistortion.java#L92-L112 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/StabilitySquareFiducialEstimate.java | StabilitySquareFiducialEstimate.process | public boolean process( double sampleRadius , Quadrilateral_F64 input ) {
work.set(input);
samples.reset();
estimator.process(work,false);
estimator.getWorldToCamera().invert(referenceCameraToWorld);
samples.reset();
createSamples(sampleRadius,work.a,input.a);
createSamples(sampleRadius,work.b,input.b);
createSamples(sampleRadius,work.c,input.c);
createSamples(sampleRadius,work.d,input.d);
if( samples.size() < 10 )
return false;
maxLocation = 0;
maxOrientation = 0;
for (int i = 0; i < samples.size(); i++) {
referenceCameraToWorld.concat(samples.get(i), difference);
ConvertRotation3D_F64.matrixToRodrigues(difference.getR(),rodrigues);
double theta = Math.abs(rodrigues.theta);
double d = difference.getT().norm();
if( theta > maxOrientation ) {
maxOrientation = theta;
}
if( d > maxLocation ) {
maxLocation = d;
}
}
return true;
} | java | public boolean process( double sampleRadius , Quadrilateral_F64 input ) {
work.set(input);
samples.reset();
estimator.process(work,false);
estimator.getWorldToCamera().invert(referenceCameraToWorld);
samples.reset();
createSamples(sampleRadius,work.a,input.a);
createSamples(sampleRadius,work.b,input.b);
createSamples(sampleRadius,work.c,input.c);
createSamples(sampleRadius,work.d,input.d);
if( samples.size() < 10 )
return false;
maxLocation = 0;
maxOrientation = 0;
for (int i = 0; i < samples.size(); i++) {
referenceCameraToWorld.concat(samples.get(i), difference);
ConvertRotation3D_F64.matrixToRodrigues(difference.getR(),rodrigues);
double theta = Math.abs(rodrigues.theta);
double d = difference.getT().norm();
if( theta > maxOrientation ) {
maxOrientation = theta;
}
if( d > maxLocation ) {
maxLocation = d;
}
}
return true;
} | [
"public",
"boolean",
"process",
"(",
"double",
"sampleRadius",
",",
"Quadrilateral_F64",
"input",
")",
"{",
"work",
".",
"set",
"(",
"input",
")",
";",
"samples",
".",
"reset",
"(",
")",
";",
"estimator",
".",
"process",
"(",
"work",
",",
"false",
")",
... | Processes the observation and generates a stability estimate
@param sampleRadius Radius around the corner pixels it will sample
@param input Observed corner location of the fiducial in distorted pixels. Must be in correct order.
@return true if successful or false if it failed | [
"Processes",
"the",
"observation",
"and",
"generates",
"a",
"stability",
"estimate"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/StabilitySquareFiducialEstimate.java#L68-L106 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/StabilitySquareFiducialEstimate.java | StabilitySquareFiducialEstimate.createSamples | private void createSamples( double sampleRadius , Point2D_F64 workPoint , Point2D_F64 originalPoint ) {
workPoint.x = originalPoint.x + sampleRadius;
if( estimator.process(work,false) ) {
samples.grow().set( estimator.getWorldToCamera() );
}
workPoint.x = originalPoint.x - sampleRadius;
if( estimator.process(work,false) ) {
samples.grow().set( estimator.getWorldToCamera() );
}
workPoint.x = originalPoint.x;
workPoint.y = originalPoint.y + sampleRadius;
if( estimator.process(work,false) ) {
samples.grow().set( estimator.getWorldToCamera() );
}
workPoint.y = originalPoint.y - sampleRadius;
if( estimator.process(work,false) ) {
samples.grow().set( estimator.getWorldToCamera() );
}
workPoint.set(originalPoint);
} | java | private void createSamples( double sampleRadius , Point2D_F64 workPoint , Point2D_F64 originalPoint ) {
workPoint.x = originalPoint.x + sampleRadius;
if( estimator.process(work,false) ) {
samples.grow().set( estimator.getWorldToCamera() );
}
workPoint.x = originalPoint.x - sampleRadius;
if( estimator.process(work,false) ) {
samples.grow().set( estimator.getWorldToCamera() );
}
workPoint.x = originalPoint.x;
workPoint.y = originalPoint.y + sampleRadius;
if( estimator.process(work,false) ) {
samples.grow().set( estimator.getWorldToCamera() );
}
workPoint.y = originalPoint.y - sampleRadius;
if( estimator.process(work,false) ) {
samples.grow().set( estimator.getWorldToCamera() );
}
workPoint.set(originalPoint);
} | [
"private",
"void",
"createSamples",
"(",
"double",
"sampleRadius",
",",
"Point2D_F64",
"workPoint",
",",
"Point2D_F64",
"originalPoint",
")",
"{",
"workPoint",
".",
"x",
"=",
"originalPoint",
".",
"x",
"+",
"sampleRadius",
";",
"if",
"(",
"estimator",
".",
"pr... | Samples around the provided corner +- in x and y directions | [
"Samples",
"around",
"the",
"provided",
"corner",
"+",
"-",
"in",
"x",
"and",
"y",
"directions"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/StabilitySquareFiducialEstimate.java#L111-L132 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldLearning.java | TldLearning.initialLearning | public void initialLearning( Rectangle2D_F64 targetRegion ,
FastQueue<ImageRectangle> cascadeRegions ) {
storageMetric.reset();
fernNegative.clear();
// learn the initial descriptor
TldHelperFunctions.convertRegion(targetRegion, targetRegion_I32);
// select the variance the first time using user selected region
variance.selectThreshold(targetRegion_I32);
// add positive examples
template.addDescriptor(true, targetRegion_I32);
fern.learnFernNoise(true, targetRegion_I32);
// Find all the regions which can be used to learn a negative descriptor
for( int i = 0; i < cascadeRegions.size; i++ ) {
ImageRectangle r = cascadeRegions.get(i);
// see if it passes the variance test
if( !variance.checkVariance(r) )
continue;
// learn features far away from the target region
double overlap = helper.computeOverlap(targetRegion_I32, r);
if( overlap > config.overlapLower )
continue;
fernNegative.add(r);
}
// randomize which regions are used
// Collections.shuffle(fernNegative,rand);
int N = fernNegative.size();//Math.min(config.numNegativeFerns,fernNegative.size());
for( int i = 0; i < N; i++ ) {
fern.learnFern(false, fernNegative.get(i) );
}
// run detection algorithm and if there is an ambiguous solution mark it as not target
detection.detectionCascade(cascadeRegions);
learnAmbiguousNegative(targetRegion);
} | java | public void initialLearning( Rectangle2D_F64 targetRegion ,
FastQueue<ImageRectangle> cascadeRegions ) {
storageMetric.reset();
fernNegative.clear();
// learn the initial descriptor
TldHelperFunctions.convertRegion(targetRegion, targetRegion_I32);
// select the variance the first time using user selected region
variance.selectThreshold(targetRegion_I32);
// add positive examples
template.addDescriptor(true, targetRegion_I32);
fern.learnFernNoise(true, targetRegion_I32);
// Find all the regions which can be used to learn a negative descriptor
for( int i = 0; i < cascadeRegions.size; i++ ) {
ImageRectangle r = cascadeRegions.get(i);
// see if it passes the variance test
if( !variance.checkVariance(r) )
continue;
// learn features far away from the target region
double overlap = helper.computeOverlap(targetRegion_I32, r);
if( overlap > config.overlapLower )
continue;
fernNegative.add(r);
}
// randomize which regions are used
// Collections.shuffle(fernNegative,rand);
int N = fernNegative.size();//Math.min(config.numNegativeFerns,fernNegative.size());
for( int i = 0; i < N; i++ ) {
fern.learnFern(false, fernNegative.get(i) );
}
// run detection algorithm and if there is an ambiguous solution mark it as not target
detection.detectionCascade(cascadeRegions);
learnAmbiguousNegative(targetRegion);
} | [
"public",
"void",
"initialLearning",
"(",
"Rectangle2D_F64",
"targetRegion",
",",
"FastQueue",
"<",
"ImageRectangle",
">",
"cascadeRegions",
")",
"{",
"storageMetric",
".",
"reset",
"(",
")",
";",
"fernNegative",
".",
"clear",
"(",
")",
";",
"// learn the initial ... | Select positive and negative examples based on the region the user's initially selected region. The selected
region is used as a positive example while all the other regions far away are used as negative examples.
@param targetRegion user selected region
@param cascadeRegions Set of regions used by the cascade detector | [
"Select",
"positive",
"and",
"negative",
"examples",
"based",
"on",
"the",
"region",
"the",
"user",
"s",
"initially",
"selected",
"region",
".",
"The",
"selected",
"region",
"is",
"used",
"as",
"a",
"positive",
"example",
"while",
"all",
"the",
"other",
"reg... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldLearning.java#L83-L126 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldLearning.java | TldLearning.updateLearning | public void updateLearning( Rectangle2D_F64 targetRegion ) {
storageMetric.reset();
// learn the initial descriptor
TldHelperFunctions.convertRegion(targetRegion, targetRegion_I32);
template.addDescriptor(true, targetRegion_I32);
fern.learnFernNoise(true, targetRegion_I32);
// mark only a few of the far away regions as negative. Marking all of them as negative is
// computationally expensive
FastQueue<TldRegionFernInfo> ferns = detection.getFernInfo();
int N = Math.min(config.numNegativeFerns,ferns.size);
for( int i = 0; i < N; i++ ) {
int index = rand.nextInt(ferns.size);
TldRegionFernInfo f = ferns.get(index);
// no need to check variance here since the detector already did it
// learn features far away from the target region
double overlap = helper.computeOverlap(targetRegion_I32, f.r);
if( overlap > config.overlapLower )
continue;
fern.learnFern(false, f.r );
}
learnAmbiguousNegative(targetRegion);
} | java | public void updateLearning( Rectangle2D_F64 targetRegion ) {
storageMetric.reset();
// learn the initial descriptor
TldHelperFunctions.convertRegion(targetRegion, targetRegion_I32);
template.addDescriptor(true, targetRegion_I32);
fern.learnFernNoise(true, targetRegion_I32);
// mark only a few of the far away regions as negative. Marking all of them as negative is
// computationally expensive
FastQueue<TldRegionFernInfo> ferns = detection.getFernInfo();
int N = Math.min(config.numNegativeFerns,ferns.size);
for( int i = 0; i < N; i++ ) {
int index = rand.nextInt(ferns.size);
TldRegionFernInfo f = ferns.get(index);
// no need to check variance here since the detector already did it
// learn features far away from the target region
double overlap = helper.computeOverlap(targetRegion_I32, f.r);
if( overlap > config.overlapLower )
continue;
fern.learnFern(false, f.r );
}
learnAmbiguousNegative(targetRegion);
} | [
"public",
"void",
"updateLearning",
"(",
"Rectangle2D_F64",
"targetRegion",
")",
"{",
"storageMetric",
".",
"reset",
"(",
")",
";",
"// learn the initial descriptor",
"TldHelperFunctions",
".",
"convertRegion",
"(",
"targetRegion",
",",
"targetRegion_I32",
")",
";",
"... | Updates learning using the latest tracking results.
@param targetRegion Region selected by the fused tracking | [
"Updates",
"learning",
"using",
"the",
"latest",
"tracking",
"results",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldLearning.java#L133-L162 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldLearning.java | TldLearning.learnAmbiguousNegative | protected void learnAmbiguousNegative(Rectangle2D_F64 targetRegion) {
TldHelperFunctions.convertRegion(targetRegion, targetRegion_I32);
if( detection.isSuccess() ) {
TldRegion best = detection.getBest();
// see if it found the correct solution
double overlap = helper.computeOverlap(best.rect,targetRegion_I32);
if( overlap <= config.overlapLower ) {
template.addDescriptor(false,best.rect);
// fern.learnFernNoise(false, best.rect );
}
// mark all ambiguous regions as bad
List<ImageRectangle> ambiguous = detection.getAmbiguousRegions();
for( ImageRectangle r : ambiguous ) {
overlap = helper.computeOverlap(r,targetRegion_I32);
if( overlap <= config.overlapLower ) {
fern.learnFernNoise(false, r );
template.addDescriptor(false,r);
}
}
}
} | java | protected void learnAmbiguousNegative(Rectangle2D_F64 targetRegion) {
TldHelperFunctions.convertRegion(targetRegion, targetRegion_I32);
if( detection.isSuccess() ) {
TldRegion best = detection.getBest();
// see if it found the correct solution
double overlap = helper.computeOverlap(best.rect,targetRegion_I32);
if( overlap <= config.overlapLower ) {
template.addDescriptor(false,best.rect);
// fern.learnFernNoise(false, best.rect );
}
// mark all ambiguous regions as bad
List<ImageRectangle> ambiguous = detection.getAmbiguousRegions();
for( ImageRectangle r : ambiguous ) {
overlap = helper.computeOverlap(r,targetRegion_I32);
if( overlap <= config.overlapLower ) {
fern.learnFernNoise(false, r );
template.addDescriptor(false,r);
}
}
}
} | [
"protected",
"void",
"learnAmbiguousNegative",
"(",
"Rectangle2D_F64",
"targetRegion",
")",
"{",
"TldHelperFunctions",
".",
"convertRegion",
"(",
"targetRegion",
",",
"targetRegion_I32",
")",
";",
"if",
"(",
"detection",
".",
"isSuccess",
"(",
")",
")",
"{",
"TldR... | Mark regions which were local maximums and had high confidence as negative. These regions were
candidates for the tracker but were not selected | [
"Mark",
"regions",
"which",
"were",
"local",
"maximums",
"and",
"had",
"high",
"confidence",
"as",
"negative",
".",
"These",
"regions",
"were",
"candidates",
"for",
"the",
"tracker",
"but",
"were",
"not",
"selected"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/tld/TldLearning.java#L168-L192 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/factory/filter/binary/FactoryThresholdBinary.java | FactoryThresholdBinary.localOtsu | public static <T extends ImageGray<T>>
InputToBinary<T> localOtsu(ConfigLength regionWidth, double scale, boolean down, boolean otsu2, double tuning, Class<T> inputType) {
if( BOverrideFactoryThresholdBinary.localOtsu != null )
return BOverrideFactoryThresholdBinary.localOtsu.handle(otsu2,regionWidth, tuning, scale, down, inputType);
ThresholdLocalOtsu otsu;
if(BoofConcurrency.USE_CONCURRENT ) {
otsu = new ThresholdLocalOtsu_MT(otsu2, regionWidth, tuning, scale, down);
} else {
otsu = new ThresholdLocalOtsu(otsu2, regionWidth, tuning, scale, down);
}
return new InputToBinarySwitch<>(otsu, inputType);
} | java | public static <T extends ImageGray<T>>
InputToBinary<T> localOtsu(ConfigLength regionWidth, double scale, boolean down, boolean otsu2, double tuning, Class<T> inputType) {
if( BOverrideFactoryThresholdBinary.localOtsu != null )
return BOverrideFactoryThresholdBinary.localOtsu.handle(otsu2,regionWidth, tuning, scale, down, inputType);
ThresholdLocalOtsu otsu;
if(BoofConcurrency.USE_CONCURRENT ) {
otsu = new ThresholdLocalOtsu_MT(otsu2, regionWidth, tuning, scale, down);
} else {
otsu = new ThresholdLocalOtsu(otsu2, regionWidth, tuning, scale, down);
}
return new InputToBinarySwitch<>(otsu, inputType);
} | [
"public",
"static",
"<",
"T",
"extends",
"ImageGray",
"<",
"T",
">",
">",
"InputToBinary",
"<",
"T",
">",
"localOtsu",
"(",
"ConfigLength",
"regionWidth",
",",
"double",
"scale",
",",
"boolean",
"down",
",",
"boolean",
"otsu2",
",",
"double",
"tuning",
","... | Applies a local Otsu threshold
@see ThresholdLocalOtsu
@param regionWidth About how wide and tall you wish a block to be in pixels.
@param scale Scale factor adjust for threshold. 1.0 means no change.
@param down Should it threshold up or down.
@param tuning Tuning parameter. 0 = standard Otsu. Greater than 0 will penalize zero texture.
@param inputType Type of input image
@return Filter to binary | [
"Applies",
"a",
"local",
"Otsu",
"threshold"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/factory/filter/binary/FactoryThresholdBinary.java#L128-L140 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/factory/filter/binary/FactoryThresholdBinary.java | FactoryThresholdBinary.blockMean | public static <T extends ImageGray<T>>
InputToBinary<T> blockMean(ConfigLength regionWidth, double scale , boolean down, boolean thresholdFromLocalBlocks,
Class<T> inputType) {
if( BOverrideFactoryThresholdBinary.blockMean != null )
return BOverrideFactoryThresholdBinary.blockMean.handle(regionWidth, scale, down,
thresholdFromLocalBlocks, inputType);
BlockProcessor processor;
if( inputType == GrayU8.class )
processor = new ThresholdBlockMean_U8(scale,down);
else
processor = new ThresholdBlockMean_F32((float)scale,down);
if( BoofConcurrency.USE_CONCURRENT ) {
return new ThresholdBlock_MT(processor, regionWidth, thresholdFromLocalBlocks, inputType);
} else {
return new ThresholdBlock(processor, regionWidth, thresholdFromLocalBlocks, inputType);
}
} | java | public static <T extends ImageGray<T>>
InputToBinary<T> blockMean(ConfigLength regionWidth, double scale , boolean down, boolean thresholdFromLocalBlocks,
Class<T> inputType) {
if( BOverrideFactoryThresholdBinary.blockMean != null )
return BOverrideFactoryThresholdBinary.blockMean.handle(regionWidth, scale, down,
thresholdFromLocalBlocks, inputType);
BlockProcessor processor;
if( inputType == GrayU8.class )
processor = new ThresholdBlockMean_U8(scale,down);
else
processor = new ThresholdBlockMean_F32((float)scale,down);
if( BoofConcurrency.USE_CONCURRENT ) {
return new ThresholdBlock_MT(processor, regionWidth, thresholdFromLocalBlocks, inputType);
} else {
return new ThresholdBlock(processor, regionWidth, thresholdFromLocalBlocks, inputType);
}
} | [
"public",
"static",
"<",
"T",
"extends",
"ImageGray",
"<",
"T",
">",
">",
"InputToBinary",
"<",
"T",
">",
"blockMean",
"(",
"ConfigLength",
"regionWidth",
",",
"double",
"scale",
",",
"boolean",
"down",
",",
"boolean",
"thresholdFromLocalBlocks",
",",
"Class",... | Applies a non-overlapping block mean threshold
@see ThresholdBlockMean
@param scale Scale factor adjust for threshold. 1.0 means no change.
@param down Should it threshold up or down.
@param regionWidth Approximate size of block region
@param inputType Type of input image
@return Filter to binary | [
"Applies",
"a",
"non",
"-",
"overlapping",
"block",
"mean",
"threshold"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/factory/filter/binary/FactoryThresholdBinary.java#L186-L204 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/factory/filter/binary/FactoryThresholdBinary.java | FactoryThresholdBinary.blockOtsu | public static <T extends ImageGray<T>>
InputToBinary<T> blockOtsu(ConfigLength regionWidth, double scale, boolean down, boolean thresholdFromLocalBlocks,
boolean otsu2, double tuning,Class<T> inputType) {
if( BOverrideFactoryThresholdBinary.blockOtsu != null )
return BOverrideFactoryThresholdBinary.blockOtsu.handle(otsu2,regionWidth, tuning, scale, down,
thresholdFromLocalBlocks, inputType);
BlockProcessor processor = new ThresholdBlockOtsu(otsu2,tuning,scale,down);
InputToBinary<GrayU8> otsu;
if( BoofConcurrency.USE_CONCURRENT ) {
otsu = new ThresholdBlock_MT<>(processor, regionWidth, thresholdFromLocalBlocks, GrayU8.class);
} else {
otsu = new ThresholdBlock<>(processor, regionWidth, thresholdFromLocalBlocks, GrayU8.class);
}
return new InputToBinarySwitch<>(otsu,inputType);
} | java | public static <T extends ImageGray<T>>
InputToBinary<T> blockOtsu(ConfigLength regionWidth, double scale, boolean down, boolean thresholdFromLocalBlocks,
boolean otsu2, double tuning,Class<T> inputType) {
if( BOverrideFactoryThresholdBinary.blockOtsu != null )
return BOverrideFactoryThresholdBinary.blockOtsu.handle(otsu2,regionWidth, tuning, scale, down,
thresholdFromLocalBlocks, inputType);
BlockProcessor processor = new ThresholdBlockOtsu(otsu2,tuning,scale,down);
InputToBinary<GrayU8> otsu;
if( BoofConcurrency.USE_CONCURRENT ) {
otsu = new ThresholdBlock_MT<>(processor, regionWidth, thresholdFromLocalBlocks, GrayU8.class);
} else {
otsu = new ThresholdBlock<>(processor, regionWidth, thresholdFromLocalBlocks, GrayU8.class);
}
return new InputToBinarySwitch<>(otsu,inputType);
} | [
"public",
"static",
"<",
"T",
"extends",
"ImageGray",
"<",
"T",
">",
">",
"InputToBinary",
"<",
"T",
">",
"blockOtsu",
"(",
"ConfigLength",
"regionWidth",
",",
"double",
"scale",
",",
"boolean",
"down",
",",
"boolean",
"thresholdFromLocalBlocks",
",",
"boolean... | Applies a non-overlapping block Otsu threshold
@see ThresholdBlockOtsu
@param regionWidth Approximate size of block region
@param scale Scale factor adjust for threshold. 1.0 means no change.
@param down Should it threshold up or down.
@param inputType Type of input image
@return Filter to binary | [
"Applies",
"a",
"non",
"-",
"overlapping",
"block",
"Otsu",
"threshold"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/factory/filter/binary/FactoryThresholdBinary.java#L217-L234 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/factory/filter/binary/FactoryThresholdBinary.java | FactoryThresholdBinary.threshold | public static <T extends ImageGray<T>>
InputToBinary<T> threshold( ConfigThreshold config, Class<T> inputType) {
switch( config.type ) {
case FIXED:
return globalFixed(config.fixedThreshold, config.down, inputType);
case GLOBAL_OTSU:
return globalOtsu(config.minPixelValue, config.maxPixelValue, config.scale, config.down, inputType);
case GLOBAL_ENTROPY:
return globalEntropy(config.minPixelValue, config.maxPixelValue, config.scale, config.down, inputType);
case GLOBAL_LI:
return globalLi(config.minPixelValue, config.maxPixelValue, config.scale, config.down, inputType);
case GLOBAL_HUANG:
return globalHuang(config.minPixelValue, config.maxPixelValue, config.scale, config.down, inputType);
case LOCAL_GAUSSIAN:
return localGaussian(config.width, config.scale, config.down, inputType);
case LOCAL_SAVOLA:
return localSauvola(config.width, config.down, config.savolaK, inputType);
case LOCAL_NICK:
return localNick(config.width, config.down, config.nickK, inputType);
case LOCAL_MEAN:
return localMean(config.width, config.scale, config.down, inputType);
case LOCAL_OTSU: {
ConfigThresholdLocalOtsu c = (ConfigThresholdLocalOtsu) config;
return localOtsu(config.width, config.scale, config.down, c.useOtsu2, c.tuning, inputType);
}
case BLOCK_MIN_MAX: {
ConfigThresholdBlockMinMax c = (ConfigThresholdBlockMinMax) config;
return blockMinMax(c.width, c.scale , c.down, c.thresholdFromLocalBlocks, c.minimumSpread,
inputType);
}
case BLOCK_MEAN:
return blockMean(config.width, config.scale , config.down,
config.thresholdFromLocalBlocks, inputType);
case BLOCK_OTSU: {
ConfigThresholdLocalOtsu c = (ConfigThresholdLocalOtsu) config;
return blockOtsu(c.width, c.scale, c.down, c.thresholdFromLocalBlocks, c.useOtsu2, c.tuning,
inputType);
}
}
throw new IllegalArgumentException("Unknown type "+config.type);
} | java | public static <T extends ImageGray<T>>
InputToBinary<T> threshold( ConfigThreshold config, Class<T> inputType) {
switch( config.type ) {
case FIXED:
return globalFixed(config.fixedThreshold, config.down, inputType);
case GLOBAL_OTSU:
return globalOtsu(config.minPixelValue, config.maxPixelValue, config.scale, config.down, inputType);
case GLOBAL_ENTROPY:
return globalEntropy(config.minPixelValue, config.maxPixelValue, config.scale, config.down, inputType);
case GLOBAL_LI:
return globalLi(config.minPixelValue, config.maxPixelValue, config.scale, config.down, inputType);
case GLOBAL_HUANG:
return globalHuang(config.minPixelValue, config.maxPixelValue, config.scale, config.down, inputType);
case LOCAL_GAUSSIAN:
return localGaussian(config.width, config.scale, config.down, inputType);
case LOCAL_SAVOLA:
return localSauvola(config.width, config.down, config.savolaK, inputType);
case LOCAL_NICK:
return localNick(config.width, config.down, config.nickK, inputType);
case LOCAL_MEAN:
return localMean(config.width, config.scale, config.down, inputType);
case LOCAL_OTSU: {
ConfigThresholdLocalOtsu c = (ConfigThresholdLocalOtsu) config;
return localOtsu(config.width, config.scale, config.down, c.useOtsu2, c.tuning, inputType);
}
case BLOCK_MIN_MAX: {
ConfigThresholdBlockMinMax c = (ConfigThresholdBlockMinMax) config;
return blockMinMax(c.width, c.scale , c.down, c.thresholdFromLocalBlocks, c.minimumSpread,
inputType);
}
case BLOCK_MEAN:
return blockMean(config.width, config.scale , config.down,
config.thresholdFromLocalBlocks, inputType);
case BLOCK_OTSU: {
ConfigThresholdLocalOtsu c = (ConfigThresholdLocalOtsu) config;
return blockOtsu(c.width, c.scale, c.down, c.thresholdFromLocalBlocks, c.useOtsu2, c.tuning,
inputType);
}
}
throw new IllegalArgumentException("Unknown type "+config.type);
} | [
"public",
"static",
"<",
"T",
"extends",
"ImageGray",
"<",
"T",
">",
">",
"InputToBinary",
"<",
"T",
">",
"threshold",
"(",
"ConfigThreshold",
"config",
",",
"Class",
"<",
"T",
">",
"inputType",
")",
"{",
"switch",
"(",
"config",
".",
"type",
")",
"{",... | Creates threshold using a config class
@param config Configuration
@param inputType Type of input image
@return The thresholder | [
"Creates",
"threshold",
"using",
"a",
"config",
"class"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/factory/filter/binary/FactoryThresholdBinary.java#L318-L372 | train |
lessthanoptimal/BoofCV | integration/boofcv-swing/src/main/java/boofcv/gui/dialogs/JSpringPanel.java | JSpringPanel.constraintSouth | public void constraintSouth(JComponent target, JComponent top, JComponent bottom, int padV ) {
if( bottom == null ) {
layout.putConstraint(SpringLayout.SOUTH, target, -padV, SpringLayout.SOUTH, this);
} else {
Spring a = Spring.sum(Spring.constant(-padV),layout.getConstraint(SpringLayout.NORTH,bottom));
Spring b;
if( top == null )
b = Spring.sum(Spring.height(target),layout.getConstraint(SpringLayout.NORTH,this));
else
b = Spring.sum(Spring.height(target),layout.getConstraint(SpringLayout.SOUTH,top));
layout.getConstraints(target).setConstraint(SpringLayout.SOUTH, Spring.max(a,b));
}
} | java | public void constraintSouth(JComponent target, JComponent top, JComponent bottom, int padV ) {
if( bottom == null ) {
layout.putConstraint(SpringLayout.SOUTH, target, -padV, SpringLayout.SOUTH, this);
} else {
Spring a = Spring.sum(Spring.constant(-padV),layout.getConstraint(SpringLayout.NORTH,bottom));
Spring b;
if( top == null )
b = Spring.sum(Spring.height(target),layout.getConstraint(SpringLayout.NORTH,this));
else
b = Spring.sum(Spring.height(target),layout.getConstraint(SpringLayout.SOUTH,top));
layout.getConstraints(target).setConstraint(SpringLayout.SOUTH, Spring.max(a,b));
}
} | [
"public",
"void",
"constraintSouth",
"(",
"JComponent",
"target",
",",
"JComponent",
"top",
",",
"JComponent",
"bottom",
",",
"int",
"padV",
")",
"{",
"if",
"(",
"bottom",
"==",
"null",
")",
"{",
"layout",
".",
"putConstraint",
"(",
"SpringLayout",
".",
"S... | Constrain it to the top of it's bottom panel and prevent it from getting crushed below it's size | [
"Constrain",
"it",
"to",
"the",
"top",
"of",
"it",
"s",
"bottom",
"panel",
"and",
"prevent",
"it",
"from",
"getting",
"crushed",
"below",
"it",
"s",
"size"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/integration/boofcv-swing/src/main/java/boofcv/gui/dialogs/JSpringPanel.java#L217-L230 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java | QuadPoseEstimator.setLensDistoriton | public void setLensDistoriton(LensDistortionNarrowFOV distortion ) {
pixelToNorm = distortion.undistort_F64(true,false);
normToPixel = distortion.distort_F64(false, true);
} | java | public void setLensDistoriton(LensDistortionNarrowFOV distortion ) {
pixelToNorm = distortion.undistort_F64(true,false);
normToPixel = distortion.distort_F64(false, true);
} | [
"public",
"void",
"setLensDistoriton",
"(",
"LensDistortionNarrowFOV",
"distortion",
")",
"{",
"pixelToNorm",
"=",
"distortion",
".",
"undistort_F64",
"(",
"true",
",",
"false",
")",
";",
"normToPixel",
"=",
"distortion",
".",
"distort_F64",
"(",
"false",
",",
"... | Specifies the intrinsic parameters.
@param distortion Intrinsic camera parameters | [
"Specifies",
"the",
"intrinsic",
"parameters",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java#L133-L136 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java | QuadPoseEstimator.setFiducial | public void setFiducial( double x0 , double y0 , double x1 , double y1 ,
double x2 , double y2 , double x3 , double y3 ) {
points.get(0).location.set(x0,y0,0);
points.get(1).location.set(x1,y1,0);
points.get(2).location.set(x2,y2,0);
points.get(3).location.set(x3,y3,0);
} | java | public void setFiducial( double x0 , double y0 , double x1 , double y1 ,
double x2 , double y2 , double x3 , double y3 ) {
points.get(0).location.set(x0,y0,0);
points.get(1).location.set(x1,y1,0);
points.get(2).location.set(x2,y2,0);
points.get(3).location.set(x3,y3,0);
} | [
"public",
"void",
"setFiducial",
"(",
"double",
"x0",
",",
"double",
"y0",
",",
"double",
"x1",
",",
"double",
"y1",
",",
"double",
"x2",
",",
"double",
"y2",
",",
"double",
"x3",
",",
"double",
"y3",
")",
"{",
"points",
".",
"get",
"(",
"0",
")",
... | Specify the location of points on the 2D fiducial. These should be in "world coordinates" | [
"Specify",
"the",
"location",
"of",
"points",
"on",
"the",
"2D",
"fiducial",
".",
"These",
"should",
"be",
"in",
"world",
"coordinates"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java#L141-L147 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java | QuadPoseEstimator.pixelToMarker | public void pixelToMarker( double pixelX , double pixelY , Point2D_F64 marker ) {
// find pointing vector in camera reference frame
pixelToNorm.compute(pixelX,pixelY,marker);
cameraP3.set(marker.x,marker.y,1);
// rotate into marker reference frame
GeometryMath_F64.multTran(outputFiducialToCamera.R,cameraP3,ray.slope);
GeometryMath_F64.multTran(outputFiducialToCamera.R,outputFiducialToCamera.T,ray.p);
ray.p.scale(-1);
double t = -ray.p.z/ray.slope.z;
marker.x = ray.p.x + ray.slope.x*t;
marker.y = ray.p.y + ray.slope.y*t;
} | java | public void pixelToMarker( double pixelX , double pixelY , Point2D_F64 marker ) {
// find pointing vector in camera reference frame
pixelToNorm.compute(pixelX,pixelY,marker);
cameraP3.set(marker.x,marker.y,1);
// rotate into marker reference frame
GeometryMath_F64.multTran(outputFiducialToCamera.R,cameraP3,ray.slope);
GeometryMath_F64.multTran(outputFiducialToCamera.R,outputFiducialToCamera.T,ray.p);
ray.p.scale(-1);
double t = -ray.p.z/ray.slope.z;
marker.x = ray.p.x + ray.slope.x*t;
marker.y = ray.p.y + ray.slope.y*t;
} | [
"public",
"void",
"pixelToMarker",
"(",
"double",
"pixelX",
",",
"double",
"pixelY",
",",
"Point2D_F64",
"marker",
")",
"{",
"// find pointing vector in camera reference frame",
"pixelToNorm",
".",
"compute",
"(",
"pixelX",
",",
"pixelY",
",",
"marker",
")",
";",
... | Given the found solution, compute the the observed pixel would appear on the marker's surface.
pixel -> normalized pixel -> rotated -> projected on to plane
@param pixelX (Input) pixel coordinate
@param pixelY (Input) pixel coordinate
@param marker (Output) location on the marker | [
"Given",
"the",
"found",
"solution",
"compute",
"the",
"the",
"observed",
"pixel",
"would",
"appear",
"on",
"the",
"marker",
"s",
"surface",
".",
"pixel",
"-",
">",
"normalized",
"pixel",
"-",
">",
"rotated",
"-",
">",
"projected",
"on",
"to",
"plane"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java#L156-L171 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java | QuadPoseEstimator.estimate | protected boolean estimate( Quadrilateral_F64 cornersPixels ,
Quadrilateral_F64 cornersNorm ,
Se3_F64 foundFiducialToCamera ) {
// put it into a list to simplify algorithms
listObs.clear();
listObs.add( cornersPixels.a );
listObs.add( cornersPixels.b );
listObs.add( cornersPixels.c );
listObs.add( cornersPixels.d );
// convert observations into normalized image coordinates which P3P requires
points.get(0).observation.set(cornersNorm.a);
points.get(1).observation.set(cornersNorm.b);
points.get(2).observation.set(cornersNorm.c);
points.get(3).observation.set(cornersNorm.d);
// estimate pose using all permutations
bestError = Double.MAX_VALUE;
estimateP3P(0);
estimateP3P(1);
estimateP3P(2);
estimateP3P(3);
if( bestError == Double.MAX_VALUE )
return false;
// refine the best estimate
inputP3P.clear();
for( int i = 0; i < 4; i++ ) {
inputP3P.add( points.get(i) );
}
// got poor or horrible solution the first way, let's try it with EPNP
// and see if it does better
if( bestError > 2 ) {
if (epnp.process(inputP3P, foundEPNP)) {
if( foundEPNP.T.z > 0 ) {
double error = computeErrors(foundEPNP);
// System.out.println(" error EPNP = "+error);
if (error < bestError) {
bestPose.set(foundEPNP);
}
}
}
}
if( !refine.fitModel(inputP3P,bestPose,foundFiducialToCamera) ) {
// us the previous estimate instead
foundFiducialToCamera.set(bestPose);
return true;
}
return true;
} | java | protected boolean estimate( Quadrilateral_F64 cornersPixels ,
Quadrilateral_F64 cornersNorm ,
Se3_F64 foundFiducialToCamera ) {
// put it into a list to simplify algorithms
listObs.clear();
listObs.add( cornersPixels.a );
listObs.add( cornersPixels.b );
listObs.add( cornersPixels.c );
listObs.add( cornersPixels.d );
// convert observations into normalized image coordinates which P3P requires
points.get(0).observation.set(cornersNorm.a);
points.get(1).observation.set(cornersNorm.b);
points.get(2).observation.set(cornersNorm.c);
points.get(3).observation.set(cornersNorm.d);
// estimate pose using all permutations
bestError = Double.MAX_VALUE;
estimateP3P(0);
estimateP3P(1);
estimateP3P(2);
estimateP3P(3);
if( bestError == Double.MAX_VALUE )
return false;
// refine the best estimate
inputP3P.clear();
for( int i = 0; i < 4; i++ ) {
inputP3P.add( points.get(i) );
}
// got poor or horrible solution the first way, let's try it with EPNP
// and see if it does better
if( bestError > 2 ) {
if (epnp.process(inputP3P, foundEPNP)) {
if( foundEPNP.T.z > 0 ) {
double error = computeErrors(foundEPNP);
// System.out.println(" error EPNP = "+error);
if (error < bestError) {
bestPose.set(foundEPNP);
}
}
}
}
if( !refine.fitModel(inputP3P,bestPose,foundFiducialToCamera) ) {
// us the previous estimate instead
foundFiducialToCamera.set(bestPose);
return true;
}
return true;
} | [
"protected",
"boolean",
"estimate",
"(",
"Quadrilateral_F64",
"cornersPixels",
",",
"Quadrilateral_F64",
"cornersNorm",
",",
"Se3_F64",
"foundFiducialToCamera",
")",
"{",
"// put it into a list to simplify algorithms",
"listObs",
".",
"clear",
"(",
")",
";",
"listObs",
".... | Given the observed corners of the quad in the image in pixels estimate and store the results
of its pose | [
"Given",
"the",
"observed",
"corners",
"of",
"the",
"quad",
"in",
"the",
"image",
"in",
"pixels",
"estimate",
"and",
"store",
"the",
"results",
"of",
"its",
"pose"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java#L210-L263 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java | QuadPoseEstimator.estimateP3P | protected void estimateP3P(int excluded) {
// the point used to check the solutions is the last one
inputP3P.clear();
for( int i = 0; i < 4; i++ ) {
if( i != excluded ) {
inputP3P.add( points.get(i) );
}
}
// initial estimate for the pose
solutions.reset();
if( !p3p.process(inputP3P,solutions) ) {
// System.err.println("PIP Failed!?! That's weird");
return;
}
for (int i = 0; i < solutions.size; i++) {
double error = computeErrors(solutions.get(i));
// see if it's better and it should save the results
if( error < bestError ) {
bestError = error;
bestPose.set(solutions.get(i));
}
}
} | java | protected void estimateP3P(int excluded) {
// the point used to check the solutions is the last one
inputP3P.clear();
for( int i = 0; i < 4; i++ ) {
if( i != excluded ) {
inputP3P.add( points.get(i) );
}
}
// initial estimate for the pose
solutions.reset();
if( !p3p.process(inputP3P,solutions) ) {
// System.err.println("PIP Failed!?! That's weird");
return;
}
for (int i = 0; i < solutions.size; i++) {
double error = computeErrors(solutions.get(i));
// see if it's better and it should save the results
if( error < bestError ) {
bestError = error;
bestPose.set(solutions.get(i));
}
}
} | [
"protected",
"void",
"estimateP3P",
"(",
"int",
"excluded",
")",
"{",
"// the point used to check the solutions is the last one",
"inputP3P",
".",
"clear",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
")",
"{",
"if",... | Estimates the pose using P3P from 3 out of 4 points. Then use all 4 to pick the best solution
@param excluded which corner to exclude and use to check the answers from the others | [
"Estimates",
"the",
"pose",
"using",
"P3P",
"from",
"3",
"out",
"of",
"4",
"points",
".",
"Then",
"use",
"all",
"4",
"to",
"pick",
"the",
"best",
"solution"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java#L270-L298 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java | QuadPoseEstimator.enlarge | protected void enlarge( Quadrilateral_F64 corners, double scale ) {
UtilPolygons2D_F64.center(corners, center);
extend(center,corners.a,scale);
extend(center,corners.b,scale);
extend(center,corners.c,scale);
extend(center,corners.d,scale);
} | java | protected void enlarge( Quadrilateral_F64 corners, double scale ) {
UtilPolygons2D_F64.center(corners, center);
extend(center,corners.a,scale);
extend(center,corners.b,scale);
extend(center,corners.c,scale);
extend(center,corners.d,scale);
} | [
"protected",
"void",
"enlarge",
"(",
"Quadrilateral_F64",
"corners",
",",
"double",
"scale",
")",
"{",
"UtilPolygons2D_F64",
".",
"center",
"(",
"corners",
",",
"center",
")",
";",
"extend",
"(",
"center",
",",
"corners",
".",
"a",
",",
"scale",
")",
";",
... | Enlarges the quadrilateral to make it more sensitive to changes in orientation | [
"Enlarges",
"the",
"quadrilateral",
"to",
"make",
"it",
"more",
"sensitive",
"to",
"changes",
"in",
"orientation"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java#L303-L311 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java | QuadPoseEstimator.computeErrors | protected double computeErrors(Se3_F64 fiducialToCamera ) {
if( fiducialToCamera.T.z < 0 ) {
// the low level algorithm should already filter this code, but just incase
return Double.MAX_VALUE;
}
double maxError = 0;
for( int i = 0; i < 4; i++ ) {
maxError = Math.max(maxError,computePixelError(fiducialToCamera, points.get(i).location, listObs.get(i)));
}
return maxError;
} | java | protected double computeErrors(Se3_F64 fiducialToCamera ) {
if( fiducialToCamera.T.z < 0 ) {
// the low level algorithm should already filter this code, but just incase
return Double.MAX_VALUE;
}
double maxError = 0;
for( int i = 0; i < 4; i++ ) {
maxError = Math.max(maxError,computePixelError(fiducialToCamera, points.get(i).location, listObs.get(i)));
}
return maxError;
} | [
"protected",
"double",
"computeErrors",
"(",
"Se3_F64",
"fiducialToCamera",
")",
"{",
"if",
"(",
"fiducialToCamera",
".",
"T",
".",
"z",
"<",
"0",
")",
"{",
"// the low level algorithm should already filter this code, but just incase",
"return",
"Double",
".",
"MAX_VALU... | Compute the sum of reprojection errors for all four points
@param fiducialToCamera Transform being evaluated
@return sum of Euclidean-squared errors | [
"Compute",
"the",
"sum",
"of",
"reprojection",
"errors",
"for",
"all",
"four",
"points"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/square/QuadPoseEstimator.java#L323-L336 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/alg/geo/f/ParamFundamentalEpipolar.java | ParamFundamentalEpipolar.encode | @Override
public void encode(DMatrixRMaj F, double[] param) {
// see if which columns are to be used
selectColumns(F);
// set the largest element in the first two columns and normalize
// using that value
double v[] = new double[]{F.get(0,col0),F.get(1,col0),F.get(2,col0),
F.get(0,col1),F.get(1,col1),F.get(2,col1)};
double divisor = selectDivisor(v,param);
// solve for alpha and beta and put into param
SimpleMatrix A = new SimpleMatrix(3,2);
SimpleMatrix y = new SimpleMatrix(3,1);
for( int i = 0; i < 3; i++ ) {
A.set(i,0,v[i]);
A.set(i,1,v[i+3]);
y.set(i,0,F.get(i,col2)/divisor);
}
SimpleMatrix x = A.solve(y);
param[5] = x.get(0);
param[6] = x.get(1);
} | java | @Override
public void encode(DMatrixRMaj F, double[] param) {
// see if which columns are to be used
selectColumns(F);
// set the largest element in the first two columns and normalize
// using that value
double v[] = new double[]{F.get(0,col0),F.get(1,col0),F.get(2,col0),
F.get(0,col1),F.get(1,col1),F.get(2,col1)};
double divisor = selectDivisor(v,param);
// solve for alpha and beta and put into param
SimpleMatrix A = new SimpleMatrix(3,2);
SimpleMatrix y = new SimpleMatrix(3,1);
for( int i = 0; i < 3; i++ ) {
A.set(i,0,v[i]);
A.set(i,1,v[i+3]);
y.set(i,0,F.get(i,col2)/divisor);
}
SimpleMatrix x = A.solve(y);
param[5] = x.get(0);
param[6] = x.get(1);
} | [
"@",
"Override",
"public",
"void",
"encode",
"(",
"DMatrixRMaj",
"F",
",",
"double",
"[",
"]",
"param",
")",
"{",
"// see if which columns are to be used",
"selectColumns",
"(",
"F",
")",
";",
"// set the largest element in the first two columns and normalize",
"// using ... | Examines the matrix structure to determine how to parameterize F. | [
"Examines",
"the",
"matrix",
"structure",
"to",
"determine",
"how",
"to",
"parameterize",
"F",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/alg/geo/f/ParamFundamentalEpipolar.java#L61-L85 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/alg/geo/f/ParamFundamentalEpipolar.java | ParamFundamentalEpipolar.selectDivisor | private double selectDivisor( double v[] , double param[] ) {
double maxValue = 0;
int maxIndex = 0;
for( int i = 0; i < v.length; i++ ) {
if( Math.abs(v[i]) > maxValue ) {
maxValue = Math.abs(v[i]);
maxIndex = i;
}
}
double divisor = v[maxIndex];
int index = 0;
for( int i = 0; i < v.length; i++ ) {
v[i] /= divisor;
if( i != maxIndex ) {
// save first 5 parameters
param[index] = v[i];
// save indexes in the matrix
int col = i < 3 ? col0 : col1;
indexes[index++] = 3*(i%3)+ col;
}
}
// index of 1
int col = maxIndex >= 3 ? col1 : col0;
indexes[5] = 3*(maxIndex % 3) + col;
return divisor;
} | java | private double selectDivisor( double v[] , double param[] ) {
double maxValue = 0;
int maxIndex = 0;
for( int i = 0; i < v.length; i++ ) {
if( Math.abs(v[i]) > maxValue ) {
maxValue = Math.abs(v[i]);
maxIndex = i;
}
}
double divisor = v[maxIndex];
int index = 0;
for( int i = 0; i < v.length; i++ ) {
v[i] /= divisor;
if( i != maxIndex ) {
// save first 5 parameters
param[index] = v[i];
// save indexes in the matrix
int col = i < 3 ? col0 : col1;
indexes[index++] = 3*(i%3)+ col;
}
}
// index of 1
int col = maxIndex >= 3 ? col1 : col0;
indexes[5] = 3*(maxIndex % 3) + col;
return divisor;
} | [
"private",
"double",
"selectDivisor",
"(",
"double",
"v",
"[",
"]",
",",
"double",
"param",
"[",
"]",
")",
"{",
"double",
"maxValue",
"=",
"0",
";",
"int",
"maxIndex",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"v",
".",
"l... | The divisor is the element in the first two columns that has the largest absolute value.
Finds this element, sets col0 to be the row which contains it, and specifies which elements
in that column are to be used.
@return Value of the divisor | [
"The",
"divisor",
"is",
"the",
"element",
"in",
"the",
"first",
"two",
"columns",
"that",
"has",
"the",
"largest",
"absolute",
"value",
".",
"Finds",
"this",
"element",
"sets",
"col0",
"to",
"be",
"the",
"row",
"which",
"contains",
"it",
"and",
"specifies"... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/alg/geo/f/ParamFundamentalEpipolar.java#L94-L125 | train |
lessthanoptimal/BoofCV | main/boofcv-sfm/src/main/java/boofcv/alg/sfm/structure2/GeneratePairwiseImageGraph.java | GeneratePairwiseImageGraph.createEdge | protected void createEdge( String src , String dst ,
FastQueue<AssociatedPair> pairs , FastQueue<AssociatedIndex> matches ) {
// Fitting Essential/Fundamental works when the scene is not planar and not pure rotation
int countF = 0;
if( ransac3D.process(pairs.toList()) ) {
countF = ransac3D.getMatchSet().size();
}
// Fitting homography will work when all or part of the scene is planar or motion is pure rotation
int countH = 0;
if( ransacH.process(pairs.toList()) ) {
countH = ransacH.getMatchSet().size();
}
// fail if not enough features are remaining after RANSAC
if( Math.max(countF,countH) < minimumInliers )
return;
// The idea here is that if the number features for F is greater than H then it's a 3D scene.
// If they are similar then it might be a plane
boolean is3D = countF > countH*ratio3D;
PairwiseImageGraph2.Motion edge = graph.edges.grow();
edge.is3D = is3D;
edge.countF = countF;
edge.countH = countH;
edge.index = graph.edges.size-1;
edge.src = graph.lookupNode(src);
edge.dst = graph.lookupNode(dst);
edge.src.connections.add(edge);
edge.dst.connections.add(edge);
if( is3D ) {
saveInlierMatches(ransac3D, matches,edge);
edge.F.set(ransac3D.getModelParameters());
} else {
saveInlierMatches(ransacH, matches,edge);
Homography2D_F64 H = ransacH.getModelParameters();
ConvertDMatrixStruct.convert(H,edge.F);
}
} | java | protected void createEdge( String src , String dst ,
FastQueue<AssociatedPair> pairs , FastQueue<AssociatedIndex> matches ) {
// Fitting Essential/Fundamental works when the scene is not planar and not pure rotation
int countF = 0;
if( ransac3D.process(pairs.toList()) ) {
countF = ransac3D.getMatchSet().size();
}
// Fitting homography will work when all or part of the scene is planar or motion is pure rotation
int countH = 0;
if( ransacH.process(pairs.toList()) ) {
countH = ransacH.getMatchSet().size();
}
// fail if not enough features are remaining after RANSAC
if( Math.max(countF,countH) < minimumInliers )
return;
// The idea here is that if the number features for F is greater than H then it's a 3D scene.
// If they are similar then it might be a plane
boolean is3D = countF > countH*ratio3D;
PairwiseImageGraph2.Motion edge = graph.edges.grow();
edge.is3D = is3D;
edge.countF = countF;
edge.countH = countH;
edge.index = graph.edges.size-1;
edge.src = graph.lookupNode(src);
edge.dst = graph.lookupNode(dst);
edge.src.connections.add(edge);
edge.dst.connections.add(edge);
if( is3D ) {
saveInlierMatches(ransac3D, matches,edge);
edge.F.set(ransac3D.getModelParameters());
} else {
saveInlierMatches(ransacH, matches,edge);
Homography2D_F64 H = ransacH.getModelParameters();
ConvertDMatrixStruct.convert(H,edge.F);
}
} | [
"protected",
"void",
"createEdge",
"(",
"String",
"src",
",",
"String",
"dst",
",",
"FastQueue",
"<",
"AssociatedPair",
">",
"pairs",
",",
"FastQueue",
"<",
"AssociatedIndex",
">",
"matches",
")",
"{",
"// Fitting Essential/Fundamental works when the scene is not planar... | Connects two views together if they meet a minimal set of geometric requirements. Determines if there
is strong evidence that there is 3D information present and not just a homography
@param src ID of src image
@param dst ID of dst image
@param pairs Associated features pixels
@param matches Associated features feature indexes | [
"Connects",
"two",
"views",
"together",
"if",
"they",
"meet",
"a",
"minimal",
"set",
"of",
"geometric",
"requirements",
".",
"Determines",
"if",
"there",
"is",
"strong",
"evidence",
"that",
"there",
"is",
"3D",
"information",
"present",
"and",
"not",
"just",
... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-sfm/src/main/java/boofcv/alg/sfm/structure2/GeneratePairwiseImageGraph.java#L155-L195 | train |
lessthanoptimal/BoofCV | main/boofcv-sfm/src/main/java/boofcv/alg/sfm/structure2/GeneratePairwiseImageGraph.java | GeneratePairwiseImageGraph.saveInlierMatches | private void saveInlierMatches(ModelMatcher<?, ?> ransac,
FastQueue<AssociatedIndex> matches, PairwiseImageGraph2.Motion edge) {
int N = ransac.getMatchSet().size();
edge.inliers.reset();
for (int i = 0; i < N; i++) {
int idx = ransac.getInputIndex(i);
edge.inliers.grow().set(matches.get(idx));
}
} | java | private void saveInlierMatches(ModelMatcher<?, ?> ransac,
FastQueue<AssociatedIndex> matches, PairwiseImageGraph2.Motion edge) {
int N = ransac.getMatchSet().size();
edge.inliers.reset();
for (int i = 0; i < N; i++) {
int idx = ransac.getInputIndex(i);
edge.inliers.grow().set(matches.get(idx));
}
} | [
"private",
"void",
"saveInlierMatches",
"(",
"ModelMatcher",
"<",
"?",
",",
"?",
">",
"ransac",
",",
"FastQueue",
"<",
"AssociatedIndex",
">",
"matches",
",",
"PairwiseImageGraph2",
".",
"Motion",
"edge",
")",
"{",
"int",
"N",
"=",
"ransac",
".",
"getMatchSe... | Puts the inliers from RANSAC into the edge's list of associated features
@param ransac RANSAC
@param matches List of matches from feature association
@param edge The edge that the inliers are to be saved to | [
"Puts",
"the",
"inliers",
"from",
"RANSAC",
"into",
"the",
"edge",
"s",
"list",
"of",
"associated",
"features"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-sfm/src/main/java/boofcv/alg/sfm/structure2/GeneratePairwiseImageGraph.java#L203-L212 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquaresIntoClusters.java | SquaresIntoClusters.recycleData | protected void recycleData() {
for (int i = 0; i < nodes.size(); i++) {
SquareNode n = nodes.get(i);
for (int j = 0; j < n.edges.length; j++) {
if( n.edges[j] != null ) {
graph.detachEdge(n.edges[j]);
}
}
}
for (int i = 0; i < nodes.size(); i++) {
SquareNode n = nodes.get(i);
for (int j = 0; j < n.edges.length; j++) {
if( n.edges[j] != null )
throw new RuntimeException("BUG!");
}
}
nodes.reset();
for (int i = 0; i < clusters.size; i++) {
clusters.get(i).clear();
}
clusters.reset();
} | java | protected void recycleData() {
for (int i = 0; i < nodes.size(); i++) {
SquareNode n = nodes.get(i);
for (int j = 0; j < n.edges.length; j++) {
if( n.edges[j] != null ) {
graph.detachEdge(n.edges[j]);
}
}
}
for (int i = 0; i < nodes.size(); i++) {
SquareNode n = nodes.get(i);
for (int j = 0; j < n.edges.length; j++) {
if( n.edges[j] != null )
throw new RuntimeException("BUG!");
}
}
nodes.reset();
for (int i = 0; i < clusters.size; i++) {
clusters.get(i).clear();
}
clusters.reset();
} | [
"protected",
"void",
"recycleData",
"(",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"nodes",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"SquareNode",
"n",
"=",
"nodes",
".",
"get",
"(",
"i",
")",
";",
"for",
"(",
"int",
... | Reset and recycle data structures from the previous run | [
"Reset",
"and",
"recycle",
"data",
"structures",
"from",
"the",
"previous",
"run"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquaresIntoClusters.java#L46-L69 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquaresIntoClusters.java | SquaresIntoClusters.findClusters | protected void findClusters() {
for (int i = 0; i < nodes.size(); i++) {
SquareNode n = nodes.get(i);
if( n.graph < 0 ) {
n.graph = clusters.size();
List<SquareNode> graph = clusters.grow();
graph.add(n);
addToCluster(n, graph);
}
}
} | java | protected void findClusters() {
for (int i = 0; i < nodes.size(); i++) {
SquareNode n = nodes.get(i);
if( n.graph < 0 ) {
n.graph = clusters.size();
List<SquareNode> graph = clusters.grow();
graph.add(n);
addToCluster(n, graph);
}
}
} | [
"protected",
"void",
"findClusters",
"(",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"nodes",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"SquareNode",
"n",
"=",
"nodes",
".",
"get",
"(",
"i",
")",
";",
"if",
"(",
"n",
... | Put sets of nodes into the same list if they are some how connected | [
"Put",
"sets",
"of",
"nodes",
"into",
"the",
"same",
"list",
"if",
"they",
"are",
"some",
"how",
"connected"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquaresIntoClusters.java#L74-L86 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquaresIntoClusters.java | SquaresIntoClusters.addToCluster | void addToCluster(SquareNode seed, List<SquareNode> graph) {
open.clear();
open.add(seed);
while( !open.isEmpty() ) {
SquareNode n = open.remove( open.size() - 1 );
for (int i = 0; i < n.square.size(); i++) {
SquareEdge edge = n.edges[i];
if( edge == null )
continue;
SquareNode other;
if( edge.a == n )
other = edge.b;
else if( edge.b == n )
other = edge.a;
else
throw new RuntimeException("BUG!");
if( other.graph == SquareNode.RESET_GRAPH) {
other.graph = n.graph;
graph.add(other);
open.add(other);
} else if( other.graph != n.graph ) {
throw new RuntimeException("BUG! "+other.graph+" "+n.graph);
}
}
}
} | java | void addToCluster(SquareNode seed, List<SquareNode> graph) {
open.clear();
open.add(seed);
while( !open.isEmpty() ) {
SquareNode n = open.remove( open.size() - 1 );
for (int i = 0; i < n.square.size(); i++) {
SquareEdge edge = n.edges[i];
if( edge == null )
continue;
SquareNode other;
if( edge.a == n )
other = edge.b;
else if( edge.b == n )
other = edge.a;
else
throw new RuntimeException("BUG!");
if( other.graph == SquareNode.RESET_GRAPH) {
other.graph = n.graph;
graph.add(other);
open.add(other);
} else if( other.graph != n.graph ) {
throw new RuntimeException("BUG! "+other.graph+" "+n.graph);
}
}
}
} | [
"void",
"addToCluster",
"(",
"SquareNode",
"seed",
",",
"List",
"<",
"SquareNode",
">",
"graph",
")",
"{",
"open",
".",
"clear",
"(",
")",
";",
"open",
".",
"add",
"(",
"seed",
")",
";",
"while",
"(",
"!",
"open",
".",
"isEmpty",
"(",
")",
")",
"... | Finds all neighbors and adds them to the graph. Repeated until there are no more nodes to add to the graph | [
"Finds",
"all",
"neighbors",
"and",
"adds",
"them",
"to",
"the",
"graph",
".",
"Repeated",
"until",
"there",
"are",
"no",
"more",
"nodes",
"to",
"add",
"to",
"the",
"graph"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquaresIntoClusters.java#L91-L119 | train |
lessthanoptimal/BoofCV | examples/src/main/java/boofcv/examples/segmentation/ExampleSegmentColor.java | ExampleSegmentColor.printClickedColor | public static void printClickedColor( final BufferedImage image ) {
ImagePanel gui = new ImagePanel(image);
gui.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
float[] color = new float[3];
int rgb = image.getRGB(e.getX(),e.getY());
ColorHsv.rgbToHsv((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF, color);
System.out.println("H = " + color[0]+" S = "+color[1]+" V = "+color[2]);
showSelectedColor("Selected",image,color[0],color[1]);
}
});
ShowImages.showWindow(gui,"Color Selector");
} | java | public static void printClickedColor( final BufferedImage image ) {
ImagePanel gui = new ImagePanel(image);
gui.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
float[] color = new float[3];
int rgb = image.getRGB(e.getX(),e.getY());
ColorHsv.rgbToHsv((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF, color);
System.out.println("H = " + color[0]+" S = "+color[1]+" V = "+color[2]);
showSelectedColor("Selected",image,color[0],color[1]);
}
});
ShowImages.showWindow(gui,"Color Selector");
} | [
"public",
"static",
"void",
"printClickedColor",
"(",
"final",
"BufferedImage",
"image",
")",
"{",
"ImagePanel",
"gui",
"=",
"new",
"ImagePanel",
"(",
"image",
")",
";",
"gui",
".",
"addMouseListener",
"(",
"new",
"MouseAdapter",
"(",
")",
"{",
"@",
"Overrid... | Shows a color image and allows the user to select a pixel, convert it to HSV, print
the HSV values, and calls the function below to display similar pixels. | [
"Shows",
"a",
"color",
"image",
"and",
"allows",
"the",
"user",
"to",
"select",
"a",
"pixel",
"convert",
"it",
"to",
"HSV",
"print",
"the",
"HSV",
"values",
"and",
"calls",
"the",
"function",
"below",
"to",
"display",
"similar",
"pixels",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/examples/src/main/java/boofcv/examples/segmentation/ExampleSegmentColor.java#L48-L63 | train |
lessthanoptimal/BoofCV | examples/src/main/java/boofcv/examples/segmentation/ExampleSegmentColor.java | ExampleSegmentColor.showSelectedColor | public static void showSelectedColor( String name , BufferedImage image , float hue , float saturation ) {
Planar<GrayF32> input = ConvertBufferedImage.convertFromPlanar(image,null,true,GrayF32.class);
Planar<GrayF32> hsv = input.createSameShape();
// Convert into HSV
ColorHsv.rgbToHsv(input,hsv);
// Euclidean distance squared threshold for deciding which pixels are members of the selected set
float maxDist2 = 0.4f*0.4f;
// Extract hue and saturation bands which are independent of intensity
GrayF32 H = hsv.getBand(0);
GrayF32 S = hsv.getBand(1);
// Adjust the relative importance of Hue and Saturation.
// Hue has a range of 0 to 2*PI and Saturation from 0 to 1.
float adjustUnits = (float)(Math.PI/2.0);
// step through each pixel and mark how close it is to the selected color
BufferedImage output = new BufferedImage(input.width,input.height,BufferedImage.TYPE_INT_RGB);
for( int y = 0; y < hsv.height; y++ ) {
for( int x = 0; x < hsv.width; x++ ) {
// Hue is an angle in radians, so simple subtraction doesn't work
float dh = UtilAngle.dist(H.unsafe_get(x,y),hue);
float ds = (S.unsafe_get(x,y)-saturation)*adjustUnits;
// this distance measure is a bit naive, but good enough for to demonstrate the concept
float dist2 = dh*dh + ds*ds;
if( dist2 <= maxDist2 ) {
output.setRGB(x,y,image.getRGB(x,y));
}
}
}
ShowImages.showWindow(output,"Showing "+name);
} | java | public static void showSelectedColor( String name , BufferedImage image , float hue , float saturation ) {
Planar<GrayF32> input = ConvertBufferedImage.convertFromPlanar(image,null,true,GrayF32.class);
Planar<GrayF32> hsv = input.createSameShape();
// Convert into HSV
ColorHsv.rgbToHsv(input,hsv);
// Euclidean distance squared threshold for deciding which pixels are members of the selected set
float maxDist2 = 0.4f*0.4f;
// Extract hue and saturation bands which are independent of intensity
GrayF32 H = hsv.getBand(0);
GrayF32 S = hsv.getBand(1);
// Adjust the relative importance of Hue and Saturation.
// Hue has a range of 0 to 2*PI and Saturation from 0 to 1.
float adjustUnits = (float)(Math.PI/2.0);
// step through each pixel and mark how close it is to the selected color
BufferedImage output = new BufferedImage(input.width,input.height,BufferedImage.TYPE_INT_RGB);
for( int y = 0; y < hsv.height; y++ ) {
for( int x = 0; x < hsv.width; x++ ) {
// Hue is an angle in radians, so simple subtraction doesn't work
float dh = UtilAngle.dist(H.unsafe_get(x,y),hue);
float ds = (S.unsafe_get(x,y)-saturation)*adjustUnits;
// this distance measure is a bit naive, but good enough for to demonstrate the concept
float dist2 = dh*dh + ds*ds;
if( dist2 <= maxDist2 ) {
output.setRGB(x,y,image.getRGB(x,y));
}
}
}
ShowImages.showWindow(output,"Showing "+name);
} | [
"public",
"static",
"void",
"showSelectedColor",
"(",
"String",
"name",
",",
"BufferedImage",
"image",
",",
"float",
"hue",
",",
"float",
"saturation",
")",
"{",
"Planar",
"<",
"GrayF32",
">",
"input",
"=",
"ConvertBufferedImage",
".",
"convertFromPlanar",
"(",
... | Selectively displays only pixels which have a similar hue and saturation values to what is provided.
This is intended to be a simple example of color based segmentation. Color based segmentation can be done
in RGB color, but is more problematic due to it not being intensity invariant. More robust techniques
can use Gaussian models instead of a uniform distribution, as is done below. | [
"Selectively",
"displays",
"only",
"pixels",
"which",
"have",
"a",
"similar",
"hue",
"and",
"saturation",
"values",
"to",
"what",
"is",
"provided",
".",
"This",
"is",
"intended",
"to",
"be",
"a",
"simple",
"example",
"of",
"color",
"based",
"segmentation",
"... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/examples/src/main/java/boofcv/examples/segmentation/ExampleSegmentColor.java#L71-L106 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/alg/transform/wavelet/UtilWavelet.java | UtilWavelet.transformDimension | public static ImageDimension transformDimension( ImageBase orig , int level )
{
return transformDimension(orig.width,orig.height,level);
} | java | public static ImageDimension transformDimension( ImageBase orig , int level )
{
return transformDimension(orig.width,orig.height,level);
} | [
"public",
"static",
"ImageDimension",
"transformDimension",
"(",
"ImageBase",
"orig",
",",
"int",
"level",
")",
"{",
"return",
"transformDimension",
"(",
"orig",
".",
"width",
",",
"orig",
".",
"height",
",",
"level",
")",
";",
"}"
] | Returns dimension which is required for the transformed image in a multilevel
wavelet transform. | [
"Returns",
"dimension",
"which",
"is",
"required",
"for",
"the",
"transformed",
"image",
"in",
"a",
"multilevel",
"wavelet",
"transform",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/alg/transform/wavelet/UtilWavelet.java#L93-L96 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/alg/transform/wavelet/UtilWavelet.java | UtilWavelet.borderForwardLower | public static int borderForwardLower( WlCoef desc ) {
int ret = -Math.min(desc.offsetScaling,desc.offsetWavelet);
return ret + (ret % 2);
} | java | public static int borderForwardLower( WlCoef desc ) {
int ret = -Math.min(desc.offsetScaling,desc.offsetWavelet);
return ret + (ret % 2);
} | [
"public",
"static",
"int",
"borderForwardLower",
"(",
"WlCoef",
"desc",
")",
"{",
"int",
"ret",
"=",
"-",
"Math",
".",
"min",
"(",
"desc",
".",
"offsetScaling",
",",
"desc",
".",
"offsetWavelet",
")",
";",
"return",
"ret",
"+",
"(",
"ret",
"%",
"2",
... | Returns the lower border for a forward wavelet transform. | [
"Returns",
"the",
"lower",
"border",
"for",
"a",
"forward",
"wavelet",
"transform",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/alg/transform/wavelet/UtilWavelet.java#L172-L176 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/alg/transform/wavelet/UtilWavelet.java | UtilWavelet.borderInverseLower | public static int borderInverseLower( WlBorderCoef<?> desc, BorderIndex1D border ) {
WlCoef inner = desc.getInnerCoefficients();
int borderSize = borderForwardLower(inner);
WlCoef ll = borderSize > 0 ? inner : null;
WlCoef lu = ll;
WlCoef uu = inner;
int indexLU = 0;
if( desc.getLowerLength() > 0 ) {
ll = desc.getBorderCoefficients(0);
indexLU = desc.getLowerLength()*2-2;
lu = desc.getBorderCoefficients(indexLU);
}
if( desc.getUpperLength() > 0 ) {
uu = desc.getBorderCoefficients(-2);
}
border.setLength(2000);
borderSize = checkInverseLower(ll,0,border,borderSize);
borderSize = checkInverseLower(lu,indexLU,border,borderSize);
borderSize = checkInverseLower(uu,1998,border,borderSize);
return borderSize;
} | java | public static int borderInverseLower( WlBorderCoef<?> desc, BorderIndex1D border ) {
WlCoef inner = desc.getInnerCoefficients();
int borderSize = borderForwardLower(inner);
WlCoef ll = borderSize > 0 ? inner : null;
WlCoef lu = ll;
WlCoef uu = inner;
int indexLU = 0;
if( desc.getLowerLength() > 0 ) {
ll = desc.getBorderCoefficients(0);
indexLU = desc.getLowerLength()*2-2;
lu = desc.getBorderCoefficients(indexLU);
}
if( desc.getUpperLength() > 0 ) {
uu = desc.getBorderCoefficients(-2);
}
border.setLength(2000);
borderSize = checkInverseLower(ll,0,border,borderSize);
borderSize = checkInverseLower(lu,indexLU,border,borderSize);
borderSize = checkInverseLower(uu,1998,border,borderSize);
return borderSize;
} | [
"public",
"static",
"int",
"borderInverseLower",
"(",
"WlBorderCoef",
"<",
"?",
">",
"desc",
",",
"BorderIndex1D",
"border",
")",
"{",
"WlCoef",
"inner",
"=",
"desc",
".",
"getInnerCoefficients",
"(",
")",
";",
"int",
"borderSize",
"=",
"borderForwardLower",
"... | Returns the lower border for an inverse wavelet transform. | [
"Returns",
"the",
"lower",
"border",
"for",
"an",
"inverse",
"wavelet",
"transform",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/alg/transform/wavelet/UtilWavelet.java#L193-L219 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/alg/transform/wavelet/UtilWavelet.java | UtilWavelet.round | public static int round( int top , int div2 , int divisor ) {
if( top > 0 )
return (top + div2)/divisor;
else
return (top - div2)/divisor;
} | java | public static int round( int top , int div2 , int divisor ) {
if( top > 0 )
return (top + div2)/divisor;
else
return (top - div2)/divisor;
} | [
"public",
"static",
"int",
"round",
"(",
"int",
"top",
",",
"int",
"div2",
",",
"int",
"divisor",
")",
"{",
"if",
"(",
"top",
">",
"0",
")",
"return",
"(",
"top",
"+",
"div2",
")",
"/",
"divisor",
";",
"else",
"return",
"(",
"top",
"-",
"div2",
... | Specialized rounding for use with integer wavelet transform.
return (top +- div2) / divisor;
@param top Top part of the equation.
@param div2 The divisor divided by two.
@param divisor The divisor.
@return | [
"Specialized",
"rounding",
"for",
"use",
"with",
"integer",
"wavelet",
"transform",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/alg/transform/wavelet/UtilWavelet.java#L308-L313 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/alg/transform/wavelet/UtilWavelet.java | UtilWavelet.adjustForDisplay | public static void adjustForDisplay(ImageGray transform , int numLevels , double valueRange ) {
if( transform instanceof GrayF32)
adjustForDisplay((GrayF32)transform,numLevels,(float)valueRange);
else
adjustForDisplay((GrayI)transform,numLevels,(int)valueRange);
} | java | public static void adjustForDisplay(ImageGray transform , int numLevels , double valueRange ) {
if( transform instanceof GrayF32)
adjustForDisplay((GrayF32)transform,numLevels,(float)valueRange);
else
adjustForDisplay((GrayI)transform,numLevels,(int)valueRange);
} | [
"public",
"static",
"void",
"adjustForDisplay",
"(",
"ImageGray",
"transform",
",",
"int",
"numLevels",
",",
"double",
"valueRange",
")",
"{",
"if",
"(",
"transform",
"instanceof",
"GrayF32",
")",
"adjustForDisplay",
"(",
"(",
"GrayF32",
")",
"transform",
",",
... | Adjusts the values inside a wavelet transform to make it easier to view.
@param transform
@param numLevels Number of levels in the transform | [
"Adjusts",
"the",
"values",
"inside",
"a",
"wavelet",
"transform",
"to",
"make",
"it",
"easier",
"to",
"view",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/alg/transform/wavelet/UtilWavelet.java#L332-L337 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/alg/enhance/impl/ImplEnhanceHistogram.java | ImplEnhanceHistogram.equalizeLocalNaive | public static void equalizeLocalNaive( GrayU8 input , int radius , GrayU8 output ,
IWorkArrays workArrays )
{
int width = 2*radius+1;
int maxValue = workArrays.length()-1;
//CONCURRENT_BELOW BoofConcurrency.loopBlocks(0,input.height,(idx0,idx1)->{
int idx0 = 0, idx1 = input.height;
int[] histogram = workArrays.pop();
for( int y = idx0; y < idx1; y++ ) {
// make sure it's inside the image bounds
int y0 = y-radius;
int y1 = y+radius+1;
if( y0 < 0 ) {
y0 = 0; y1 = width;
if( y1 > input.height )
y1 = input.height;
} else if( y1 > input.height ) {
y1 = input.height;
y0 = y1 - width;
if( y0 < 0 )
y0 = 0;
}
// pixel indexes
int indexIn = input.startIndex + y*input.stride;
int indexOut = output.startIndex + y*output.stride;
for( int x = 0; x < input.width; x++ ) {
// make sure it's inside the image bounds
int x0 = x-radius;
int x1 = x+radius+1;
if( x0 < 0 ) {
x0 = 0; x1 = width;
if( x1 > input.width )
x1 = input.width;
} else if( x1 > input.width ) {
x1 = input.width;
x0 = x1 - width;
if( x0 < 0 )
x0 = 0;
}
// compute the local histogram
localHistogram(input,x0,y0,x1,y1,histogram);
// only need to compute up to the value of the input pixel
int inputValue = input.data[indexIn++] & 0xFF;
int sum = 0;
for( int i = 0; i <= inputValue; i++ ) {
sum += histogram[i];
}
int area = (y1-y0)*(x1-x0);
output.data[indexOut++] = (byte)((sum*maxValue)/area);
}
}
workArrays.recycle(histogram);
//CONCURRENT_ABOVE });
} | java | public static void equalizeLocalNaive( GrayU8 input , int radius , GrayU8 output ,
IWorkArrays workArrays )
{
int width = 2*radius+1;
int maxValue = workArrays.length()-1;
//CONCURRENT_BELOW BoofConcurrency.loopBlocks(0,input.height,(idx0,idx1)->{
int idx0 = 0, idx1 = input.height;
int[] histogram = workArrays.pop();
for( int y = idx0; y < idx1; y++ ) {
// make sure it's inside the image bounds
int y0 = y-radius;
int y1 = y+radius+1;
if( y0 < 0 ) {
y0 = 0; y1 = width;
if( y1 > input.height )
y1 = input.height;
} else if( y1 > input.height ) {
y1 = input.height;
y0 = y1 - width;
if( y0 < 0 )
y0 = 0;
}
// pixel indexes
int indexIn = input.startIndex + y*input.stride;
int indexOut = output.startIndex + y*output.stride;
for( int x = 0; x < input.width; x++ ) {
// make sure it's inside the image bounds
int x0 = x-radius;
int x1 = x+radius+1;
if( x0 < 0 ) {
x0 = 0; x1 = width;
if( x1 > input.width )
x1 = input.width;
} else if( x1 > input.width ) {
x1 = input.width;
x0 = x1 - width;
if( x0 < 0 )
x0 = 0;
}
// compute the local histogram
localHistogram(input,x0,y0,x1,y1,histogram);
// only need to compute up to the value of the input pixel
int inputValue = input.data[indexIn++] & 0xFF;
int sum = 0;
for( int i = 0; i <= inputValue; i++ ) {
sum += histogram[i];
}
int area = (y1-y0)*(x1-x0);
output.data[indexOut++] = (byte)((sum*maxValue)/area);
}
}
workArrays.recycle(histogram);
//CONCURRENT_ABOVE });
} | [
"public",
"static",
"void",
"equalizeLocalNaive",
"(",
"GrayU8",
"input",
",",
"int",
"radius",
",",
"GrayU8",
"output",
",",
"IWorkArrays",
"workArrays",
")",
"{",
"int",
"width",
"=",
"2",
"*",
"radius",
"+",
"1",
";",
"int",
"maxValue",
"=",
"workArrays... | Inefficiently computes the local histogram, but can handle every possible case for image size and
local region size | [
"Inefficiently",
"computes",
"the",
"local",
"histogram",
"but",
"can",
"handle",
"every",
"possible",
"case",
"for",
"image",
"size",
"and",
"local",
"region",
"size"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/alg/enhance/impl/ImplEnhanceHistogram.java#L111-L170 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/alg/enhance/impl/ImplEnhanceHistogram.java | ImplEnhanceHistogram.equalizeLocalInner | public static void equalizeLocalInner( GrayU8 input , int radius , GrayU8 output ,
IWorkArrays workArrays ) {
int width = 2*radius+1;
int area = width*width;
int maxValue = workArrays.length()-1;
//CONCURRENT_BELOW BoofConcurrency.loopBlocks(radius,input.height-radius,(y0,y1)->{
int y0 = radius, y1 = input.height-radius;
int[] histogram = workArrays.pop();
for( int y = y0; y < y1; y++ ) {
localHistogram(input,0,y-radius,width,y+radius+1,histogram);
// compute equalized pixel value using the local histogram
int inputValue = input.unsafe_get(radius, y);
int sum = 0;
for( int i = 0; i <= inputValue; i++ ) {
sum += histogram[i];
}
output.set(radius,y, (sum*maxValue)/area );
// start of old and new columns in histogram region
int indexOld = input.startIndex + y*input.stride;
int indexNew = indexOld+width;
// index of pixel being examined
int indexIn = input.startIndex + y*input.stride+radius+1;
int indexOut = output.startIndex + y*output.stride+radius+1;
for( int x = radius+1; x < input.width-radius; x++ ) {
// update local histogram by removing the left column
for( int i = -radius; i <= radius; i++ ) {
histogram[input.data[indexOld + i*input.stride] & 0xFF]--;
}
// update local histogram by adding the right column
for( int i = -radius; i <= radius; i++ ) {
histogram[input.data[indexNew + i*input.stride] & 0xFF]++;
}
// compute equalized pixel value using the local histogram
inputValue = input.data[indexIn++] & 0xFF;
sum = 0;
for( int i = 0; i <= inputValue; i++ ) {
sum += histogram[i];
}
output.data[indexOut++] = (byte)((sum*maxValue)/area);
indexOld++;
indexNew++;
}
}
workArrays.recycle(histogram);
//CONCURRENT_ABOVE });
} | java | public static void equalizeLocalInner( GrayU8 input , int radius , GrayU8 output ,
IWorkArrays workArrays ) {
int width = 2*radius+1;
int area = width*width;
int maxValue = workArrays.length()-1;
//CONCURRENT_BELOW BoofConcurrency.loopBlocks(radius,input.height-radius,(y0,y1)->{
int y0 = radius, y1 = input.height-radius;
int[] histogram = workArrays.pop();
for( int y = y0; y < y1; y++ ) {
localHistogram(input,0,y-radius,width,y+radius+1,histogram);
// compute equalized pixel value using the local histogram
int inputValue = input.unsafe_get(radius, y);
int sum = 0;
for( int i = 0; i <= inputValue; i++ ) {
sum += histogram[i];
}
output.set(radius,y, (sum*maxValue)/area );
// start of old and new columns in histogram region
int indexOld = input.startIndex + y*input.stride;
int indexNew = indexOld+width;
// index of pixel being examined
int indexIn = input.startIndex + y*input.stride+radius+1;
int indexOut = output.startIndex + y*output.stride+radius+1;
for( int x = radius+1; x < input.width-radius; x++ ) {
// update local histogram by removing the left column
for( int i = -radius; i <= radius; i++ ) {
histogram[input.data[indexOld + i*input.stride] & 0xFF]--;
}
// update local histogram by adding the right column
for( int i = -radius; i <= radius; i++ ) {
histogram[input.data[indexNew + i*input.stride] & 0xFF]++;
}
// compute equalized pixel value using the local histogram
inputValue = input.data[indexIn++] & 0xFF;
sum = 0;
for( int i = 0; i <= inputValue; i++ ) {
sum += histogram[i];
}
output.data[indexOut++] = (byte)((sum*maxValue)/area);
indexOld++;
indexNew++;
}
}
workArrays.recycle(histogram);
//CONCURRENT_ABOVE });
} | [
"public",
"static",
"void",
"equalizeLocalInner",
"(",
"GrayU8",
"input",
",",
"int",
"radius",
",",
"GrayU8",
"output",
",",
"IWorkArrays",
"workArrays",
")",
"{",
"int",
"width",
"=",
"2",
"*",
"radius",
"+",
"1",
";",
"int",
"area",
"=",
"width",
"*",... | Performs local histogram equalization just on the inner portion of the image | [
"Performs",
"local",
"histogram",
"equalization",
"just",
"on",
"the",
"inner",
"portion",
"of",
"the",
"image"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/alg/enhance/impl/ImplEnhanceHistogram.java#L175-L232 | train |
lessthanoptimal/BoofCV | main/boofcv-ip/src/main/java/boofcv/alg/enhance/impl/ImplEnhanceHistogram.java | ImplEnhanceHistogram.localHistogram | public static void localHistogram( GrayU16 input , int x0 , int y0 , int x1, int y1 , int histogram[] ) {
for( int i = 0; i < histogram.length; i++ )
histogram[i] = 0;
for( int i = y0; i < y1; i++ ) {
int index = input.startIndex + i*input.stride + x0;
int end = index + x1-x0;
for( ; index < end; index++ ) {
histogram[input.data[index] & 0xFFFF]++;
}
}
} | java | public static void localHistogram( GrayU16 input , int x0 , int y0 , int x1, int y1 , int histogram[] ) {
for( int i = 0; i < histogram.length; i++ )
histogram[i] = 0;
for( int i = y0; i < y1; i++ ) {
int index = input.startIndex + i*input.stride + x0;
int end = index + x1-x0;
for( ; index < end; index++ ) {
histogram[input.data[index] & 0xFFFF]++;
}
}
} | [
"public",
"static",
"void",
"localHistogram",
"(",
"GrayU16",
"input",
",",
"int",
"x0",
",",
"int",
"y0",
",",
"int",
"x1",
",",
"int",
"y1",
",",
"int",
"histogram",
"[",
"]",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"histogra... | Computes the local histogram just for the specified inner region | [
"Computes",
"the",
"local",
"histogram",
"just",
"for",
"the",
"specified",
"inner",
"region"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-ip/src/main/java/boofcv/alg/enhance/impl/ImplEnhanceHistogram.java#L718-L729 | train |
lessthanoptimal/BoofCV | integration/boofcv-swing/src/main/java/boofcv/gui/image/ImageZoomPanel.java | ImageZoomPanel.setBufferedImage | public synchronized void setBufferedImage(BufferedImage image) {
// assume the image was initially set before the GUI was invoked
if( checkEventDispatch && this.img != null ) {
if( !SwingUtilities.isEventDispatchThread() )
throw new RuntimeException("Changed image when not in GUI thread?");
}
this.img = image;
if( image != null )
updateSize(image.getWidth(),image.getHeight());
} | java | public synchronized void setBufferedImage(BufferedImage image) {
// assume the image was initially set before the GUI was invoked
if( checkEventDispatch && this.img != null ) {
if( !SwingUtilities.isEventDispatchThread() )
throw new RuntimeException("Changed image when not in GUI thread?");
}
this.img = image;
if( image != null )
updateSize(image.getWidth(),image.getHeight());
} | [
"public",
"synchronized",
"void",
"setBufferedImage",
"(",
"BufferedImage",
"image",
")",
"{",
"// assume the image was initially set before the GUI was invoked",
"if",
"(",
"checkEventDispatch",
"&&",
"this",
".",
"img",
"!=",
"null",
")",
"{",
"if",
"(",
"!",
"Swing... | Change the image being displayed.
@param image The new image which will be displayed. | [
"Change",
"the",
"image",
"being",
"displayed",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/integration/boofcv-swing/src/main/java/boofcv/gui/image/ImageZoomPanel.java#L127-L137 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/meanshift/TrackerMeanShiftLikelihood.java | TrackerMeanShiftLikelihood.initialize | public void initialize( T image , RectangleLength2D_I32 initial ) {
if( !image.isInBounds(initial.x0,initial.y0) )
throw new IllegalArgumentException("Initial rectangle is out of bounds!");
if( !image.isInBounds(initial.x0+initial.width,initial.y0+initial.height) )
throw new IllegalArgumentException("Initial rectangle is out of bounds!");
pdf.reshape(image.width,image.height);
ImageMiscOps.fill(pdf,-1);
setTrackLocation(initial);
failed = false;
// compute the initial sum of the likelihood so that it can detect when the target is no longer visible
minimumSum = 0;
targetModel.setImage(image);
for( int y = 0; y < initial.height; y++ ) {
for( int x = 0; x < initial.width; x++ ) {
minimumSum += targetModel.compute(x+initial.x0,y+initial.y0);
}
}
minimumSum *= minFractionDrop;
} | java | public void initialize( T image , RectangleLength2D_I32 initial ) {
if( !image.isInBounds(initial.x0,initial.y0) )
throw new IllegalArgumentException("Initial rectangle is out of bounds!");
if( !image.isInBounds(initial.x0+initial.width,initial.y0+initial.height) )
throw new IllegalArgumentException("Initial rectangle is out of bounds!");
pdf.reshape(image.width,image.height);
ImageMiscOps.fill(pdf,-1);
setTrackLocation(initial);
failed = false;
// compute the initial sum of the likelihood so that it can detect when the target is no longer visible
minimumSum = 0;
targetModel.setImage(image);
for( int y = 0; y < initial.height; y++ ) {
for( int x = 0; x < initial.width; x++ ) {
minimumSum += targetModel.compute(x+initial.x0,y+initial.y0);
}
}
minimumSum *= minFractionDrop;
} | [
"public",
"void",
"initialize",
"(",
"T",
"image",
",",
"RectangleLength2D_I32",
"initial",
")",
"{",
"if",
"(",
"!",
"image",
".",
"isInBounds",
"(",
"initial",
".",
"x0",
",",
"initial",
".",
"y0",
")",
")",
"throw",
"new",
"IllegalArgumentException",
"(... | Specifies the initial target location so that it can learn its description
@param image Image
@param initial Initial target location and the mean-shift bandwidth | [
"Specifies",
"the",
"initial",
"target",
"location",
"so",
"that",
"it",
"can",
"learn",
"its",
"description"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/meanshift/TrackerMeanShiftLikelihood.java#L93-L117 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/meanshift/TrackerMeanShiftLikelihood.java | TrackerMeanShiftLikelihood.process | public boolean process( T image ) {
if( failed )
return false;
targetModel.setImage(image);
// mark the region where the pdf has been modified as dirty
dirty.set(location.x0, location.y0, location.x0 + location.width, location.y0 + location.height);
// compute the pdf inside the initial rectangle
updatePdfImage(location.x0 , location.y0 , location.x0+location.width , location.y0+location.height);
// current location of the target
int x0 = location.x0;
int y0 = location.y0;
// previous location of the target in the most recent iteration
int prevX = x0;
int prevY = y0;
// iterate until it converges or reaches the maximum number of iterations
for( int i = 0; i < maxIterations; i++ ) {
// compute the weighted centroid using the likelihood function
float totalPdf = 0;
float sumX = 0;
float sumY = 0;
for( int y = 0; y < location.height; y++ ) {
int indexPdf = pdf.startIndex + pdf.stride*(y+y0) + x0;
for( int x = 0; x < location.width; x++ ) {
float p = pdf.data[indexPdf++];
totalPdf += p;
sumX += (x0+x)*p;
sumY += (y0+y)*p;
}
}
// if the target isn't likely to be in view, give up
if( totalPdf <= minimumSum ) {
failed = true;
return false;
}
// Use the new center to find the new top left corner, while rounding to the nearest integer
x0 = (int)(sumX/totalPdf-location.width/2+0.5f);
y0 = (int)(sumY/totalPdf-location.height/2+0.5f);
// make sure it doesn't go outside the image
if( x0 < 0 )
x0 = 0;
else if( x0 >= image.width-location.width )
x0 = image.width-location.width;
if( y0 < 0 )
y0 = 0;
else if( y0 >= image.height-location.height )
y0 = image.height-location.height;
// see if it has converged
if( x0 == prevX && y0 == prevY )
break;
// save the previous location
prevX = x0;
prevY = y0;
// update the pdf
updatePdfImage(x0,y0,x0+location.width,y0+location.height);
}
// update the output
location.x0 = x0;
location.y0 = y0;
// clean up the image for the next iteration
ImageMiscOps.fillRectangle(pdf,-1,dirty.x0,dirty.y0,dirty.x1-dirty.x0,dirty.y1-dirty.y0);
return true;
} | java | public boolean process( T image ) {
if( failed )
return false;
targetModel.setImage(image);
// mark the region where the pdf has been modified as dirty
dirty.set(location.x0, location.y0, location.x0 + location.width, location.y0 + location.height);
// compute the pdf inside the initial rectangle
updatePdfImage(location.x0 , location.y0 , location.x0+location.width , location.y0+location.height);
// current location of the target
int x0 = location.x0;
int y0 = location.y0;
// previous location of the target in the most recent iteration
int prevX = x0;
int prevY = y0;
// iterate until it converges or reaches the maximum number of iterations
for( int i = 0; i < maxIterations; i++ ) {
// compute the weighted centroid using the likelihood function
float totalPdf = 0;
float sumX = 0;
float sumY = 0;
for( int y = 0; y < location.height; y++ ) {
int indexPdf = pdf.startIndex + pdf.stride*(y+y0) + x0;
for( int x = 0; x < location.width; x++ ) {
float p = pdf.data[indexPdf++];
totalPdf += p;
sumX += (x0+x)*p;
sumY += (y0+y)*p;
}
}
// if the target isn't likely to be in view, give up
if( totalPdf <= minimumSum ) {
failed = true;
return false;
}
// Use the new center to find the new top left corner, while rounding to the nearest integer
x0 = (int)(sumX/totalPdf-location.width/2+0.5f);
y0 = (int)(sumY/totalPdf-location.height/2+0.5f);
// make sure it doesn't go outside the image
if( x0 < 0 )
x0 = 0;
else if( x0 >= image.width-location.width )
x0 = image.width-location.width;
if( y0 < 0 )
y0 = 0;
else if( y0 >= image.height-location.height )
y0 = image.height-location.height;
// see if it has converged
if( x0 == prevX && y0 == prevY )
break;
// save the previous location
prevX = x0;
prevY = y0;
// update the pdf
updatePdfImage(x0,y0,x0+location.width,y0+location.height);
}
// update the output
location.x0 = x0;
location.y0 = y0;
// clean up the image for the next iteration
ImageMiscOps.fillRectangle(pdf,-1,dirty.x0,dirty.y0,dirty.x1-dirty.x0,dirty.y1-dirty.y0);
return true;
} | [
"public",
"boolean",
"process",
"(",
"T",
"image",
")",
"{",
"if",
"(",
"failed",
")",
"return",
"false",
";",
"targetModel",
".",
"setImage",
"(",
"image",
")",
";",
"// mark the region where the pdf has been modified as dirty",
"dirty",
".",
"set",
"(",
"locat... | Updates the target's location in the image by performing a mean-shift search. Returns if it was
successful at finding the target or not. If it fails once it will need to be re-initialized
@param image Most recent image in the sequence
@return true for success or false if it failed | [
"Updates",
"the",
"target",
"s",
"location",
"in",
"the",
"image",
"by",
"performing",
"a",
"mean",
"-",
"shift",
"search",
".",
"Returns",
"if",
"it",
"was",
"successful",
"at",
"finding",
"the",
"target",
"or",
"not",
".",
"If",
"it",
"fails",
"once",
... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/meanshift/TrackerMeanShiftLikelihood.java#L141-L221 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/tracker/meanshift/TrackerMeanShiftLikelihood.java | TrackerMeanShiftLikelihood.updatePdfImage | protected void updatePdfImage( int x0 , int y0 , int x1 , int y1 ) {
for( int y = y0; y < y1; y++ ) {
int indexOut = pdf.startIndex + pdf.stride*y + x0;
for( int x = x0; x < x1; x++ , indexOut++ ) {
if( pdf.data[indexOut] < 0 )
pdf.data[indexOut] = targetModel.compute(x, y);
}
}
// update the dirty region
if( dirty.x0 > x0 )
dirty.x0 = x0;
if( dirty.y0 > y0 )
dirty.y0 = y0;
if( dirty.x1 < x1 )
dirty.x1 = x1;
if( dirty.y1 < y1 )
dirty.y1 = y1;
} | java | protected void updatePdfImage( int x0 , int y0 , int x1 , int y1 ) {
for( int y = y0; y < y1; y++ ) {
int indexOut = pdf.startIndex + pdf.stride*y + x0;
for( int x = x0; x < x1; x++ , indexOut++ ) {
if( pdf.data[indexOut] < 0 )
pdf.data[indexOut] = targetModel.compute(x, y);
}
}
// update the dirty region
if( dirty.x0 > x0 )
dirty.x0 = x0;
if( dirty.y0 > y0 )
dirty.y0 = y0;
if( dirty.x1 < x1 )
dirty.x1 = x1;
if( dirty.y1 < y1 )
dirty.y1 = y1;
} | [
"protected",
"void",
"updatePdfImage",
"(",
"int",
"x0",
",",
"int",
"y0",
",",
"int",
"x1",
",",
"int",
"y1",
")",
"{",
"for",
"(",
"int",
"y",
"=",
"y0",
";",
"y",
"<",
"y1",
";",
"y",
"++",
")",
"{",
"int",
"indexOut",
"=",
"pdf",
".",
"st... | Computes the PDF only inside the image as needed amd update the dirty rectangle | [
"Computes",
"the",
"PDF",
"only",
"inside",
"the",
"image",
"as",
"needed",
"amd",
"update",
"the",
"dirty",
"rectangle"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/tracker/meanshift/TrackerMeanShiftLikelihood.java#L226-L246 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ms/SegmentMeanShiftSearchGray.java | SegmentMeanShiftSearchGray.process | @Override
public void process( T image ) {
// initialize data structures
this.image = image;
this.stopRequested = false;
modeLocation.reset();
modeColor.reset();
modeMemberCount.reset();
interpolate.setImage(image);
pixelToMode.reshape(image.width, image.height);
quickMode.reshape(image.width, image.height);
// mark as -1 so it knows which pixels have been assigned a mode already and can skip them
ImageMiscOps.fill(pixelToMode, -1);
// mark all pixels are not being a mode
ImageMiscOps.fill(quickMode,-1);
// use mean shift to find the peak of each pixel in the image
int indexImg = 0;
for( int y = 0; y < image.height&& !stopRequested; y++ ) {
for( int x = 0; x < image.width; x++ , indexImg++) {
if( pixelToMode.data[indexImg] != -1 ) {
int peakIndex = pixelToMode.data[indexImg];
modeMemberCount.data[peakIndex]++;
continue;
}
float meanColor = interpolate.get(x, y);
findPeak(x,y, meanColor);
// convert mean-shift location into pixel index
int modeX = (int)(this.modeX +0.5f);
int modeY = (int)(this.modeY +0.5f);
int modePixelIndex = modeY*image.width + modeX;
// get index in the list of peaks
int modeIndex = quickMode.data[modePixelIndex];
// If the mode is new add it to the list
if( modeIndex < 0 ) {
modeIndex = this.modeLocation.size();
this.modeLocation.grow().set(modeX, modeY);
// Save the peak's color
modeColor.grow()[0] = meanGray;
// Mark the mode in the segment image
quickMode.data[modePixelIndex] = modeIndex;
// Set the initial count to zero. This will be incremented when it is traversed later on
modeMemberCount.add(0);
}
// add this pixel to the membership list
modeMemberCount.data[modeIndex]++;
// Add all pixels it traversed through to the membership of this mode
// This is an approximate of mean-shift
for( int i = 0; i < history.size; i++ ) {
Point2D_F32 p = history.get(i);
int px = (int)(p.x+0.5f);
int py = (int)(p.y+0.5f);
int index = pixelToMode.getIndex(px,py);
if( pixelToMode.data[index] == -1 ) {
pixelToMode.data[index] = modeIndex;
}
}
}
}
} | java | @Override
public void process( T image ) {
// initialize data structures
this.image = image;
this.stopRequested = false;
modeLocation.reset();
modeColor.reset();
modeMemberCount.reset();
interpolate.setImage(image);
pixelToMode.reshape(image.width, image.height);
quickMode.reshape(image.width, image.height);
// mark as -1 so it knows which pixels have been assigned a mode already and can skip them
ImageMiscOps.fill(pixelToMode, -1);
// mark all pixels are not being a mode
ImageMiscOps.fill(quickMode,-1);
// use mean shift to find the peak of each pixel in the image
int indexImg = 0;
for( int y = 0; y < image.height&& !stopRequested; y++ ) {
for( int x = 0; x < image.width; x++ , indexImg++) {
if( pixelToMode.data[indexImg] != -1 ) {
int peakIndex = pixelToMode.data[indexImg];
modeMemberCount.data[peakIndex]++;
continue;
}
float meanColor = interpolate.get(x, y);
findPeak(x,y, meanColor);
// convert mean-shift location into pixel index
int modeX = (int)(this.modeX +0.5f);
int modeY = (int)(this.modeY +0.5f);
int modePixelIndex = modeY*image.width + modeX;
// get index in the list of peaks
int modeIndex = quickMode.data[modePixelIndex];
// If the mode is new add it to the list
if( modeIndex < 0 ) {
modeIndex = this.modeLocation.size();
this.modeLocation.grow().set(modeX, modeY);
// Save the peak's color
modeColor.grow()[0] = meanGray;
// Mark the mode in the segment image
quickMode.data[modePixelIndex] = modeIndex;
// Set the initial count to zero. This will be incremented when it is traversed later on
modeMemberCount.add(0);
}
// add this pixel to the membership list
modeMemberCount.data[modeIndex]++;
// Add all pixels it traversed through to the membership of this mode
// This is an approximate of mean-shift
for( int i = 0; i < history.size; i++ ) {
Point2D_F32 p = history.get(i);
int px = (int)(p.x+0.5f);
int py = (int)(p.y+0.5f);
int index = pixelToMode.getIndex(px,py);
if( pixelToMode.data[index] == -1 ) {
pixelToMode.data[index] = modeIndex;
}
}
}
}
} | [
"@",
"Override",
"public",
"void",
"process",
"(",
"T",
"image",
")",
"{",
"// initialize data structures",
"this",
".",
"image",
"=",
"image",
";",
"this",
".",
"stopRequested",
"=",
"false",
";",
"modeLocation",
".",
"reset",
"(",
")",
";",
"modeColor",
... | Performs mean-shift clustering on the input image
@param image Input image | [
"Performs",
"mean",
"-",
"shift",
"clustering",
"on",
"the",
"input",
"image"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ms/SegmentMeanShiftSearchGray.java#L62-L131 | train |
lessthanoptimal/BoofCV | main/boofcv-geo/src/main/java/boofcv/struct/geo/Point2D3D.java | Point2D3D.set | public void set( Point2D3D src ) {
observation.set(src.observation);
location.set(src.location);
} | java | public void set( Point2D3D src ) {
observation.set(src.observation);
location.set(src.location);
} | [
"public",
"void",
"set",
"(",
"Point2D3D",
"src",
")",
"{",
"observation",
".",
"set",
"(",
"src",
".",
"observation",
")",
";",
"location",
".",
"set",
"(",
"src",
".",
"location",
")",
";",
"}"
] | Sets 'this' to be identical to 'src'. | [
"Sets",
"this",
"to",
"be",
"identical",
"to",
"src",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-geo/src/main/java/boofcv/struct/geo/Point2D3D.java#L52-L55 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polygon/DetectPolygonBinaryGrayRefine.java | DetectPolygonBinaryGrayRefine.clearLensDistortion | public void clearLensDistortion() {
detector.clearLensDistortion();
if( refineGray != null )
refineGray.clearLensDistortion();
edgeIntensity.setTransform(null);
} | java | public void clearLensDistortion() {
detector.clearLensDistortion();
if( refineGray != null )
refineGray.clearLensDistortion();
edgeIntensity.setTransform(null);
} | [
"public",
"void",
"clearLensDistortion",
"(",
")",
"{",
"detector",
".",
"clearLensDistortion",
"(",
")",
";",
"if",
"(",
"refineGray",
"!=",
"null",
")",
"refineGray",
".",
"clearLensDistortion",
"(",
")",
";",
"edgeIntensity",
".",
"setTransform",
"(",
"null... | Discard previously set lens distortion models | [
"Discard",
"previously",
"set",
"lens",
"distortion",
"models"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polygon/DetectPolygonBinaryGrayRefine.java#L132-L137 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polygon/DetectPolygonBinaryGrayRefine.java | DetectPolygonBinaryGrayRefine.process | public void process(T gray , GrayU8 binary ) {
detector.process(gray,binary);
if( refineGray != null )
refineGray.setImage(gray);
edgeIntensity.setImage(gray);
long time0 = System.nanoTime();
FastQueue<DetectPolygonFromContour.Info> detections = detector.getFound();
if( adjustForBias != null ) {
int minSides = getMinimumSides();
for (int i = detections.size()-1; i >= 0; i-- ) {
Polygon2D_F64 p = detections.get(i).polygon;
adjustForBias.process(p, detector.isOutputClockwise());
// When the polygon is adjusted for bias a point might need to be removed because it's
// almost parallel. This could cause the shape to have too few corners and needs to be removed.
if( p.size() < minSides)
detections.remove(i);
}
}
long time1 = System.nanoTime();
double milli = (time1-time0)*1e-6;
milliAdjustBias.update(milli);
// System.out.printf(" contour %7.2f shapes %7.2f adjust_bias %7.2f\n",
// detector.getMilliShapes(),detector.getMilliShapes(),milliAdjustBias);
} | java | public void process(T gray , GrayU8 binary ) {
detector.process(gray,binary);
if( refineGray != null )
refineGray.setImage(gray);
edgeIntensity.setImage(gray);
long time0 = System.nanoTime();
FastQueue<DetectPolygonFromContour.Info> detections = detector.getFound();
if( adjustForBias != null ) {
int minSides = getMinimumSides();
for (int i = detections.size()-1; i >= 0; i-- ) {
Polygon2D_F64 p = detections.get(i).polygon;
adjustForBias.process(p, detector.isOutputClockwise());
// When the polygon is adjusted for bias a point might need to be removed because it's
// almost parallel. This could cause the shape to have too few corners and needs to be removed.
if( p.size() < minSides)
detections.remove(i);
}
}
long time1 = System.nanoTime();
double milli = (time1-time0)*1e-6;
milliAdjustBias.update(milli);
// System.out.printf(" contour %7.2f shapes %7.2f adjust_bias %7.2f\n",
// detector.getMilliShapes(),detector.getMilliShapes(),milliAdjustBias);
} | [
"public",
"void",
"process",
"(",
"T",
"gray",
",",
"GrayU8",
"binary",
")",
"{",
"detector",
".",
"process",
"(",
"gray",
",",
"binary",
")",
";",
"if",
"(",
"refineGray",
"!=",
"null",
")",
"refineGray",
".",
"setImage",
"(",
"gray",
")",
";",
"edg... | Detects polygons inside the grayscale image and its thresholded version
@param gray Gray scale image
@param binary Binary version of grayscale image | [
"Detects",
"polygons",
"inside",
"the",
"grayscale",
"image",
"and",
"its",
"thresholded",
"version"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polygon/DetectPolygonBinaryGrayRefine.java#L149-L177 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polygon/DetectPolygonBinaryGrayRefine.java | DetectPolygonBinaryGrayRefine.refine | public boolean refine( DetectPolygonFromContour.Info info ) {
double before,after;
if( edgeIntensity.computeEdge(info.polygon,!detector.isOutputClockwise()) ) {
before = edgeIntensity.getAverageOutside() - edgeIntensity.getAverageInside();
} else {
return false;
}
boolean success = false;
if( refineContour != null ) {
List<Point2D_I32> contour = detector.getContour(info);
refineContour.process(contour,info.splits,work);
if( adjustForBias != null )
adjustForBias.process(work, detector.isOutputClockwise());
if( edgeIntensity.computeEdge(work,!detector.isOutputClockwise()) ) {
after = edgeIntensity.getAverageOutside() - edgeIntensity.getAverageInside();
if( after > before ) {
info.edgeInside = edgeIntensity.getAverageInside();
info.edgeOutside = edgeIntensity.getAverageOutside();
info.polygon.set(work);
success = true;
before = after;
}
}
}
if( functionAdjust != null ) {
functionAdjust.adjust(info, detector.isOutputClockwise());
}
if( refineGray != null ) {
work.vertexes.resize(info.polygon.size());
if( refineGray.refine(info.polygon,work) ) {
if( edgeIntensity.computeEdge(work,!detector.isOutputClockwise()) ) {
after = edgeIntensity.getAverageOutside() - edgeIntensity.getAverageInside();
// basically, unless it diverged stick with this optimization
// a near tie
if( after*1.5 > before ) {
info.edgeInside = edgeIntensity.getAverageInside();
info.edgeOutside = edgeIntensity.getAverageOutside();
info.polygon.set(work);
success = true;
}
}
}
}
return success;
} | java | public boolean refine( DetectPolygonFromContour.Info info ) {
double before,after;
if( edgeIntensity.computeEdge(info.polygon,!detector.isOutputClockwise()) ) {
before = edgeIntensity.getAverageOutside() - edgeIntensity.getAverageInside();
} else {
return false;
}
boolean success = false;
if( refineContour != null ) {
List<Point2D_I32> contour = detector.getContour(info);
refineContour.process(contour,info.splits,work);
if( adjustForBias != null )
adjustForBias.process(work, detector.isOutputClockwise());
if( edgeIntensity.computeEdge(work,!detector.isOutputClockwise()) ) {
after = edgeIntensity.getAverageOutside() - edgeIntensity.getAverageInside();
if( after > before ) {
info.edgeInside = edgeIntensity.getAverageInside();
info.edgeOutside = edgeIntensity.getAverageOutside();
info.polygon.set(work);
success = true;
before = after;
}
}
}
if( functionAdjust != null ) {
functionAdjust.adjust(info, detector.isOutputClockwise());
}
if( refineGray != null ) {
work.vertexes.resize(info.polygon.size());
if( refineGray.refine(info.polygon,work) ) {
if( edgeIntensity.computeEdge(work,!detector.isOutputClockwise()) ) {
after = edgeIntensity.getAverageOutside() - edgeIntensity.getAverageInside();
// basically, unless it diverged stick with this optimization
// a near tie
if( after*1.5 > before ) {
info.edgeInside = edgeIntensity.getAverageInside();
info.edgeOutside = edgeIntensity.getAverageOutside();
info.polygon.set(work);
success = true;
}
}
}
}
return success;
} | [
"public",
"boolean",
"refine",
"(",
"DetectPolygonFromContour",
".",
"Info",
"info",
")",
"{",
"double",
"before",
",",
"after",
";",
"if",
"(",
"edgeIntensity",
".",
"computeEdge",
"(",
"info",
".",
"polygon",
",",
"!",
"detector",
".",
"isOutputClockwise",
... | Refines the fit to the specified polygon. Only info.polygon is modified
@param info The polygon and related info
@return true if successful or false if not | [
"Refines",
"the",
"fit",
"to",
"the",
"specified",
"polygon",
".",
"Only",
"info",
".",
"polygon",
"is",
"modified"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polygon/DetectPolygonBinaryGrayRefine.java#L184-L236 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/shapes/polygon/DetectPolygonBinaryGrayRefine.java | DetectPolygonBinaryGrayRefine.refineAll | public void refineAll() {
List<DetectPolygonFromContour.Info> detections = detector.getFound().toList();
for (int i = 0; i < detections.size(); i++) {
refine(detections.get(i));
}
} | java | public void refineAll() {
List<DetectPolygonFromContour.Info> detections = detector.getFound().toList();
for (int i = 0; i < detections.size(); i++) {
refine(detections.get(i));
}
} | [
"public",
"void",
"refineAll",
"(",
")",
"{",
"List",
"<",
"DetectPolygonFromContour",
".",
"Info",
">",
"detections",
"=",
"detector",
".",
"getFound",
"(",
")",
".",
"toList",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"detecti... | Refines all the detected polygons and places them into the provided list. Polygons which fail the refinement
step are not added. | [
"Refines",
"all",
"the",
"detected",
"polygons",
"and",
"places",
"them",
"into",
"the",
"provided",
"list",
".",
"Polygons",
"which",
"fail",
"the",
"refinement",
"step",
"are",
"not",
"added",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/shapes/polygon/DetectPolygonBinaryGrayRefine.java#L242-L248 | train |
lessthanoptimal/BoofCV | main/boofcv-types/src/main/java/boofcv/alg/InputSanityCheck.java | InputSanityCheck.checkReshape | public static <T extends ImageGray<T>> T checkReshape(T target , ImageGray testImage , Class<T> targetType )
{
if( target == null ) {
return GeneralizedImageOps.createSingleBand(targetType, testImage.width, testImage.height);
} else if( target.width != testImage.width || target.height != testImage.height ) {
target.reshape(testImage.width,testImage.height);
}
return target;
} | java | public static <T extends ImageGray<T>> T checkReshape(T target , ImageGray testImage , Class<T> targetType )
{
if( target == null ) {
return GeneralizedImageOps.createSingleBand(targetType, testImage.width, testImage.height);
} else if( target.width != testImage.width || target.height != testImage.height ) {
target.reshape(testImage.width,testImage.height);
}
return target;
} | [
"public",
"static",
"<",
"T",
"extends",
"ImageGray",
"<",
"T",
">",
">",
"T",
"checkReshape",
"(",
"T",
"target",
",",
"ImageGray",
"testImage",
",",
"Class",
"<",
"T",
">",
"targetType",
")",
"{",
"if",
"(",
"target",
"==",
"null",
")",
"{",
"retur... | Checks to see if the target image is null or if it is a different size than
the test image. If it is null then a new image is returned, otherwise
target is reshaped and returned.
@param target
@param testImage
@param targetType
@param <T>
@return | [
"Checks",
"to",
"see",
"if",
"the",
"target",
"image",
"is",
"null",
"or",
"if",
"it",
"is",
"a",
"different",
"size",
"than",
"the",
"test",
"image",
".",
"If",
"it",
"is",
"null",
"then",
"a",
"new",
"image",
"is",
"returned",
"otherwise",
"target",
... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-types/src/main/java/boofcv/alg/InputSanityCheck.java#L44-L52 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/interest/FeaturePyramid.java | FeaturePyramid.findLocalScaleSpaceMax | protected void findLocalScaleSpaceMax(PyramidFloat<T> ss, int layerID) {
int index0 = spaceIndex;
int index1 = (spaceIndex + 1) % 3;
int index2 = (spaceIndex + 2) % 3;
List<Point2D_I16> candidates = maximums[index1];
ImageBorder_F32 inten0 = (ImageBorder_F32) FactoryImageBorderAlgs.value(intensities[index0], 0);
GrayF32 inten1 = intensities[index1];
ImageBorder_F32 inten2 = (ImageBorder_F32) FactoryImageBorderAlgs.value(intensities[index2], 0);
float scale0 = (float) ss.scale[layerID - 1];
float scale1 = (float) ss.scale[layerID];
float scale2 = (float) ss.scale[layerID + 1];
float sigma0 = (float) ss.getSigma(layerID - 1);
float sigma1 = (float) ss.getSigma(layerID);
float sigma2 = (float) ss.getSigma(layerID + 1);
// not sure if this is the correct way to handle the change in scale
float ss0 = (float) (Math.pow(sigma0, scalePower)/scale0);
float ss1 = (float) (Math.pow(sigma1, scalePower)/scale1);
float ss2 = (float) (Math.pow(sigma2, scalePower)/scale2);
for (Point2D_I16 c : candidates) {
float val = ss1 * inten1.get(c.x, c.y);
// find pixel location in each image's local coordinate
int x0 = (int) (c.x * scale1 / scale0);
int y0 = (int) (c.y * scale1 / scale0);
int x2 = (int) (c.x * scale1 / scale2);
int y2 = (int) (c.y * scale1 / scale2);
if (checkMax(inten0, val / ss0, x0, y0) && checkMax(inten2, val / ss2, x2, y2)) {
// put features into the scale of the upper image
foundPoints.add(new ScalePoint(c.x * scale1, c.y * scale1, sigma1));
}
}
} | java | protected void findLocalScaleSpaceMax(PyramidFloat<T> ss, int layerID) {
int index0 = spaceIndex;
int index1 = (spaceIndex + 1) % 3;
int index2 = (spaceIndex + 2) % 3;
List<Point2D_I16> candidates = maximums[index1];
ImageBorder_F32 inten0 = (ImageBorder_F32) FactoryImageBorderAlgs.value(intensities[index0], 0);
GrayF32 inten1 = intensities[index1];
ImageBorder_F32 inten2 = (ImageBorder_F32) FactoryImageBorderAlgs.value(intensities[index2], 0);
float scale0 = (float) ss.scale[layerID - 1];
float scale1 = (float) ss.scale[layerID];
float scale2 = (float) ss.scale[layerID + 1];
float sigma0 = (float) ss.getSigma(layerID - 1);
float sigma1 = (float) ss.getSigma(layerID);
float sigma2 = (float) ss.getSigma(layerID + 1);
// not sure if this is the correct way to handle the change in scale
float ss0 = (float) (Math.pow(sigma0, scalePower)/scale0);
float ss1 = (float) (Math.pow(sigma1, scalePower)/scale1);
float ss2 = (float) (Math.pow(sigma2, scalePower)/scale2);
for (Point2D_I16 c : candidates) {
float val = ss1 * inten1.get(c.x, c.y);
// find pixel location in each image's local coordinate
int x0 = (int) (c.x * scale1 / scale0);
int y0 = (int) (c.y * scale1 / scale0);
int x2 = (int) (c.x * scale1 / scale2);
int y2 = (int) (c.y * scale1 / scale2);
if (checkMax(inten0, val / ss0, x0, y0) && checkMax(inten2, val / ss2, x2, y2)) {
// put features into the scale of the upper image
foundPoints.add(new ScalePoint(c.x * scale1, c.y * scale1, sigma1));
}
}
} | [
"protected",
"void",
"findLocalScaleSpaceMax",
"(",
"PyramidFloat",
"<",
"T",
">",
"ss",
",",
"int",
"layerID",
")",
"{",
"int",
"index0",
"=",
"spaceIndex",
";",
"int",
"index1",
"=",
"(",
"spaceIndex",
"+",
"1",
")",
"%",
"3",
";",
"int",
"index2",
"... | Searches the pyramid layers up and down to see if the found 2D features are also scale space maximums. | [
"Searches",
"the",
"pyramid",
"layers",
"up",
"and",
"down",
"to",
"see",
"if",
"the",
"found",
"2D",
"features",
"are",
"also",
"scale",
"space",
"maximums",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/feature/detect/interest/FeaturePyramid.java#L168-L206 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquaresIntoCrossClusters.java | SquaresIntoCrossClusters.getCornerIndex | int getCornerIndex( SquareNode node , double x , double y ) {
for (int i = 0; i < node.square.size(); i++) {
Point2D_F64 c = node.square.get(i);
if( c.x == x && c.y == y )
return i;
}
throw new RuntimeException("BUG!");
} | java | int getCornerIndex( SquareNode node , double x , double y ) {
for (int i = 0; i < node.square.size(); i++) {
Point2D_F64 c = node.square.get(i);
if( c.x == x && c.y == y )
return i;
}
throw new RuntimeException("BUG!");
} | [
"int",
"getCornerIndex",
"(",
"SquareNode",
"node",
",",
"double",
"x",
",",
"double",
"y",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"node",
".",
"square",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"Point2D_F64",
"c",
"... | Returns the corner index of the specified coordinate | [
"Returns",
"the",
"corner",
"index",
"of",
"the",
"specified",
"coordinate"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquaresIntoCrossClusters.java#L173-L181 | train |
lessthanoptimal/BoofCV | main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquaresIntoCrossClusters.java | SquaresIntoCrossClusters.candidateIsMuchCloser | boolean candidateIsMuchCloser( SquareNode node0 ,
SquareNode node1 ,
double distance2 )
{
double length = Math.max(node0.largestSide,node1.largestSide)*tooFarFraction;
length *= length;
if( distance2 > length)
return false;
return distance2 <= length;
} | java | boolean candidateIsMuchCloser( SquareNode node0 ,
SquareNode node1 ,
double distance2 )
{
double length = Math.max(node0.largestSide,node1.largestSide)*tooFarFraction;
length *= length;
if( distance2 > length)
return false;
return distance2 <= length;
} | [
"boolean",
"candidateIsMuchCloser",
"(",
"SquareNode",
"node0",
",",
"SquareNode",
"node1",
",",
"double",
"distance2",
")",
"{",
"double",
"length",
"=",
"Math",
".",
"max",
"(",
"node0",
".",
"largestSide",
",",
"node1",
".",
"largestSide",
")",
"*",
"tooF... | Checks to see if the two corners which are to be connected are by far the two closest corners between the two
squares | [
"Checks",
"to",
"see",
"if",
"the",
"two",
"corners",
"which",
"are",
"to",
"be",
"connected",
"are",
"by",
"far",
"the",
"two",
"closest",
"corners",
"between",
"the",
"two",
"squares"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-recognition/src/main/java/boofcv/alg/fiducial/calib/squares/SquaresIntoCrossClusters.java#L209-L219 | train |
lessthanoptimal/BoofCV | integration/boofcv-swing/src/main/java/boofcv/gui/ApplicationLauncherApp.java | ApplicationLauncherApp.handleContextMenu | private void handleContextMenu(JTree tree, int x, int y) {
TreePath path = tree.getPathForLocation(x, y);
tree.setSelectionPath(path);
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if (node == null)
return;
if (!node.isLeaf()) {
tree.setSelectionPath(null);
return;
}
final AppInfo info = (AppInfo) node.getUserObject();
JMenuItem copyname = new JMenuItem("Copy Name");
copyname.addActionListener(e -> {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(info.app.getSimpleName()), null);
});
JMenuItem copypath = new JMenuItem("Copy Path");
copypath.addActionListener(e -> {
String path1 = UtilIO.getSourcePath(info.app.getPackage().getName(), info.app.getSimpleName());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(path1), null);
});
JMenuItem github = new JMenuItem("Go to Github");
github.addActionListener(e -> openInGitHub(info));
JPopupMenu submenu = new JPopupMenu();
submenu.add(copyname);
submenu.add(copypath);
submenu.add(github);
submenu.show(tree, x, y);
} | java | private void handleContextMenu(JTree tree, int x, int y) {
TreePath path = tree.getPathForLocation(x, y);
tree.setSelectionPath(path);
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if (node == null)
return;
if (!node.isLeaf()) {
tree.setSelectionPath(null);
return;
}
final AppInfo info = (AppInfo) node.getUserObject();
JMenuItem copyname = new JMenuItem("Copy Name");
copyname.addActionListener(e -> {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(info.app.getSimpleName()), null);
});
JMenuItem copypath = new JMenuItem("Copy Path");
copypath.addActionListener(e -> {
String path1 = UtilIO.getSourcePath(info.app.getPackage().getName(), info.app.getSimpleName());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(path1), null);
});
JMenuItem github = new JMenuItem("Go to Github");
github.addActionListener(e -> openInGitHub(info));
JPopupMenu submenu = new JPopupMenu();
submenu.add(copyname);
submenu.add(copypath);
submenu.add(github);
submenu.show(tree, x, y);
} | [
"private",
"void",
"handleContextMenu",
"(",
"JTree",
"tree",
",",
"int",
"x",
",",
"int",
"y",
")",
"{",
"TreePath",
"path",
"=",
"tree",
".",
"getPathForLocation",
"(",
"x",
",",
"y",
")",
";",
"tree",
".",
"setSelectionPath",
"(",
"path",
")",
";",
... | Displays a context menu for a class leaf node
Allows copying of the name and the path to the source | [
"Displays",
"a",
"context",
"menu",
"for",
"a",
"class",
"leaf",
"node",
"Allows",
"copying",
"of",
"the",
"name",
"and",
"the",
"path",
"to",
"the",
"source"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/integration/boofcv-swing/src/main/java/boofcv/gui/ApplicationLauncherApp.java#L337-L371 | train |
lessthanoptimal/BoofCV | integration/boofcv-swing/src/main/java/boofcv/gui/ApplicationLauncherApp.java | ApplicationLauncherApp.openInGitHub | private void openInGitHub( AppInfo info ) {
if (Desktop.isDesktopSupported()) {
try {
URI uri = new URI(UtilIO.getGithubURL(info.app.getPackage().getName(), info.app.getSimpleName()));
if (!uri.getPath().isEmpty())
Desktop.getDesktop().browse(uri);
else
System.err.println("Bad URL received");
} catch (Exception e1) {
JOptionPane.showMessageDialog(this,"Open GitHub Error",
"Error connecting: "+e1.getMessage(),JOptionPane.ERROR_MESSAGE);
System.err.println(e1.getMessage());
}
}
} | java | private void openInGitHub( AppInfo info ) {
if (Desktop.isDesktopSupported()) {
try {
URI uri = new URI(UtilIO.getGithubURL(info.app.getPackage().getName(), info.app.getSimpleName()));
if (!uri.getPath().isEmpty())
Desktop.getDesktop().browse(uri);
else
System.err.println("Bad URL received");
} catch (Exception e1) {
JOptionPane.showMessageDialog(this,"Open GitHub Error",
"Error connecting: "+e1.getMessage(),JOptionPane.ERROR_MESSAGE);
System.err.println(e1.getMessage());
}
}
} | [
"private",
"void",
"openInGitHub",
"(",
"AppInfo",
"info",
")",
"{",
"if",
"(",
"Desktop",
".",
"isDesktopSupported",
"(",
")",
")",
"{",
"try",
"{",
"URI",
"uri",
"=",
"new",
"URI",
"(",
"UtilIO",
".",
"getGithubURL",
"(",
"info",
".",
"app",
".",
"... | Opens github page of source code up in a browser window | [
"Opens",
"github",
"page",
"of",
"source",
"code",
"up",
"in",
"a",
"browser",
"window"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/integration/boofcv-swing/src/main/java/boofcv/gui/ApplicationLauncherApp.java#L376-L391 | train |
lessthanoptimal/BoofCV | integration/boofcv-swing/src/main/java/boofcv/gui/ApplicationLauncherApp.java | ApplicationLauncherApp.killAllProcesses | public void killAllProcesses( long blockTimeMS ) {
// remove already dead processes from the GUI
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
DefaultListModel model = (DefaultListModel)processList.getModel();
for (int i = model.size()-1; i >= 0; i--) {
ActiveProcess p = (ActiveProcess)model.get(i);
removeProcessTab(p,false);
}
}
});
// kill processes that are already running
synchronized (processes) {
for (int i = 0; i < processes.size(); i++) {
processes.get(i).requestKill();
}
}
// block until everything is dead
if( blockTimeMS > 0 ) {
long abortTime = System.currentTimeMillis()+blockTimeMS;
while( abortTime > System.currentTimeMillis() ) {
int total = 0;
synchronized (processes) {
for (int i = 0; i < processes.size(); i++) {
if (!processes.get(i).isActive()) {
total++;
}
}
if( processes.size() == total ) {
break;
}
}
}
}
} | java | public void killAllProcesses( long blockTimeMS ) {
// remove already dead processes from the GUI
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
DefaultListModel model = (DefaultListModel)processList.getModel();
for (int i = model.size()-1; i >= 0; i--) {
ActiveProcess p = (ActiveProcess)model.get(i);
removeProcessTab(p,false);
}
}
});
// kill processes that are already running
synchronized (processes) {
for (int i = 0; i < processes.size(); i++) {
processes.get(i).requestKill();
}
}
// block until everything is dead
if( blockTimeMS > 0 ) {
long abortTime = System.currentTimeMillis()+blockTimeMS;
while( abortTime > System.currentTimeMillis() ) {
int total = 0;
synchronized (processes) {
for (int i = 0; i < processes.size(); i++) {
if (!processes.get(i).isActive()) {
total++;
}
}
if( processes.size() == total ) {
break;
}
}
}
}
} | [
"public",
"void",
"killAllProcesses",
"(",
"long",
"blockTimeMS",
")",
"{",
"// remove already dead processes from the GUI",
"SwingUtilities",
".",
"invokeLater",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"Defa... | Requests that all active processes be killed.
@param blockTimeMS If > 0 then it will block until all processes are killed for the specified number
of milliseconds | [
"Requests",
"that",
"all",
"active",
"processes",
"be",
"killed",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/integration/boofcv-swing/src/main/java/boofcv/gui/ApplicationLauncherApp.java#L415-L452 | train |
lessthanoptimal/BoofCV | integration/boofcv-swing/src/main/java/boofcv/gui/ApplicationLauncherApp.java | ApplicationLauncherApp.intervalAdded | @Override
public void intervalAdded(ListDataEvent e) {
//retrieve the most recently added process and display it
DefaultListModel listModel = (DefaultListModel) e.getSource();
ActiveProcess process = (ActiveProcess) listModel.get(listModel.getSize() - 1);
addProcessTab(process, outputPanel);
} | java | @Override
public void intervalAdded(ListDataEvent e) {
//retrieve the most recently added process and display it
DefaultListModel listModel = (DefaultListModel) e.getSource();
ActiveProcess process = (ActiveProcess) listModel.get(listModel.getSize() - 1);
addProcessTab(process, outputPanel);
} | [
"@",
"Override",
"public",
"void",
"intervalAdded",
"(",
"ListDataEvent",
"e",
")",
"{",
"//retrieve the most recently added process and display it",
"DefaultListModel",
"listModel",
"=",
"(",
"DefaultListModel",
")",
"e",
".",
"getSource",
"(",
")",
";",
"ActiveProcess... | Called after a new process is added to the process list
@param e | [
"Called",
"after",
"a",
"new",
"process",
"is",
"added",
"to",
"the",
"process",
"list"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/integration/boofcv-swing/src/main/java/boofcv/gui/ApplicationLauncherApp.java#L459-L465 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ms/ClusterLabeledImage.java | ClusterLabeledImage.setUpEdges | protected void setUpEdges(GrayS32 input , GrayS32 output ) {
if( connectRule == ConnectRule.EIGHT ) {
setUpEdges8(input,edgesIn);
setUpEdges8(output,edgesOut);
edges[0].set( 1, 0);
edges[1].set( 1, 1);
edges[2].set( 0, 1);
edges[3].set(-1, 0);
} else {
setUpEdges4(input,edgesIn);
setUpEdges4(output,edgesOut);
edges[0].set( 1,0);
edges[1].set( 0, 1);
}
} | java | protected void setUpEdges(GrayS32 input , GrayS32 output ) {
if( connectRule == ConnectRule.EIGHT ) {
setUpEdges8(input,edgesIn);
setUpEdges8(output,edgesOut);
edges[0].set( 1, 0);
edges[1].set( 1, 1);
edges[2].set( 0, 1);
edges[3].set(-1, 0);
} else {
setUpEdges4(input,edgesIn);
setUpEdges4(output,edgesOut);
edges[0].set( 1,0);
edges[1].set( 0, 1);
}
} | [
"protected",
"void",
"setUpEdges",
"(",
"GrayS32",
"input",
",",
"GrayS32",
"output",
")",
"{",
"if",
"(",
"connectRule",
"==",
"ConnectRule",
".",
"EIGHT",
")",
"{",
"setUpEdges8",
"(",
"input",
",",
"edgesIn",
")",
";",
"setUpEdges8",
"(",
"output",
",",... | Declares lookup tables for neighbors | [
"Declares",
"lookup",
"tables",
"for",
"neighbors"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ms/ClusterLabeledImage.java#L88-L104 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ms/ClusterLabeledImage.java | ClusterLabeledImage.process | public void process(GrayS32 input , GrayS32 output , GrowQueue_I32 regionMemberCount ) {
// initialize data structures
this.regionMemberCount = regionMemberCount;
regionMemberCount.reset();
setUpEdges(input,output);
ImageMiscOps.fill(output,-1);
// this is a bit of a hack here. Normally you call the parent's init function.
// since the number of regions is not initially known this will grow
mergeList.reset();
connectInner(input, output);
connectLeftRight(input, output);
connectBottom(input, output);
// Merge together all the regions that are connected in the output image
performMerge(output, regionMemberCount);
} | java | public void process(GrayS32 input , GrayS32 output , GrowQueue_I32 regionMemberCount ) {
// initialize data structures
this.regionMemberCount = regionMemberCount;
regionMemberCount.reset();
setUpEdges(input,output);
ImageMiscOps.fill(output,-1);
// this is a bit of a hack here. Normally you call the parent's init function.
// since the number of regions is not initially known this will grow
mergeList.reset();
connectInner(input, output);
connectLeftRight(input, output);
connectBottom(input, output);
// Merge together all the regions that are connected in the output image
performMerge(output, regionMemberCount);
} | [
"public",
"void",
"process",
"(",
"GrayS32",
"input",
",",
"GrayS32",
"output",
",",
"GrowQueue_I32",
"regionMemberCount",
")",
"{",
"// initialize data structures",
"this",
".",
"regionMemberCount",
"=",
"regionMemberCount",
";",
"regionMemberCount",
".",
"reset",
"(... | Relabels the image such that all pixels with the same label are a member of the same graph.
@param input Labeled input image.
@param output Labeled output image.
@param regionMemberCount (Input/Output) Number of pixels which belong to each group. | [
"Relabels",
"the",
"image",
"such",
"that",
"all",
"pixels",
"with",
"the",
"same",
"label",
"are",
"a",
"member",
"of",
"the",
"same",
"graph",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ms/ClusterLabeledImage.java#L125-L143 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ms/ClusterLabeledImage.java | ClusterLabeledImage.connectInner | protected void connectInner(GrayS32 input, GrayS32 output) {
int startX = connectRule == ConnectRule.EIGHT ? 1 : 0;
for( int y = 0; y < input.height-1; y++ ) {
int indexIn = input.startIndex + y*input.stride + startX;
int indexOut = output.startIndex + y*output.stride + startX;
for( int x = startX; x < input.width-1; x++ , indexIn++, indexOut++) {
int inputLabel = input.data[indexIn];
int outputLabel = output.data[indexOut];
if( outputLabel == -1 ) { // see if it needs to create a new output segment
output.data[indexOut] = outputLabel = regionMemberCount.size;
regionMemberCount.add(1);
mergeList.add(outputLabel);
}
for( int i = 0; i < edgesIn.length; i++ ) {
if( inputLabel == input.data[indexIn+edgesIn[i]] ) {
int outputAdj = output.data[indexOut+edgesOut[i]];
if( outputAdj == -1 ) { // see if not assigned
regionMemberCount.data[outputLabel]++;
output.data[indexOut+edgesOut[i]] = outputLabel;
} else if( outputLabel != outputAdj ) { // see if assigned to different regions
markMerge(outputLabel,outputAdj);
} // do nothing, same input and output labels
}
}
}
}
} | java | protected void connectInner(GrayS32 input, GrayS32 output) {
int startX = connectRule == ConnectRule.EIGHT ? 1 : 0;
for( int y = 0; y < input.height-1; y++ ) {
int indexIn = input.startIndex + y*input.stride + startX;
int indexOut = output.startIndex + y*output.stride + startX;
for( int x = startX; x < input.width-1; x++ , indexIn++, indexOut++) {
int inputLabel = input.data[indexIn];
int outputLabel = output.data[indexOut];
if( outputLabel == -1 ) { // see if it needs to create a new output segment
output.data[indexOut] = outputLabel = regionMemberCount.size;
regionMemberCount.add(1);
mergeList.add(outputLabel);
}
for( int i = 0; i < edgesIn.length; i++ ) {
if( inputLabel == input.data[indexIn+edgesIn[i]] ) {
int outputAdj = output.data[indexOut+edgesOut[i]];
if( outputAdj == -1 ) { // see if not assigned
regionMemberCount.data[outputLabel]++;
output.data[indexOut+edgesOut[i]] = outputLabel;
} else if( outputLabel != outputAdj ) { // see if assigned to different regions
markMerge(outputLabel,outputAdj);
} // do nothing, same input and output labels
}
}
}
}
} | [
"protected",
"void",
"connectInner",
"(",
"GrayS32",
"input",
",",
"GrayS32",
"output",
")",
"{",
"int",
"startX",
"=",
"connectRule",
"==",
"ConnectRule",
".",
"EIGHT",
"?",
"1",
":",
"0",
";",
"for",
"(",
"int",
"y",
"=",
"0",
";",
"y",
"<",
"input... | Examines pixels inside the image without the need for bounds checking | [
"Examines",
"pixels",
"inside",
"the",
"image",
"without",
"the",
"need",
"for",
"bounds",
"checking"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ms/ClusterLabeledImage.java#L148-L178 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ms/ClusterLabeledImage.java | ClusterLabeledImage.connectLeftRight | protected void connectLeftRight(GrayS32 input, GrayS32 output) {
for( int y = 0; y < input.height; y++ ) {
int x = input.width-1;
int inputLabel = input.unsafe_get(x, y);
int outputLabel = output.unsafe_get(x, y);
if( outputLabel == -1 ) { // see if it needs to create a new output segment
outputLabel = regionMemberCount.size;
output.unsafe_set(x,y,outputLabel);
regionMemberCount.add(1);
mergeList.add(outputLabel);
}
// check right first
for( int i = 0; i < edges.length; i++ ) {
Point2D_I32 offset = edges[i];
// make sure it is inside the image
if( !input.isInBounds(x+offset.x,y+offset.y))
continue;
if( inputLabel == input.unsafe_get(x+offset.x,y+offset.y) ) {
int outputAdj = output.unsafe_get(x+offset.x,y+offset.y);
if( outputAdj == -1 ) { // see if not assigned
regionMemberCount.data[outputLabel]++;
output.unsafe_set(x+offset.x,y+offset.y, outputLabel);
} else if( outputLabel != outputAdj ) { // see if assigned to different regions
markMerge(outputLabel,outputAdj);
} // do nothing, same input and output labels
}
}
// skip check of left of 4-connect
if( connectRule != ConnectRule.EIGHT )
continue;
x = 0;
inputLabel = input.unsafe_get(x, y);
outputLabel = output.unsafe_get(x, y);
if( outputLabel == -1 ) { // see if it needs to create a new output segment
outputLabel = regionMemberCount.size;
output.unsafe_set(x,y,outputLabel);
regionMemberCount.add(1);
mergeList.add(outputLabel);
}
for( int i = 0; i < edges.length; i++ ) {
Point2D_I32 offset = edges[i];
// make sure it is inside the image
if( !input.isInBounds(x+offset.x,y+offset.y))
continue;
if( inputLabel == input.unsafe_get(x+offset.x,y+offset.y) ) {
int outputAdj = output.unsafe_get(x+offset.x,y+offset.y);
if( outputAdj == -1 ) { // see if not assigned
regionMemberCount.data[outputLabel]++;
output.unsafe_set(x+offset.x,y+offset.y, outputLabel);
} else if( outputLabel != outputAdj ) { // see if assigned to different regions
markMerge(outputLabel,outputAdj);
} // do nothing, same input and output labels
}
}
}
} | java | protected void connectLeftRight(GrayS32 input, GrayS32 output) {
for( int y = 0; y < input.height; y++ ) {
int x = input.width-1;
int inputLabel = input.unsafe_get(x, y);
int outputLabel = output.unsafe_get(x, y);
if( outputLabel == -1 ) { // see if it needs to create a new output segment
outputLabel = regionMemberCount.size;
output.unsafe_set(x,y,outputLabel);
regionMemberCount.add(1);
mergeList.add(outputLabel);
}
// check right first
for( int i = 0; i < edges.length; i++ ) {
Point2D_I32 offset = edges[i];
// make sure it is inside the image
if( !input.isInBounds(x+offset.x,y+offset.y))
continue;
if( inputLabel == input.unsafe_get(x+offset.x,y+offset.y) ) {
int outputAdj = output.unsafe_get(x+offset.x,y+offset.y);
if( outputAdj == -1 ) { // see if not assigned
regionMemberCount.data[outputLabel]++;
output.unsafe_set(x+offset.x,y+offset.y, outputLabel);
} else if( outputLabel != outputAdj ) { // see if assigned to different regions
markMerge(outputLabel,outputAdj);
} // do nothing, same input and output labels
}
}
// skip check of left of 4-connect
if( connectRule != ConnectRule.EIGHT )
continue;
x = 0;
inputLabel = input.unsafe_get(x, y);
outputLabel = output.unsafe_get(x, y);
if( outputLabel == -1 ) { // see if it needs to create a new output segment
outputLabel = regionMemberCount.size;
output.unsafe_set(x,y,outputLabel);
regionMemberCount.add(1);
mergeList.add(outputLabel);
}
for( int i = 0; i < edges.length; i++ ) {
Point2D_I32 offset = edges[i];
// make sure it is inside the image
if( !input.isInBounds(x+offset.x,y+offset.y))
continue;
if( inputLabel == input.unsafe_get(x+offset.x,y+offset.y) ) {
int outputAdj = output.unsafe_get(x+offset.x,y+offset.y);
if( outputAdj == -1 ) { // see if not assigned
regionMemberCount.data[outputLabel]++;
output.unsafe_set(x+offset.x,y+offset.y, outputLabel);
} else if( outputLabel != outputAdj ) { // see if assigned to different regions
markMerge(outputLabel,outputAdj);
} // do nothing, same input and output labels
}
}
}
} | [
"protected",
"void",
"connectLeftRight",
"(",
"GrayS32",
"input",
",",
"GrayS32",
"output",
")",
"{",
"for",
"(",
"int",
"y",
"=",
"0",
";",
"y",
"<",
"input",
".",
"height",
";",
"y",
"++",
")",
"{",
"int",
"x",
"=",
"input",
".",
"width",
"-",
... | Examines pixels along the left and right border | [
"Examines",
"pixels",
"along",
"the",
"left",
"and",
"right",
"border"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ms/ClusterLabeledImage.java#L183-L251 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ms/ClusterLabeledImage.java | ClusterLabeledImage.connectBottom | protected void connectBottom(GrayS32 input, GrayS32 output) {
for( int x = 0; x < input.width-1; x++ ) {
int y = input.height-1;
int inputLabel = input.unsafe_get(x,y);
int outputLabel = output.unsafe_get(x,y);
if( outputLabel == -1 ) { // see if it needs to create a new output segment
outputLabel = regionMemberCount.size;
output.unsafe_set(x,y,outputLabel);
regionMemberCount.add(1);
mergeList.add(outputLabel);
}
// for 4 and 8 connect the check is only +1 x and 0 y
if( inputLabel == input.unsafe_get(x+1,y) ) {
int outputAdj = output.unsafe_get(x+1,y);
if( outputAdj == -1 ) { // see if not assigned
regionMemberCount.data[outputLabel]++;
output.unsafe_set(x+1,y, outputLabel);
} else if( outputLabel != outputAdj ) { // see if assigned to different regions
markMerge(outputLabel,outputAdj);
} // do nothing, same input and output labels
}
}
} | java | protected void connectBottom(GrayS32 input, GrayS32 output) {
for( int x = 0; x < input.width-1; x++ ) {
int y = input.height-1;
int inputLabel = input.unsafe_get(x,y);
int outputLabel = output.unsafe_get(x,y);
if( outputLabel == -1 ) { // see if it needs to create a new output segment
outputLabel = regionMemberCount.size;
output.unsafe_set(x,y,outputLabel);
regionMemberCount.add(1);
mergeList.add(outputLabel);
}
// for 4 and 8 connect the check is only +1 x and 0 y
if( inputLabel == input.unsafe_get(x+1,y) ) {
int outputAdj = output.unsafe_get(x+1,y);
if( outputAdj == -1 ) { // see if not assigned
regionMemberCount.data[outputLabel]++;
output.unsafe_set(x+1,y, outputLabel);
} else if( outputLabel != outputAdj ) { // see if assigned to different regions
markMerge(outputLabel,outputAdj);
} // do nothing, same input and output labels
}
}
} | [
"protected",
"void",
"connectBottom",
"(",
"GrayS32",
"input",
",",
"GrayS32",
"output",
")",
"{",
"for",
"(",
"int",
"x",
"=",
"0",
";",
"x",
"<",
"input",
".",
"width",
"-",
"1",
";",
"x",
"++",
")",
"{",
"int",
"y",
"=",
"input",
".",
"height"... | Examines pixels along the bottom border | [
"Examines",
"pixels",
"along",
"the",
"bottom",
"border"
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/segmentation/ms/ClusterLabeledImage.java#L256-L281 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/tracker/klt/KltTracker.java | KltTracker.setImage | public void setImage(I image, D derivX, D derivY) {
InputSanityCheck.checkSameShape(image, derivX, derivY);
this.image = image;
this.interpInput.setImage(image);
this.derivX = derivX;
this.derivY = derivY;
} | java | public void setImage(I image, D derivX, D derivY) {
InputSanityCheck.checkSameShape(image, derivX, derivY);
this.image = image;
this.interpInput.setImage(image);
this.derivX = derivX;
this.derivY = derivY;
} | [
"public",
"void",
"setImage",
"(",
"I",
"image",
",",
"D",
"derivX",
",",
"D",
"derivY",
")",
"{",
"InputSanityCheck",
".",
"checkSameShape",
"(",
"image",
",",
"derivX",
",",
"derivY",
")",
";",
"this",
".",
"image",
"=",
"image",
";",
"this",
".",
... | Sets the current image it should be tracking with.
@param image Original input image.
@param derivX Image derivative along the x-axis
@param derivY Image derivative along the y-axis | [
"Sets",
"the",
"current",
"image",
"it",
"should",
"be",
"tracking",
"with",
"."
] | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/tracker/klt/KltTracker.java#L119-L127 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/tracker/klt/KltTracker.java | KltTracker.setDescription | @SuppressWarnings({"SuspiciousNameCombination"})
public boolean setDescription(KltFeature feature) {
setAllowedBounds(feature);
if (!isFullyInside(feature.x, feature.y)) {
if( isFullyOutside(feature.x,feature.y))
return false;
else
return internalSetDescriptionBorder(feature);
}
return internalSetDescription(feature);
} | java | @SuppressWarnings({"SuspiciousNameCombination"})
public boolean setDescription(KltFeature feature) {
setAllowedBounds(feature);
if (!isFullyInside(feature.x, feature.y)) {
if( isFullyOutside(feature.x,feature.y))
return false;
else
return internalSetDescriptionBorder(feature);
}
return internalSetDescription(feature);
} | [
"@",
"SuppressWarnings",
"(",
"{",
"\"SuspiciousNameCombination\"",
"}",
")",
"public",
"boolean",
"setDescription",
"(",
"KltFeature",
"feature",
")",
"{",
"setAllowedBounds",
"(",
"feature",
")",
";",
"if",
"(",
"!",
"isFullyInside",
"(",
"feature",
".",
"x",
... | Sets the features description using the current image and the location of the feature stored in the feature.
If the feature is an illegal location and cannot be set then false is returned.
@param feature Feature description which is to be set. Location must be specified.
@return true if the feature's description was modified. | [
"Sets",
"the",
"features",
"description",
"using",
"the",
"current",
"image",
"and",
"the",
"location",
"of",
"the",
"feature",
"stored",
"in",
"the",
"feature",
".",
"If",
"the",
"feature",
"is",
"an",
"illegal",
"location",
"and",
"cannot",
"be",
"set",
... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/tracker/klt/KltTracker.java#L146-L158 | train |
lessthanoptimal/BoofCV | main/boofcv-feature/src/main/java/boofcv/alg/tracker/klt/KltTracker.java | KltTracker.internalSetDescriptionBorder | protected boolean internalSetDescriptionBorder(KltFeature feature) {
computeSubImageBounds(feature, feature.x, feature.y);
ImageMiscOps.fill(feature.desc, Float.NaN);
feature.desc.subimage(dstX0, dstY0, dstX1, dstY1, subimage);
interpInput.setImage(image);
interpInput.region(srcX0, srcY0, subimage);
feature.derivX.subimage(dstX0, dstY0, dstX1, dstY1, subimage);
interpDeriv.setImage(derivX);
interpDeriv.region(srcX0, srcY0, subimage);
feature.derivY.subimage(dstX0, dstY0, dstX1, dstY1, subimage);
interpDeriv.setImage(derivY);
interpDeriv.region(srcX0, srcY0, subimage);
int total= 0;
Gxx = Gyy = Gxy = 0;
for( int i = 0; i < lengthFeature; i++ ) {
if( Float.isNaN(feature.desc.data[i]))
continue;
total++;
float dX = feature.derivX.data[i];
float dY = feature.derivY.data[i];
Gxx += dX * dX;
Gyy += dY * dY;
Gxy += dX * dY;
}
// technically don't need to save this...
feature.Gxx = Gxx;
feature.Gyy = Gyy;
feature.Gxy = Gxy;
float det = Gxx * Gyy - Gxy * Gxy;
return (det >= config.minDeterminant*total);
} | java | protected boolean internalSetDescriptionBorder(KltFeature feature) {
computeSubImageBounds(feature, feature.x, feature.y);
ImageMiscOps.fill(feature.desc, Float.NaN);
feature.desc.subimage(dstX0, dstY0, dstX1, dstY1, subimage);
interpInput.setImage(image);
interpInput.region(srcX0, srcY0, subimage);
feature.derivX.subimage(dstX0, dstY0, dstX1, dstY1, subimage);
interpDeriv.setImage(derivX);
interpDeriv.region(srcX0, srcY0, subimage);
feature.derivY.subimage(dstX0, dstY0, dstX1, dstY1, subimage);
interpDeriv.setImage(derivY);
interpDeriv.region(srcX0, srcY0, subimage);
int total= 0;
Gxx = Gyy = Gxy = 0;
for( int i = 0; i < lengthFeature; i++ ) {
if( Float.isNaN(feature.desc.data[i]))
continue;
total++;
float dX = feature.derivX.data[i];
float dY = feature.derivY.data[i];
Gxx += dX * dX;
Gyy += dY * dY;
Gxy += dX * dY;
}
// technically don't need to save this...
feature.Gxx = Gxx;
feature.Gyy = Gyy;
feature.Gxy = Gxy;
float det = Gxx * Gyy - Gxy * Gxy;
return (det >= config.minDeterminant*total);
} | [
"protected",
"boolean",
"internalSetDescriptionBorder",
"(",
"KltFeature",
"feature",
")",
"{",
"computeSubImageBounds",
"(",
"feature",
",",
"feature",
".",
"x",
",",
"feature",
".",
"y",
")",
";",
"ImageMiscOps",
".",
"fill",
"(",
"feature",
".",
"desc",
","... | Computes the descriptor for border features. All it needs to do
is save the pixel value, but derivative information is also computed
so that it can reject bad features immediately. | [
"Computes",
"the",
"descriptor",
"for",
"border",
"features",
".",
"All",
"it",
"needs",
"to",
"do",
"is",
"save",
"the",
"pixel",
"value",
"but",
"derivative",
"information",
"is",
"also",
"computed",
"so",
"that",
"it",
"can",
"reject",
"bad",
"features",
... | f01c0243da0ec086285ee722183804d5923bc3ac | https://github.com/lessthanoptimal/BoofCV/blob/f01c0243da0ec086285ee722183804d5923bc3ac/main/boofcv-feature/src/main/java/boofcv/alg/tracker/klt/KltTracker.java#L198-L240 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.