diff --git a/AScannerDarkly/.gitignore b/AScannerDarkly/.gitignore deleted file mode 100644 index 1de5f55..0000000 --- a/AScannerDarkly/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -cmake_install.cmake -CMakeCache.txt -CMakeFiles/* -Makefile -AScannerDarkly diff --git a/AScannerDarkly/CMakeLists.txt b/AScannerDarkly/CMakeLists.txt deleted file mode 100644 index 34ecf8d..0000000 --- a/AScannerDarkly/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.2) -project( AScannerDarkly ) -find_package( OpenCV REQUIRED ) -include_directories( ${OpenCV_INCLUDE_DIRS} ) -add_executable( AScannerDarkly main.cpp ) -target_link_libraries( AScannerDarkly ${OpenCV_LIBS} ) -target_link_libraries( AScannerDarkly -llept -ltesseract ) diff --git a/AScannerDarkly/TestImages/--psm.txt b/AScannerDarkly/TestImages/--psm.txt deleted file mode 100644 index e69de29..0000000 diff --git a/AScannerDarkly/TestImages/collector_number_0006.jpg b/AScannerDarkly/TestImages/collector_number_0006.jpg deleted file mode 100644 index 2fdc9d3..0000000 Binary files a/AScannerDarkly/TestImages/collector_number_0006.jpg and /dev/null differ diff --git a/AScannerDarkly/TestImages/emrakul_the_world_anew.jpg b/AScannerDarkly/TestImages/emrakul_the_world_anew.jpg deleted file mode 100644 index c1f9c12..0000000 Binary files a/AScannerDarkly/TestImages/emrakul_the_world_anew.jpg and /dev/null differ diff --git a/AScannerDarkly/TestImages/emrakul_the_world_anew_97.jpg b/AScannerDarkly/TestImages/emrakul_the_world_anew_97.jpg deleted file mode 100644 index 2141e73..0000000 Binary files a/AScannerDarkly/TestImages/emrakul_the_world_anew_97.jpg and /dev/null differ diff --git a/AScannerDarkly/TestImages/emrakul_the_world_anew_foil.jpg b/AScannerDarkly/TestImages/emrakul_the_world_anew_foil.jpg deleted file mode 100644 index 0cf8403..0000000 Binary files a/AScannerDarkly/TestImages/emrakul_the_world_anew_foil.jpg and /dev/null differ diff --git a/AScannerDarkly/TestImages/emrakul_the_world_anew_title_97.jpg b/AScannerDarkly/TestImages/emrakul_the_world_anew_title_97.jpg deleted file mode 100644 index 181f1ca..0000000 Binary files a/AScannerDarkly/TestImages/emrakul_the_world_anew_title_97.jpg and /dev/null differ diff --git a/AScannerDarkly/TestImages/emrakul_the_world_anew_title_black.jpg b/AScannerDarkly/TestImages/emrakul_the_world_anew_title_black.jpg deleted file mode 100644 index c93678a..0000000 Binary files a/AScannerDarkly/TestImages/emrakul_the_world_anew_title_black.jpg and /dev/null differ diff --git a/AScannerDarkly/TestImages/emrakul_the_world_anew_title_white.jpg b/AScannerDarkly/TestImages/emrakul_the_world_anew_title_white.jpg deleted file mode 100644 index aa7ddf1..0000000 Binary files a/AScannerDarkly/TestImages/emrakul_the_world_anew_title_white.jpg and /dev/null differ diff --git a/AScannerDarkly/TestImages/indicator_foil.jpg b/AScannerDarkly/TestImages/indicator_foil.jpg deleted file mode 100644 index 1ce0ffc..0000000 Binary files a/AScannerDarkly/TestImages/indicator_foil.jpg and /dev/null differ diff --git a/AScannerDarkly/TestImages/indicator_nonfoil.jpg b/AScannerDarkly/TestImages/indicator_nonfoil.jpg deleted file mode 100644 index 9394b11..0000000 Binary files a/AScannerDarkly/TestImages/indicator_nonfoil.jpg and /dev/null differ diff --git a/AScannerDarkly/TestImages/language_code_en.jpg b/AScannerDarkly/TestImages/language_code_en.jpg deleted file mode 100644 index 2e72093..0000000 Binary files a/AScannerDarkly/TestImages/language_code_en.jpg and /dev/null differ diff --git a/AScannerDarkly/TestImages/set_code_mh3.jpg b/AScannerDarkly/TestImages/set_code_mh3.jpg deleted file mode 100644 index c5ff37f..0000000 Binary files a/AScannerDarkly/TestImages/set_code_mh3.jpg and /dev/null differ diff --git a/AScannerDarkly/main.cpp b/AScannerDarkly/main.cpp deleted file mode 100644 index c4af211..0000000 --- a/AScannerDarkly/main.cpp +++ /dev/null @@ -1,161 +0,0 @@ -#include -#include -#include -#include - -const std::string SCANNER_WINDOW_NAME = "A Scanner Darkly"; -const std::string CARD_WINDOW_NAME = "Detected Card"; - -const std::string CANNY_LOWER_THRESHOLD_TRACKBAR_NAME = "Canny: Lower Threshold"; - -const float CARD_ASPECT_RATIO = 88.0f / 63.0f; -const std::string ASPECT_RATIO_TOLERANCE_TRACKBAR_NAME = "Aspect Ratio Tolerance"; -int g_aspect_ratio_tolerance = 1; -const int MAX_ASPECT_RATIO_TOLERANCE = 100; - -int g_Canny_lower_threshold = 195; -const int CANNY_UPPER_THRESHOLD = 255; - -cv::Mat cropImageToRoi(cv::Mat img, cv::Rect roi) { - return img(roi); -} - -cv::Mat detectCardInFrame(cv::Mat frame) { - cv::Mat grayscaleFrame, blurFrame, cannyFrame, cardFrame; - - // Perform edge detection - cv::cvtColor(frame, grayscaleFrame, cv::COLOR_BGR2GRAY); - cv::GaussianBlur(grayscaleFrame, blurFrame, cv::Size(5, 5), 2, 2); - cv::Canny(blurFrame, cannyFrame, g_Canny_lower_threshold, CANNY_UPPER_THRESHOLD); - - // Perform contour detection - std::vector> contours; - std::vector hierarchy; - cv::findContours(cannyFrame, contours, hierarchy, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE); - - // Detect convex hulls - std::vector> hull(contours.size()); - for(size_t i = 0; i < contours.size(); i++) { - cv::convexHull(contours[i], hull[i]); - } - - // Detect RotatedRects - std::vector minRect(contours.size()); - for(size_t i = 0; i < contours.size(); i++) { - minRect[i] = cv::minAreaRect(contours[i]); - } - - // Draw lines around RotatedRects - /* - cv::Scalar rectangleColor(255, 0, 0, 0); - cv::Point2f rect_points[4]; - minRect[i].points(rect_points); - for (int j = 0; j < 4; j++) { - cv::line(frame, rect_points[j], rect_points[(j + 1) % 4], rectangleColor); - } - */ - - // Find possible cards - std::vector possibleCards(contours.size()); - int possibleCount = 0; - for (size_t i = 0; i < minRect.size(); i++) { - float aspectRatio = minRect[i].size.height / minRect[i].size.width; - float aspectRatioTolerance = g_aspect_ratio_tolerance / 100.0f; - if (aspectRatio < (CARD_ASPECT_RATIO - aspectRatioTolerance) || aspectRatio > (CARD_ASPECT_RATIO + aspectRatioTolerance)) { - continue; - } - - cv::putText(frame, std::to_string(minRect[i].angle), minRect[i].center, cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(255, 0, 0, 0)); - - possibleCards[possibleCount] = minRect[i]; - possibleCount++; - } - - if (possibleCount == 1) { - return cropImageToRoi(frame, possibleCards[0].boundingRect()); - } else if (possibleCount > 1) { - // If we have more than one possible match, take the largest one - int largestCardIndex = 0; - int largestCardSize = 0; - - for (size_t i = 0; i < possibleCards.size(); i++) { - float size = possibleCards[i].size.width * possibleCards[i].size.height; - if (size >= largestCardSize) { - largestCardIndex = i; - largestCardSize = size; - } - } - - // Some basic error checking to ensure the RotatedRect is roughly card-sized - if (largestCardSize >= 14400 && largestCardSize <= 200000) { - return cropImageToRoi(frame, possibleCards[largestCardIndex].boundingRect()); - } - } - - return cv::Mat(); -} - -const char* readTextFromImage(cv::InputArray img) { - const char* tempFilename = "temp.bmp"; - - // Initialize Tesseract api - tesseract::TessBaseAPI* tess = new tesseract::TessBaseAPI(); - tess->Init(NULL, "eng"); - tess->SetPageSegMode(tesseract::PSM_SPARSE_TEXT); - - // Load image into Tesseract - cv::imwrite(tempFilename, img); - Pix* pixd = pixRead(tempFilename); - tess->SetImage(pixd); - tess->Recognize(0); - - // Perform OCR - const char* out = tess->GetUTF8Text(); - - // Cleanup - pixDestroy(&pixd); - std::remove(tempFilename); - - return out; -} - -int main(int argc, char** argv ) { - cv::VideoCapture cap; - cap.open(0); - - if (!cap.isOpened()) { - std::cerr << "Couldn't open capture" << std::endl; - return -1; - } - - cv::namedWindow(SCANNER_WINDOW_NAME); - - cv::createTrackbar(CANNY_LOWER_THRESHOLD_TRACKBAR_NAME, SCANNER_WINDOW_NAME, &g_Canny_lower_threshold, CANNY_UPPER_THRESHOLD, NULL); - cv::createTrackbar(ASPECT_RATIO_TOLERANCE_TRACKBAR_NAME, SCANNER_WINDOW_NAME, &g_aspect_ratio_tolerance, MAX_ASPECT_RATIO_TOLERANCE, NULL); - - cv::Mat frame, cardFrame; - while (true) { - cap >> frame; - //cardFrame = detectCardInFrame(frame); - cv::imshow(SCANNER_WINDOW_NAME, frame); - - /* - if (cardFrame.size().width > 0) { - printf("Card detected\n"); - while (true) { - cv::imshow(CARD_WINDOW_NAME, cardFrame); - char c = (char)cv::waitKey(33); - if (c == 27) { - cv::destroyWindow(CARD_WINDOW_NAME); - break; - } - } - } - */ - - char c = (char)cv::waitKey(33); - if (c == 27) { - break; - } - } -} diff --git a/AScannerDarkly/temp.bmp b/AScannerDarkly/temp.bmp deleted file mode 100644 index b354853..0000000 Binary files a/AScannerDarkly/temp.bmp and /dev/null differ diff --git a/a_scanner_dorkly/main.py b/a_scanner_dorkly/main.py deleted file mode 100755 index f0d9da6..0000000 --- a/a_scanner_dorkly/main.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/python3 - -import cv2 -import numpy as np - -mouse_raw = (0, 0) - -def clickEvent(event, x, y, flags, params): - global mouse_raw - - if event == cv2.EVENT_LBUTTONDOWN: - mouse_raw = (x, y) - print(mouse_raw) - -cap = cv2.VideoCapture(0) -cv2.namedWindow("image") -cv2.setMouseCallback("image", clickEvent) - -while True: - success, img = cap.read() - cv2.imshow("image", img) - cv2.waitKey(0) - -cv2.destroyAllWindows()