-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cropping mechanism #1602
base: master
Are you sure you want to change the base?
Cropping mechanism #1602
Conversation
photon-client/package.json
Outdated
@@ -1,50 +0,0 @@ | |||
{ | |||
"name": "photonclient", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was all of photon client deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to branch out from the new master so I copied the code from the other guys branch and the one I worked on some to the new one, its overall the same just with the cropping tab
Supersedes #1446 |
b51a3bd
to
0ee6405
Compare
aa2250f
to
8807195
Compare
8807195
to
8b58b2f
Compare
@@ -59,7 +59,6 @@ protected List<AprilTagDetection> process(CVMat in) { | |||
public void setParams(AprilTagDetectionPipeParams newParams) { | |||
if (this.params == null || !this.params.equals(newParams)) { | |||
m_detector.setConfig(newParams.detectorParams); | |||
m_detector.setQuadThresholdParameters(newParams.quadParams); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sus
public final AprilTagDetector.QuadThresholdParameters quadParams; | ||
|
||
public AprilTagDetectionPipeParams( | ||
AprilTagFamily tagFamily, | ||
AprilTagDetector.Config config, | ||
AprilTagDetector.QuadThresholdParameters quadParams) { | ||
public AprilTagDetectionPipeParams(AprilTagFamily tagFamily, AprilTagDetector.Config config) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert these changes?
if (c.x < 0 || c.y < 0) { | ||
// Skip if the corner is less than zero | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this diff?
this.divisor = divisor; | ||
this.drawAllSnapshots = drawSnapshots; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accidental changes here? restore?
public int dynamic_x = 0; | ||
public int dynamic_y = 0; | ||
public int dynamic_width = Integer.MAX_VALUE; | ||
public int dynamic_height = Integer.MAX_VALUE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make sense to serialize?
More in general I'm not sure how I feel about dynamic crop via NT -- it's pretty perpendicular to all our other stuff to date.
Rect staticCrop = settings.getStaticCrop(); | ||
|
||
staticCropPipe.setParams(staticCrop); | ||
staticCropPipe.setDynamicRect(settings.getDynamicCrop()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static crop
setdynamic
hmmm
var quadParams = new AprilTagDetector.QuadThresholdParameters(); | ||
// 5 was the default minClusterPixels in WPILib prior to 2025 | ||
// increasing it causes detection problems when decimate > 1 | ||
quadParams.minClusterPixels = 5; | ||
// these are the same as the values in WPILib 2025 | ||
// setting them here to prevent upstream changes from changing behavior of the detector | ||
quadParams.maxNumMaxima = 10; | ||
quadParams.criticalAngle = 45 * Math.PI / 180.0; | ||
quadParams.maxLineFitMSE = 10.0f; | ||
quadParams.minWhiteBlackDiff = 5; | ||
quadParams.deglitch = false; | ||
|
||
aprilTagDetectionPipe.setParams( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accidental changes?
Mat mat = in.getMat(); | ||
// if (fullyCovers(params, mat)) { | ||
// return in; | ||
// } | ||
Rect proccesor = false ? this.params : dynamiRect; | ||
|
||
int x = MathUtil.clamp(proccesor.x, 0, mat.width()); | ||
int y = MathUtil.clamp(proccesor.y, 0, mat.height()); | ||
int width = MathUtil.clamp(proccesor.width, 0, mat.width() - x); | ||
int height = MathUtil.clamp(proccesor.height, 0, mat.height() - y); | ||
|
||
return new CVMat(mat.submat(y, y + height, x, x + width)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The submat here is just a submat of the overall data array, and does not actually own the native memory. but it still needs to be released. So we need to make sure that we release
both after we are done with them. I'd argue we should release the cropped Mat immediately after Apriltag detection, since we don't use it anywhere else. See this example:
@Test
public void testRelease() {
var pipe = new CropPipe();
pipe.setParams(new Rect(10, 10, 50, 50));
var frameProvider =
new FileFrameProvider(
TestUtils.getApriltagImagePath(TestUtils.ApriltagTestImages.kTag1_640_480, false),
TestUtils.WPI2020Image.FOV,
TestUtils.get2020LifeCamCoeffs(false));
frameProvider.requestFrameThresholdType(FrameThresholdType.GREYSCALE);
var frame = frameProvider.get();
var out = pipe.run(frame.processedImage);
System.out.println(frame.processedImage.getMat());
System.out.println(out.output.getMat());
Imgcodecs.imwrite("pre_release_full.png", frame.processedImage.getMat());
Imgcodecs.imwrite("pre_release_crop.png", out.output.getMat());
frame.release();
System.out.println(frame.processedImage.getMat());
System.out.println(out.output.getMat());
Imgcodecs.imwrite("pose_releaseframe_crop.png", out.output.getMat());
out.output.getMat().release();
System.out.println(frame.processedImage.getMat());
System.out.println(out.output.getMat());
}
Output is:
// Starting state
Mat [ 480*640*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x7ff994f80a30, dataAddr=0x7ff994fb26c0 ]
Mat [ 50*50*CV_8UC1, isCont=false, isSubmat=true, nativeObj=0x7ff994f87910, dataAddr=0x7ff994fb3fca ]
// After releasing the full image Mat
Mat [ 0*0*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x7ff994f80a30, dataAddr=0x0 ]
Mat [ 50*50*CV_8UC1, isCont=false, isSubmat=true, nativeObj=0x7ff994f87910, dataAddr=0x7ff994fb3fca ]
// after releasing both
Mat [ 0*0*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x7ff994f80a30, dataAddr=0x0 ]
Mat [ 0*0*CV_8UC1, isCont=false, isSubmat=true, nativeObj=0x7ff994f87910, dataAddr=0x0 ]
…onvision into cropping-mechanism
Added CropPipeParams object and all depending pipelines updated accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the robot examples contain changes as that shouldn't happen either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should not have changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should not have changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is autogenerated and is not supposed to be committed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After resetting it back to the version in master, you can run git update-index --skip-worktree photon-server/src/main/resources/web/index.html
to prevent git from ever seeing it as changed and adding it to a commit.
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" href="./favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Photon Client</title> | ||
<script type="module" crossorigin src="./assets/index-CIrfZRaJ.js"></script> | ||
<link rel="stylesheet" crossorigin href="./assets/index-Bt-HXv2B.css"> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accepting this suggestion will revert it to the version in master:
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<link rel="icon" href="./favicon.ico" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Photon Client</title> | |
<script type="module" crossorigin src="./assets/index-CIrfZRaJ.js"></script> | |
<link rel="stylesheet" crossorigin href="./assets/index-Bt-HXv2B.css"> | |
</head> | |
<body> | |
<div id="app"></div> | |
</body> | |
</html> | |
<p>UI has not been copied!</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the changes to files under photonlib-java-examples/aimandrange/
are replacing the existing "Aim and Range" example with an example for using cropping. The cropping example should be moved to it's own folder and these files should be reverted to be identical to master.
Added cropping mechanism, the client side was done by someone else and I just continued its work and finished the core mechanism, the dynamic cropping is working as well and can be transmitted from a NT table via setDynamicCropping method of a PhotonCamera object.
Some stuff still needs to be polished but overall I want to understand if there are certain stuff that needs to be changed before I continue.
thanks in advance looking forward to see it in production :D