Giter Site home page Giter Site logo

Training doesn't finish about swiftocr HOT 3 CLOSED

nmac427 avatar nmac427 commented on May 19, 2024
Training doesn't finish

from swiftocr.

Comments (3)

tosbaha avatar tosbaha commented on May 19, 2024

I tried to train the network by myself. Here is what I have tried. I transformed the first image by -10 degrees. Then applied CISpotColor filter to turn yellow-green color to black and rest to white. Then I used extractBlobs function. However it only found 5 blobs instead of 6. I checked blobs and found out that 4th blob is qd. Since my image is fixed width, what is the part that I should change to correctly extract the blobs and train the network? Here is code that I use for image filters. I will really appreciate if you can help me out to solve this OCR problem.

        let firstImage = transformImage("original.jpg")
        let secondImage = myFilter(firstImage)
        let blobs = ocrInstance.extractBlobs(secondImage)

    func transformImage(imagename:String)->CIImage {

        let degreesToRadians: (CGFloat) -> CGFloat = {
            return $0 / 180.0 * CGFloat(M_PI)
        }

        let imagex = CIImage(image: UIImage(named: imagename)!)!
        let transform = CIFilter(name:"CIAffineTransform")!
        transform.setValue(imagex, forKey: kCIInputImageKey)
        let rotation = NSValue(CGAffineTransform: CGAffineTransformMakeRotation(degreesToRadians(-10)))
        transform.setValue(rotation, forKey: "inputTransform")
       return transform.outputImage!
    }

    func myFilter(inputImage:CIImage) ->UIImage? {
        self.context = CIContext(options: nil)

        let centerColor1 = CIColor.init(color: UIColor.blackColor())
        let replacementColor1 = CIColor.init(color: UIColor.whiteColor())

        let centerColor2 = CIColor.init(color: UIColor.blueColor())
        let replacementColor2 = CIColor.init(color: UIColor.whiteColor())
        let centerColor3 =     CIColor.init(color:  UIColor(red: 0.75, green: 0.87, blue: 0.33, alpha: 1))
        let replacementColor3 = CIColor.init(color: UIColor.blackColor())

        let closeness1:Float = 0
        let contrast1:Float = 0

        let closeness2:Float = 0
        let contrast2:Float = 0

        let closeness3:Float = 0.5
        let contrast3:Float = 1

        let parameters : CIParameters = [
            "inputCenterColor1":centerColor1,
            "inputReplacementColor1":replacementColor1,
            "inputCloseness1":closeness1,
            "inputContrast1":contrast1,

            "inputCenterColor2":centerColor2,
            "inputReplacementColor2":replacementColor2,
            "inputCloseness2":closeness2,
            "inputContrast2":contrast2,

            "inputCenterColor3":centerColor3,
            "inputReplacementColor3":replacementColor3,
            "inputCloseness3":closeness3,
            "inputContrast3":contrast3,

            kCIInputImageKey: inputImage
        ]

        let colorSpot = CIFilter(name:"CISpotColor", withInputParameters: parameters)

        if colorSpot == nil {
            print("error filter")
            return nil
        }
        self.tempModImage = colorSpot!.outputImage
        let cgimg = context.createCGImage(self.tempModImage, fromRect: self.tempModImage .extent)
        return  UIImage(CGImage: cgimg)
    }

from swiftocr.

NMAC427 avatar NMAC427 commented on May 19, 2024

Hi. I tried extractBlobs with this image:

It extracted all blobs correctly after I applied the default preprocessing algorithm. You could try adding a thresholding filter at the and of your custom filter.

from swiftocr.

tosbaha avatar tosbaha commented on May 19, 2024

I could make it by changing let xMergeRadius:CGFloat = 0.5 However I still couldn't used your trainer to train the network.Then I used more than 100 samples to train the network. It finished around 1-2 minutes. It worked with 100% success rate. I don't know maybe I was lucky 😄 Thanks for your extractBlobs code, it really helped.

from swiftocr.

Related Issues (20)

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.