Giter Site home page Giter Site logo

Porting Leptonica C code to Java about lept4j HOT 10 CLOSED

Artgit avatar Artgit commented on August 29, 2024
Porting Leptonica C code to Java

from lept4j.

Comments (10)

nguyenq avatar nguyenq commented on August 29, 2024

I think you would need to call regTestSetup to properly set up L_RegParams rp. That may be tricky to implement. If all that you try fail, I would suggest not using L_RegParams variable and replacing regTestWritePixAndCheck call with simpler pixWrite method.

from lept4j.

nguyenq avatar nguyenq commented on August 29, 2024

Doc on regTestSetup API:

http://misc.voidlinux.de/html/regutils_8c.html#a1ed38b553c1fd2997ba6797fc359bf5a

from lept4j.

DanBloomberg avatar DanBloomberg commented on August 29, 2024

Exactly correct. This was set up as a regression test which uses the leptonica regression framework; in particular, the L_RegParams struct. It is not required for using the method.

from lept4j.

Artgit avatar Artgit commented on August 29, 2024

Thanks for your answers. I have removed logic with L_RegParams. But I still having issue with the following code:

    Leptonica1.selDestroy(new PointerByReference(sel1.getPointer()));
    Leptonica1.selDestroy(new PointerByReference(sel2.getPointer()));
    Leptonica1.selDestroy(new PointerByReference(sel3.getPointer()));
    Leptonica1.selDestroy(new PointerByReference(sel4.getPointer()));
    Leptonica1.pixDestroy(new PointerByReference(pix2.getPointer()));
    Leptonica1.pixaDestroy(new PointerByReference(pixa1.getPointer()));

I'm doing something wrong here because when this code is uncommented I have the following exception: Exception in thread "main" java.lang.Error: Invalid memory access
How to correctly destroy Sels objects?

from lept4j.

nguyenq avatar nguyenq commented on August 29, 2024

I experienced no issue with running the code.

from lept4j.

Artgit avatar Artgit commented on August 29, 2024

Sorry, I forgot to add the code that causes the issue:

Leptonica instance = Leptonica.INSTANCE;
instance.pixWrite("result.png", pixs9, ILeptonica.IFF_PNG);

@nguyenq could you please try with these lines?

from lept4j.

nguyenq avatar nguyenq commented on August 29, 2024

New despeckle method, based on Leptonica's speckle_reg.c example, and its test case have been incorporated into the baseline. You can try it out.

from lept4j.

Artgit avatar Artgit commented on August 29, 2024

@nguyenq thanks! I tested despeckle method.

The following code works fine:

Leptonica instance = Leptonica.INSTANCE;
Pix pixs = instance.pixRead("w91frag.jpg");
Leptonica1.pixDisplayWrite(pixs, 1);
pixs = LeptUtils.despeckle(pixs, LeptUtils.SEL_STR2, 2);
instance.pixWrite("result.png", pixs, ILeptonica.IFF_PNG);

The following code doesn't work(with the second invocation of despeckle method the result.png has 0 bytes):

Leptonica instance = Leptonica.INSTANCE;
Pix pixs = instance.pixRead("w91frag.jpg");
Leptonica1.pixDisplayWrite(pixs, 1);
pixs = LeptUtils.despeckle(pixs, LeptUtils.SEL_STR2, 2);
pixs = LeptUtils.despeckle(pixs, LeptUtils.SEL_STR3, 3);
instance.pixWrite("result.png", pixs, ILeptonica.IFF_PNG)

What am I doing wrong?

from lept4j.

nguyenq avatar nguyenq commented on August 29, 2024

Based on the original C example, the second invocation should not be called on the result pix of a previous invocation but rather on the original pix.

Also, reassigning pix variables is not a recommended practice for Leptonica. It leads to memory leaks as the previous pix's resource is not released; it needs to be disposed. Use a new instance of pix, instead.

from lept4j.

Artgit avatar Artgit commented on August 29, 2024

Thanks!

from lept4j.

Related Issues (19)

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.