diff --git a/README.md b/README.md index 7bdf47e..e153412 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,17 @@ This file is meant to be run with an image captured from the webcam you are atte ## Mask Viewer The current implementation of the software uses opencv to select ranges of pixels defined by HSV value bounds in "Camera.h" for each of the colors on the cube. Opencv iterates through the image once for each color and generates a binary matrix of pixels with value 0 everywhere any given pixel is outside of the bounds for the speicifed color. Then it uses the sampling centers to count the number of pixels in range inside each circle defined by the center and a radius that match each color. The software then counts the number of matches for each color and whichever is highest is determined as the color for that point. This utility allows you to see the masks for a given sample image, and then reveals what it would conclude given the current bounds. Example usage is: ./training-mask.exe [image_file] [sampling locations]. + + +# Installation Details: +1.) The first step is to install opencv, I used [this page](https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html). + +2.) Install SFML, I used my package manager to install using: apt-get install libsfml-dev. + +3.) Clone this repository and the kociemba repository, and make the target within 'ckociemba'. + +4.) Place the executable compiled in hte step prior into the application directory. + +5.) Compile all of the executables within the application directory. + +6.) Install the arduino software on the boards, with the sketch and libraries included. diff --git a/application/Camera.cpp b/application/Camera.cpp index 749b258..0f80d83 100644 --- a/application/Camera.cpp +++ b/application/Camera.cpp @@ -161,17 +161,27 @@ std::vector CSRImageProcessing::highlightMat(cv::Mat& image, std::vector #include -#define RADIUS 7 +#define RADIUS 8 #define DATA_ORDER {"BLUE", "GREEN", "ORANGE", "RED", "WHITE", "YELLOW"} #define COLOR_ORDER {cv::Scalar(255,0,0), cv::Scalar(26,112,0), cv::Scalar(0, 130, 255), cv::Scalar(0,0,255), cv::Scalar(255,255,255), cv::Scalar(0,255,255)} #define SFML_COLOR_ORDER {sf::Color(0, 0, 255), sf::Color(0, 112,26), sf::Color(255, 130,0), sf::Color(255, 0, 0), sf::Color(255,255,255), sf::Color(255,255,0)} -#define BLUE_LOW cv::Scalar(100, 50, 20) +#define BLUE_LOW cv::Scalar(95, 50, 20) #define BLUE_HIGH cv::Scalar(140, 250, 250) -#define GREEN_LOW cv::Scalar(40, 30, 0) -#define GREEN_HIGH cv::Scalar(95, 255, 255) +#define GREEN_LOW cv::Scalar(40, 30, 20) +#define GREEN_HIGH cv::Scalar(85, 255, 255) #define ORANGE_LOW cv::Scalar(15, 40, 40) #define ORANGE_HIGH cv::Scalar(23, 255, 255) @@ -29,7 +29,7 @@ #define RED_HIGH_2 cv::Scalar(255, 200, 200) #define WHITE_LOW cv::Scalar(0, 0, 60) -#define WHITE_HIGH cv::Scalar(255, 40, 255) +#define WHITE_HIGH cv::Scalar(255, 30, 255) #define YELLOW_LOW cv::Scalar(23, 40, 20) #define YELLOW_HIGH cv::Scalar(45, 255, 255) diff --git a/application/Driver.cpp b/application/Driver.cpp index 747194a..d1744ab 100644 --- a/application/Driver.cpp +++ b/application/Driver.cpp @@ -266,6 +266,20 @@ int main(int argc, char *argv[]) { if (event.key.code == sf::Keyboard::B) { robot.performMove("B"); } + + if (event.key.code == sf::Keyboard::V) { + int counts[] = {0,0,0,0,0,0}; + for (int i = 0; i < 54; i++) { + counts[data[i]]++; + } + + bool valid = true; + for (int i = 0; i < 6 && valid; i++) { + valid = counts[i] == 9; + } + + std::cout << "Valid: " << valid << std::endl; + } } else if (alt_held) { if (event.key.code == sf::Keyboard::R) { robot.performMove("R'"); diff --git a/application/DriverSampling.cpp b/application/DriverSampling.cpp index 75a7a62..a334812 100644 --- a/application/DriverSampling.cpp +++ b/application/DriverSampling.cpp @@ -1,11 +1,13 @@ #include -#include "Camera.h" #include #include +#include "Camera.h" + + int main (int argc, char* argv[]) { if (argc < 3) { - std::cout << "Not enough args, example use: " << argv[0] << " [sample image file] [facelet name (ex: B9)]" << std::endl; + std::cout << "Not enough args, example use: " << argv[0] << " [sample image file] [sampling center output file]" << std::endl; return 1; } sf::Image image; diff --git a/application/Makefile b/application/Makefile index 9879bce..cda65f6 100644 --- a/application/Makefile +++ b/application/Makefile @@ -6,20 +6,19 @@ OBJECTS=$(SOURCES:.cpp=.o) EXECUTABLE=csr.exe -all: $(EXECUTABLE) +all: $(EXECUTABLE) sampling-config.exe training-mask.exe -$(EXECUTABLE): $(OBJECTS) *.h +$(EXECUTABLE): $(OBJECTS) $(CC) $(OBJECTS) -o $@ $(LDFLAGS) -.cpp.o: $< *.h - $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) +.cpp.o: $< + $(CC) $(CFLAGS) $< -c $(LDFLAGS) clean: rm *.o *.exe - sampling-config.exe: DriverSampling.cpp $(CC) DriverSampling.cpp -o sampling-config.exe $(LDFLAGS) -training-mask.exe: TrainingTestMask.cpp +training-mask.exe: TrainingTestMask.cpp Camera.o $(CC) TrainingTestMask.cpp -o training-mask.exe $(LDFLAGS) diff --git a/application/TrainingTestMask.cpp b/application/TrainingTestMask.cpp index 11cfcff..347b2bf 100644 --- a/application/TrainingTestMask.cpp +++ b/application/TrainingTestMask.cpp @@ -79,6 +79,7 @@ int main (int argc, char* argv[]) { cv::inRange(hsv, ORANGE_LOW_2 , ORANGE_HIGH_2, orange_mask_2); cv::inRange(hsv, YELLOW_LOW , YELLOW_HIGH, yellow_mask); orange_mask = orange_mask | orange_mask_2; + red_mask = red_mask | red_mask_2; Mat masks[] = {blue_mask, green_mask, orange_mask, red_mask, white_mask, yellow_mask}; Scalar colors[] = COLOR_ORDER; diff --git a/application/options.opt b/application/options.opt index f33557e..da3fd9f 100644 --- a/application/options.opt +++ b/application/options.opt @@ -3,10 +3,10 @@ Camera_brightness_frd 95 Camera_brightness_flu 100 Camera_brightness_bru 90 Camera_contrast_bld 25 -Camera_contrast_frd 25 +Camera_contrast_frd 30 Camera_contrast_flu 30 -Camera_contrast_bru 20 +Camera_contrast_bru 25 Camera_saturation_bld 30 Camera_saturation_frd 30 Camera_saturation_flu 30 -Camera_saturation_bru 20 +Camera_saturation_bru 30 diff --git a/application/training/sampling_locations_bld.dat b/application/training/sampling_locations_bld.dat index 8b7d0dc..53a0abe 100644 --- a/application/training/sampling_locations_bld.dat +++ b/application/training/sampling_locations_bld.dat @@ -4,12 +4,12 @@ 142 55 L8 152 27 L9 40 127 B3 -81 127 B6 -128 129 B9 +76 122 B6 +128 139 B9 143 158 B8 155 184 B7 158 103 D7 171 71 D4 180 42 D1 172 139 D8 -181 166 D9 +176 171 D9 diff --git a/application/training/sampling_locations_bru.dat b/application/training/sampling_locations_bru.dat index 0ef7eac..1b7a35b 100644 --- a/application/training/sampling_locations_bru.dat +++ b/application/training/sampling_locations_bru.dat @@ -1,7 +1,7 @@ -141 199 U1 +141 202 U1 133 167 U2 122 129 U3 -134 101 U6 +133 105 U6 144 78 U9 92 149 B1 104 186 B2 diff --git a/application/training/sampling_locations_frd.dat b/application/training/sampling_locations_frd.dat index 64c9ec5..edf182b 100644 --- a/application/training/sampling_locations_frd.dat +++ b/application/training/sampling_locations_frd.dat @@ -11,5 +11,5 @@ 161 185 D1 154 158 D2 144 124 D3 -155 91 D6 +155 98 D6 165 63 D9