// Path: src/main/java/com/tom_e_white/set_game/preprocess/CreateTrainingSetV2.java
// public class CreateTrainingSetV2 {
//     public static void main(String[] args) throws IOException {
//         if (!RAW_LABELLED_DIRECTORY.exists()) {
//             CardDetector cardDetector = new CardDetector(4, 66);
//             File outDir = RAW_LABELLED_DIRECTORY;
//             outDir.mkdirs();
//             for (File d : RAW_SORTED_DIRECTORY.listFiles((dir, name) -> name.matches("\\d"))) {
//                 int numberLabel = Integer.valueOf(d.getName());
//                 for (File file : d.listFiles((dir, name) -> name.matches(".*\\.jpg"))) {
//                     System.out.println(file);
//                     List<CardImage> images = cardDetector.detect(file.getAbsolutePath(), false, true, 3, 9);
//                     int i = 0;
//                     for (CardImage image : images) {
//                         Card card = new Card(numberLabel, (i % 9) / 3, i / 9, i % 3);
//                         File labelledDirectory = new File(outDir, card.getDescription().replace(" ", "-"));
//                         labelledDirectory.mkdirs();
//                         File newFile = new File(labelledDirectory, file.getName().replace(".jpg", "_" + numberLabel + "_" + i + ".jpg"));
//                         UtilImageIO.saveImage(image.getImage(), newFile.getAbsolutePath());
//                         i++;
//                     }
//                 }
//             }
//         }
// 
//         ViewLabelledImagesV2.view(RAW_LABELLED_DIRECTORY);
//     }
// 
// }
// 
// Path: src/main/java/com/tom_e_white/set_game/preprocess/TrainingDataV2.java
// public interface TrainingDataV2 {
//     File RAW_NEW_DIRECTORY = new File("data/train-v2/raw-new");
//     File RAW_SORTED_DIRECTORY = new File("data/train-v2/raw-sorted");
//     File RAW_LABELLED_DIRECTORY = new File("data/train-v2/raw-labelled");
//     File LABELLED_DIRECTORY = new File("data/train-v2/labelled");
// }


import boofcv.io.image.UtilImageIO;
import com.tom_e_white.set_game.preprocess.CreateTrainingSetV2;
import com.tom_e_white.set_game.preprocess.TrainingDataV2;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
package com.tom_e_white.set_game.train;



/**
 * Take the images created by {@link CreateTrainingSetV2} and extract useful features from them.
 * The resulting data can be used to train a model for predicting the shapes on a card.
 */
public class CreateTrainingDataV2 {
    public static void main(String[] args) throws IOException {
        FeatureFinder[] finders = new FeatureFinder[] {
                new FindCardColourFeatures(2),
//                new FindCardShadingFeatures(),
//                new FindCardShapeFeatures()
        };
        for (FeatureFinder finder : finders) {
            List<String> summaries = new ArrayList<>();
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CreateTrainingSetV2.java
// public class CreateTrainingSetV2 {
//     public static void main(String[] args) throws IOException {
//         if (!RAW_LABELLED_DIRECTORY.exists()) {
//             CardDetector cardDetector = new CardDetector(4, 66);
//             File outDir = RAW_LABELLED_DIRECTORY;
//             outDir.mkdirs();
//             for (File d : RAW_SORTED_DIRECTORY.listFiles((dir, name) -> name.matches("\\d"))) {
//                 int numberLabel = Integer.valueOf(d.getName());
//                 for (File file : d.listFiles((dir, name) -> name.matches(".*\\.jpg"))) {
//                     System.out.println(file);
//                     List<CardImage> images = cardDetector.detect(file.getAbsolutePath(), false, true, 3, 9);
//                     int i = 0;
//                     for (CardImage image : images) {
//                         Card card = new Card(numberLabel, (i % 9) / 3, i / 9, i % 3);
//                         File labelledDirectory = new File(outDir, card.getDescription().replace(" ", "-"));
//                         labelledDirectory.mkdirs();
//                         File newFile = new File(labelledDirectory, file.getName().replace(".jpg", "_" + numberLabel + "_" + i + ".jpg"));
//                         UtilImageIO.saveImage(image.getImage(), newFile.getAbsolutePath());
//                         i++;
//                     }
//                 }
//             }
//         }
// 
//         ViewLabelledImagesV2.view(RAW_LABELLED_DIRECTORY);
//     }
// 
// }
// 
// Path: src/main/java/com/tom_e_white/set_game/preprocess/TrainingDataV2.java
// public interface TrainingDataV2 {
//     File RAW_NEW_DIRECTORY = new File("data/train-v2/raw-new");
//     File RAW_SORTED_DIRECTORY = new File("data/train-v2/raw-sorted");
//     File RAW_LABELLED_DIRECTORY = new File("data/train-v2/raw-labelled");
//     File LABELLED_DIRECTORY = new File("data/train-v2/labelled");
// }


// Path: src/main/java/com/tom_e_white/set_game/train/CreateTrainingDataV2.java
import boofcv.io.image.UtilImageIO;
import com.tom_e_white.set_game.preprocess.CreateTrainingSetV2;
import com.tom_e_white.set_game.preprocess.TrainingDataV2;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

package com.tom_e_white.set_game.train;



/**
 * Take the images created by {@link CreateTrainingSetV2} and extract useful features from them.
 * The resulting data can be used to train a model for predicting the shapes on a card.
 */
public class CreateTrainingDataV2 {
    public static void main(String[] args) throws IOException {
        FeatureFinder[] finders = new FeatureFinder[] {
                new FindCardColourFeatures(2),
//                new FindCardShadingFeatures(),
//                new FindCardShapeFeatures()
        };
        for (FeatureFinder finder : finders) {
            List<String> summaries = new ArrayList<>();
            for (File d : TrainingDataV2.LABELLED_DIRECTORY.listFiles((dir, name) -> !name.matches("\\..*"))) {