Skip to content

Commit 4b1a17b

Browse files
authored
Merge pull request #4 from DavidNorthup/dev
Dev
2 parents 6ef118e + cb06ff9 commit 4b1a17b

11 files changed

+63
-23
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,17 @@ This file is meant to be run with an image captured from the webcam you are atte
2020

2121
## Mask Viewer
2222
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].
23+
24+
25+
# Installation Details:
26+
1.) The first step is to install opencv, I used [this page](https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html).
27+
28+
2.) Install SFML, I used my package manager to install using: apt-get install libsfml-dev.
29+
30+
3.) Clone this repository and the kociemba repository, and make the target within 'ckociemba'.
31+
32+
4.) Place the executable compiled in hte step prior into the application directory.
33+
34+
5.) Compile all of the executables within the application directory.
35+
36+
6.) Install the arduino software on the boards, with the sketch and libraries included.

application/Camera.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,27 @@ std::vector<int> CSRImageProcessing::highlightMat(cv::Mat& image, std::vector<cv
161161
return data;
162162
}
163163

164-
164+
/*
165+
This function saves the opencv Mat object into an image specified by the variable path
166+
*/
165167
void CSRImageProcessing::saveImageToFile(std::string path, cv::Mat& image) {
166168
cv::imwrite(path, image);
167169
std::cout << "Saved image to file." << std::endl;
168170
}
169171

172+
/*
173+
This helper function is used by the color reccomendation function. It is used to
174+
determine if the point P is geometrically within the circle given by center and radius.
175+
*/
170176
bool CSRImageProcessing::pointInCircle(cv::Point p, cv::Point center, int radius) {
171177
int dx = p.x - center.x, dy = p.y - center.y;
172178
return std::sqrt(dx*dx + dy*dy) <= radius;
173179
}
174180

181+
/*
182+
This function gives a recommendation for the cube facelet color by examining each of the color
183+
masks. We sample in a circle with center (x,y) with radius rad.
184+
*/
175185
int CSRImageProcessing::getReccomendation(int x, int y, int rad, cv::Mat masks[]) {
176186
int maxCount = 0, maxIndex = 0;
177187
for (int i = 0; i < 6; i++) {

application/Camera.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
#include <fstream>
77
#include <vector>
88

9-
#define RADIUS 7
9+
#define RADIUS 8
1010

1111
#define DATA_ORDER {"BLUE", "GREEN", "ORANGE", "RED", "WHITE", "YELLOW"}
1212
#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)}
1313
#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)}
1414

15-
#define BLUE_LOW cv::Scalar(100, 50, 20)
15+
#define BLUE_LOW cv::Scalar(95, 50, 20)
1616
#define BLUE_HIGH cv::Scalar(140, 250, 250)
1717

18-
#define GREEN_LOW cv::Scalar(40, 30, 0)
19-
#define GREEN_HIGH cv::Scalar(95, 255, 255)
18+
#define GREEN_LOW cv::Scalar(40, 30, 20)
19+
#define GREEN_HIGH cv::Scalar(85, 255, 255)
2020

2121
#define ORANGE_LOW cv::Scalar(15, 40, 40)
2222
#define ORANGE_HIGH cv::Scalar(23, 255, 255)
@@ -29,7 +29,7 @@
2929
#define RED_HIGH_2 cv::Scalar(255, 200, 200)
3030

3131
#define WHITE_LOW cv::Scalar(0, 0, 60)
32-
#define WHITE_HIGH cv::Scalar(255, 40, 255)
32+
#define WHITE_HIGH cv::Scalar(255, 30, 255)
3333

3434
#define YELLOW_LOW cv::Scalar(23, 40, 20)
3535
#define YELLOW_HIGH cv::Scalar(45, 255, 255)

application/Driver.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,20 @@ int main(int argc, char *argv[]) {
266266
if (event.key.code == sf::Keyboard::B) {
267267
robot.performMove("B");
268268
}
269+
270+
if (event.key.code == sf::Keyboard::V) {
271+
int counts[] = {0,0,0,0,0,0};
272+
for (int i = 0; i < 54; i++) {
273+
counts[data[i]]++;
274+
}
275+
276+
bool valid = true;
277+
for (int i = 0; i < 6 && valid; i++) {
278+
valid = counts[i] == 9;
279+
}
280+
281+
std::cout << "Valid: " << valid << std::endl;
282+
}
269283
} else if (alt_held) {
270284
if (event.key.code == sf::Keyboard::R) {
271285
robot.performMove("R'");

application/DriverSampling.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include <SFML/Graphics.hpp>
2-
#include "Camera.h"
32
#include <iostream>
43
#include <fstream>
54

5+
#include "Camera.h"
6+
7+
68
int main (int argc, char* argv[]) {
79
if (argc < 3) {
8-
std::cout << "Not enough args, example use: " << argv[0] << " [sample image file] [facelet name (ex: B9)]" << std::endl;
10+
std::cout << "Not enough args, example use: " << argv[0] << " [sample image file] [sampling center output file]" << std::endl;
911
return 1;
1012
}
1113
sf::Image image;

application/Makefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ OBJECTS=$(SOURCES:.cpp=.o)
66
EXECUTABLE=csr.exe
77

88

9-
all: $(EXECUTABLE)
9+
all: $(EXECUTABLE) sampling-config.exe training-mask.exe
1010

11-
$(EXECUTABLE): $(OBJECTS) *.h
11+
$(EXECUTABLE): $(OBJECTS)
1212
$(CC) $(OBJECTS) -o $@ $(LDFLAGS)
1313

14-
.cpp.o: $< *.h
15-
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
14+
.cpp.o: $<
15+
$(CC) $(CFLAGS) $< -c $(LDFLAGS)
1616

1717
clean:
1818
rm *.o *.exe
1919

20-
2120
sampling-config.exe: DriverSampling.cpp
2221
$(CC) DriverSampling.cpp -o sampling-config.exe $(LDFLAGS)
2322

24-
training-mask.exe: TrainingTestMask.cpp
23+
training-mask.exe: TrainingTestMask.cpp Camera.o
2524
$(CC) TrainingTestMask.cpp -o training-mask.exe $(LDFLAGS)

application/TrainingTestMask.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ int main (int argc, char* argv[]) {
7979
cv::inRange(hsv, ORANGE_LOW_2 , ORANGE_HIGH_2, orange_mask_2);
8080
cv::inRange(hsv, YELLOW_LOW , YELLOW_HIGH, yellow_mask);
8181
orange_mask = orange_mask | orange_mask_2;
82+
red_mask = red_mask | red_mask_2;
8283

8384
Mat masks[] = {blue_mask, green_mask, orange_mask, red_mask, white_mask, yellow_mask};
8485
Scalar colors[] = COLOR_ORDER;

application/options.opt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ Camera_brightness_frd 95
33
Camera_brightness_flu 100
44
Camera_brightness_bru 90
55
Camera_contrast_bld 25
6-
Camera_contrast_frd 25
6+
Camera_contrast_frd 30
77
Camera_contrast_flu 30
8-
Camera_contrast_bru 20
8+
Camera_contrast_bru 25
99
Camera_saturation_bld 30
1010
Camera_saturation_frd 30
1111
Camera_saturation_flu 30
12-
Camera_saturation_bru 20
12+
Camera_saturation_bru 30

application/training/sampling_locations_bld.dat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
142 55 L8
55
152 27 L9
66
40 127 B3
7-
81 127 B6
8-
128 129 B9
7+
76 122 B6
8+
128 139 B9
99
143 158 B8
1010
155 184 B7
1111
158 103 D7
1212
171 71 D4
1313
180 42 D1
1414
172 139 D8
15-
181 166 D9
15+
176 171 D9

application/training/sampling_locations_bru.dat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
141 199 U1
1+
141 202 U1
22
133 167 U2
33
122 129 U3
4-
134 101 U6
4+
133 105 U6
55
144 78 U9
66
92 149 B1
77
104 186 B2

0 commit comments

Comments
 (0)