Coder Social home page Coder Social logo

papers's People

Contributors

pmanot avatar vmanot avatar

Watchers

 avatar

papers's Issues

Extracting Answers

Markscheme format for pre-2017 papers is different, and needs a different function to extract answers

Extracting Questions

Unable to correctly separate paper into questions and their containing pages.

Cropping Image

Below is some example code for a visual preview of snapshots of pages from a test pdf, cropped to isolate the question numbers, which are then to be detected using VisionKit:

struct TestCrop: View {
    let pdf = PDFDocument(url: URL(fileURLWithPath: Bundle.main.path(forResource: "9701_m20_qp_42", ofType: "pdf")!))!
    var body: some View {
        ScrollView {
            VStack {
                ForEach(1..<(pdf.pageCount - 1)){ i in
                    Image(cgImage: pdf.page(at: i)!.snapshot().cgImage!.cropping(to: CGRect(origin: CGPoint(x: 50, y: 0), size: CGSize(width: 100, height: 1000)))!)
                        .resizable()
                        .border(Color.black)
                        .scaleEffect(0.10, anchor: .center)
                        .scaledToFill()
                    
                }
            }
        }
    }
}

When the underlying values for the CGRect cropping the image are changed to further isolate the number, VisionKit seems to fail at recognising it, even though language correction is disabled, and numbers are specifically marked as custom words.

recognizeTextRequest.usesLanguageCorrection = false
recognizeTextRequest.customWords = Array(1..<10).map { "\($0)" }

Furthermore, in tests with different sized phones, there are cases when Vision fails to detect the questions accurately, even though the screen size of the phone is not used as an argument anywhere.

Below is the full code for the VisionKit helper function being called to detect text:

func recogniseText(from image: CGImage) -> String {
    var recognizedText = ""
    let recognizeTextRequest = VNRecognizeTextRequest { (request, error) in
        guard error == nil else { return }
        
        guard let observations = request.results as? [VNRecognizedTextObservation] else { return }
        
        let maximumRecognitionCandidates = 1
        for observation in observations {
            guard let candidate = observation.topCandidates(maximumRecognitionCandidates).first else { continue }
            
            recognizedText = candidate.string
            
        }
    }
    recognizeTextRequest.recognitionLevel = .accurate
    recognizeTextRequest.usesLanguageCorrection = false
    recognizeTextRequest.customWords = Array(1..<10).map { "\($0)" }
    recognizeTextRequest.revision = VNRecognizeTextRequestRevision2
    
    let requestHandler = VNImageRequestHandler(cgImage: image, options: [:])
    try? requestHandler.perform([recognizeTextRequest])
    
    return recognizedText
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.