From 14f0e278a1b302b1471e2c9a9a271a85184e42d4 Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Fri, 10 Feb 2023 14:39:27 -0500 Subject: [PATCH] Finish crop mods, fix config Was accidentally saving all values twice, instead of just once. That's been resolved. --- README.md | 13 ++++-- src/main/java/org/baxter/disco/ocr/Cli.java | 2 +- .../org/baxter/disco/ocr/ConfigFacade.java | 4 +- .../baxter/disco/ocr/ConfigProperties.java | 4 +- .../org/baxter/disco/ocr/OpenCVFacade.java | 40 ------------------- 5 files changed, 14 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index fc3aa0b..8fa8c49 100644 --- a/README.md +++ b/README.md @@ -52,15 +52,20 @@ sudo systemctl disable pigpiod The first command stops all currently running `pigpio` daemon processes. The second command disables the daemon, so that it will not start again if you reboot. 2. You will need to create a new `udev` rule. This creates a symlink for a given camera, plugged into a specific USB port, and allows the Java code to consistently communicate with the camera. An example `udev` rule is given in this repo (`83-webcam.rules`), but will need to be modified to your specific device. - 1. Copy the example `udev` rule file to your Raspberry Pi, and put it in `/etc/udev/rules.d/` (if this directory does not exist, create it). It is recommended to do this in the terminal, by running the following commands: + 1. Copy the example `udev` rule file to your Raspberry Pi, and put it in `/etc/udev/rules.d/` (if this directory does not exist, create it). This is done by running the followwing command in the terminal. ```bash sudo cp /media/pi/[flash drive]/83-webcam.rules /etc/udev/rules.d/ ``` - This is a soft-requirement, as interacting with files in this location requires administrative privileges. + Replace the `[flash drive]` portion of the above line with the name of your flash drive. + Alternatively, you can go to your flash drive in the File Manager, and press the `F4` key to open a terminal in that location. Then, enter the following command: - 2. Open the copied file in the text editor of your choice, and open a terminal window as well. It is recommended to do this by running the following command in a terminal: + ```bash + sudo cp 83-webcam.rules /etc/udev/rules.d/ + ``` + + 2. Open the copied file in the text editor of your choice, and open a terminal window as well. This is done easiest by running the following command in a terminal: ```bash sudo -e /etc/udev/rules.d/83-webcam.rules @@ -68,7 +73,7 @@ The first command stops all currently running `pigpio` daemon processes. The sec This will open a terminal-based text editor, crucially, *as an admin*, which will allow you to save the file. - 3. Run the following command in your terminal window. + 3. Run the following command in a second terminal window. ```bash sudo udevadm monitor -p | grep ID_PATH= diff --git a/src/main/java/org/baxter/disco/ocr/Cli.java b/src/main/java/org/baxter/disco/ocr/Cli.java index 5b387c5..6b13da1 100644 --- a/src/main/java/org/baxter/disco/ocr/Cli.java +++ b/src/main/java/org/baxter/disco/ocr/Cli.java @@ -697,7 +697,7 @@ public class Cli for(int i = 0; i < localIterations; i++) { println(""); - println("===================================="); + ErrorLogging.logError("===================================="); ErrorLogging.logError("Starting iteration " + (i+1) + " of " + localIterations + "..."); while(!LOCK.tryLock()) {} fixture.iterationMovement(prime); diff --git a/src/main/java/org/baxter/disco/ocr/ConfigFacade.java b/src/main/java/org/baxter/disco/ocr/ConfigFacade.java index 88cc815..939fdd4 100644 --- a/src/main/java/org/baxter/disco/ocr/ConfigFacade.java +++ b/src/main/java/org/baxter/disco/ocr/ConfigFacade.java @@ -335,8 +335,8 @@ public class ConfigFacade { for(ConfigProperties property : ConfigProperties.values()) { - String propertyName = camera + "." + property.toString(); - String propertyValue =configMap.get(camera).get(property).toString(); + String propertyName = camera + "." + property.getConfig(); + String propertyValue = configMap.get(camera).get(property).toString(); CONFIG_STORE.setProperty(propertyName,propertyValue); } } diff --git a/src/main/java/org/baxter/disco/ocr/ConfigProperties.java b/src/main/java/org/baxter/disco/ocr/ConfigProperties.java index a92f0c0..8d8c282 100644 --- a/src/main/java/org/baxter/disco/ocr/ConfigProperties.java +++ b/src/main/java/org/baxter/disco/ocr/ConfigProperties.java @@ -69,9 +69,9 @@ public enum ConfigProperties private ConfigProperties(String print, String config, double defaultValue) { this.print = print; this.config = config; this.defaultValue = defaultValue; } /** - * Getter for the config-readable name of the value. + * Getter for the default value for this config property * - * @return String of the name of the value. + * @return double of the default value */ public double getDefaultValue() { return defaultValue; } diff --git a/src/main/java/org/baxter/disco/ocr/OpenCVFacade.java b/src/main/java/org/baxter/disco/ocr/OpenCVFacade.java index 69be583..1d6bb88 100644 --- a/src/main/java/org/baxter/disco/ocr/OpenCVFacade.java +++ b/src/main/java/org/baxter/disco/ocr/OpenCVFacade.java @@ -280,46 +280,6 @@ public class OpenCVFacade return output; } - /** - * Crop the given image to the dimensions in the configuration; - * deprecated in favour of {@link #crop(Mat, Rect)} - * - * @deprecated - * @param image Frame taken from the camera. - * @param cameraName Name of the camera taking the picture - * - * @return Frame of the cropped image - */ - private static Mat cropImage(Mat image, String cameraName) - { - Mat output = null; - int x = (int)ConfigFacade.getValue(cameraName,ConfigProperties.CROP_X); - int y = (int)ConfigFacade.getValue(cameraName,ConfigProperties.CROP_Y); - int width = (int)ConfigFacade.getValue(cameraName,ConfigProperties.CROP_W); - int height = (int)ConfigFacade.getValue(cameraName,ConfigProperties.CROP_H); - //ErrorLogging.logError("DEBUG: Crop dimensions:"); - //ErrorLogging.logError("DEBUG: X = " + x); - //ErrorLogging.logError("DEBUG: Y = " + y); - //ErrorLogging.logError("DEBUG: Width = " + width); - //ErrorLogging.logError("DEBUG: Height = " + height); - //ErrorLogging.logError("DEBUG: Original image size: "); - //ErrorLogging.logError("DEBUG: Width: " + image.cols()); - //ErrorLogging.logError("DEBUG: Height: " + image.rows()); - - IplImage temp = MAT_CONVERTER.convertToIplImage(MAT_CONVERTER.convert(image)); - CvRect crop = new CvRect(); - crop.x(x); crop.y(y); crop.width(width); crop.height(height); - cvSetImageROI(temp,crop); - IplImage croppedImage = cvCreateImage(cvGetSize(temp), temp.depth(),temp.nChannels()); - cvCopy(temp,croppedImage); - output = MAT_CONVERTER.convert(MAT_CONVERTER.convert(croppedImage)); - //Old code; Throws runtime exception - Failed assertion that all inputs are safe. Not entirely sure why though. - //var cropRectangle = new Rect(x,y,width,height); - //output = image.apply(cropRectangle); - ////output = new Mat(image,cropRectangle); - return output; - } - /** * Put the given image through a binary threshold. * This reduces the image from greyscale to only pure white and black pixels. -- 2.47.2