Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Applying the model to a project #16

Merged
merged 13 commits into from
Sep 13, 2022

Conversation

Juhwa-Lee1023
Copy link
Owner

@Juhwa-Lee1023 Juhwa-Lee1023 commented Sep 13, 2022

@LeeSungNo-ian
@jeong-hyeonHwang
@commitcomplete

Outline

Work Contents

  • 숫자 인식 시키기
  • 인식 시킨 숫자를 스도쿠 풀이 알고리즘에 넣기
  • 풀이한 숫자들을 스도쿠에 그리기

Trouble Point

1. The recognition rate of the model was 95%, but when I actually used it, it didn't even come out as 80%.(모델의 인식률은 95%였는데 실제로 사용해보니 80%로도 안나온다.)

  • �Trouble Situation

    • When obtaining coordinates, Sudoku is cut and obtained, and the border of the table is sometimes recognized as a number in the cut picture.(좌표를 구할 때 스도쿠를 잘라서 구하는데, 그 자른 사진에 표의 테두리가 숫자로 인식될 때가 있다.)
  • Trouble Shooting

    • Cut and import the edges of the cut picture again.(자른 사진의 테두리를 다시 자르고 가져온다.)
    int gx = (int)(mat.size().width * 0.1);
    int gy = (int)(mat.size().height * 0.1);
    int gw = (int)(mat.size().width * 0.7);
    int gh = (int)(mat.size().height * 0.8);
    //이미지 자르기
    cv::rectangle(contourMat, cv::Point(gx, gy), cv::Point(gx+gw, gy+gh), CV_RGB(0, 255, 0), 2);

2. Although the recognition rate has been raised to around 85%, it is still far less than the recognition rate of the original model, 95%.(인식률을 85%정도로 올렸지만, 아직 원래 모델의 인식률인 95%보다 훨씬 부족하다.)

  • �Trouble Situation

    • Even if the image is cut and imported, the border of the table is often recognized.(이미지를 잘라서 가져와도 표의 테두리가 인식되는 경우가 잦다.)
  • Trouble Shooting

    • The image is preprocessed to bring only the largest contour, just as it was when the Sudoku region was first searched.(해당 이미지를 처음 스도쿠 영역을 찾을때 처럼 전처리를 거쳐 가장 큰 윤곽만 가져온다.)
// UIImage를 cv::Mat로 변환
    cv::Mat mat;
    UIImageToMat(image, mat);
    
    // grayScale을 입힌다.
    cv::Mat toGray;
    cv::cvtColor(mat, toGray, CV_BGR2GRAY);
    
    // threshold를 강조한다.
    cv::Mat toThresh;
    cv::adaptiveThreshold(toGray, toThresh, 255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY_INV, 11, 41);
    
    // 테두리를 찾는다.
    std::vector<std::vector<cv::Point>> contours;
    std::vector<cv::Vec4i> hierarchy;
    cv::findContours(toThresh, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);

    int maxArea = 0;
    int maxContourIndex = -1;
    cv::Rect bRect;
    for (int i = 0; i < contours.size(); i++)
    {
        double area = cv::contourArea(contours[i]);
        if (area > 10)
        {
            cv::Rect r = cv::boundingRect(contours[i]);
            int ox = MAX(gx, r.x);
            int oy = MAX(gy, r.y);
            int ox2 = MIN(gx+gw, r.x+r.width);
            int oy2 = MIN(gy+gh, r.y+r.height);
            int ow = ox2 - ox;
            int oh = oy2 - oy;
            int oarea = ow * oh;
            if (oarea == r.area())
            {
                // 포함되는 것 중 제일 큰 것만 남긴다
                if (area > maxArea)
                {
                    maxArea = area;
                    maxContourIndex = i;
                    bRect = r;
                }
            }
        }
    }

3. The recognition rate of models made of creatml is low.(creatml로 만든 모델의 인식률이 낮다.)

  • �Trouble Situation

    • The recognition rate is about 95%, and in the case of Sudoku, there are many cases where the recognition is wrong due to the large number. (인식률이 약 95%정도인데, 스도쿠의 경우 숫자가 많아서 인식을 잘못하는 경우가 많다.)
  • Trouble Shooting

    • A lightweight number recognition dl model was created using TensorFlow.(TensorFlow를 이용하여 경량화된 숫자인식 dl모델을 만들어 넣었다.)
    • The recognition rate was 99%, and the error rate was very low(인식률은 99%로 오류발생률이 매우 낮아졌다)

sudoku

@Juhwa-Lee1023 Juhwa-Lee1023 linked an issue Sep 13, 2022 that may be closed by this pull request
3 tasks
Copy link

@jeong-hyeonHwang jeong-hyeonHwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

카메라 홀릭~!~~ 오늘도 파이팅! 👍👍👍

Sudoku/photoSudokuViewController.swift Outdated Show resolved Hide resolved
Sudoku/photoSudokuViewController.swift Outdated Show resolved Hide resolved
Sudoku/photoSudokuViewController.swift Outdated Show resolved Hide resolved

let num = String(0)
var c: UIColor = UIColor(red: 210/255, green: 31/255, blue: 0/255, alpha: 100)
var fsz: CGFloat = 28

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

축약어를 프로퍼티 이름으로 쓰는 경우 옆에 어떤 단어의 축약어인지 comment를 남기면 좋을 것 같아요!

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        let cutViewWidth = refinedView.bounds.size.width / 9
        let cutViewHeight = refinedView.bounds.size.height / 9
        let cutViewWidthInt = Int(cutViewWidth)
        let cutViewHeightInt = Int(cutViewHeight)
        for row in 0..<9 {
            let yCoordinate = Int(CGFloat(row) * cutViewHeight)
            for col in 0..<9 {
                let xCoordinate = Int(CGFloat(col) * cutViewWidth)
                var fontColor: UIColor = UIColor(red: 210/255, green: 31/255, blue: 0/255, alpha: 100)
                let fontSize: CGFloat = 28

a48a9c6

급하게 코드를 짜다보니 이름을 너무 성의없이 지었던것 같습니다.. 바로 수정하였습니다!

Copy link

@commitcomplete commitcomplete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openCV를 활용한 이미지 전처리가 인상적이네요! 조금만더 명확한 변수명을 사용하면 더 이해하기 쉬울것 같아요!

Sudoku/photoSudokuViewController.swift Outdated Show resolved Hide resolved
Sudoku/photoSudokuViewController.swift Outdated Show resolved Hide resolved
@Juhwa-Lee1023 Juhwa-Lee1023 merged commit 201b1eb into main Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Applying the model to a project
3 participants