esimov / caire

Content aware image resize library
MIT License
10.36k stars 384 forks source link

Enlarging an image with face detect panics #75

Closed pjebs closed 2 years ago

pjebs commented 2 years ago

I am attempting to enlarge an image by 200% with face detection. It panics:

    p := &caire.Processor{
        NewWidth:   1024,
        NewHeight:  2048,
        FaceDetect: true,
    }

    resized, err := p.Resize(src)
    if err != nil {
        return nil, err
    }
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1046efcc8]

goroutine 1 [running, locked to thread]:
github.com/esimov/pigo/core.(*Pigo).RunCascade(0x208?, {0xaa, 0x400, 0x3fb999999999999a, 0x3ff199999999999a, {{0x14000400000, 0x80000, 0x80000}, 0x200, 0x400, ...}}, ...)
    /Users/pj/go/pkg/mod/github.com/esimov/pigo@v1.4.5/core/pigo.go:216 +0x68
github.com/esimov/caire.(*Carver).ComputeSeams(0x14000172240, 0x140001442c0, 0x140001721c0)
    /Users/pj/go/pkg/mod/github.com/esimov/caire@v1.4.3/carver.go:102 +0x1cc
github.com/esimov/caire.(*Processor).enlarge(0x140001442c0, 0x1045c8338?, 0x140001721c0)
    /Users/pj/go/pkg/mod/github.com/esimov/caire@v1.4.3/process.go:581 +0xbc
github.com/esimov/caire.(*Processor).Resize.func2(0x14000135d78?, 0x1045c893c?)
    /Users/pj/go/pkg/mod/github.com/esimov/caire@v1.4.3/process.go:169 +0x7c
github.com/esimov/caire.(*Processor).Resize(0x140001442c0, 0x140001721c0)
    /Users/pj/go/pkg/mod/github.com/esimov/caire@v1.4.3/process.go:356 +0x894
facemask/core.FaceMask({0x1047d4fb8?, 0x1400012c078?}, {0x14000135f40, 0x1, 0x1400015bf28?})
    /Users/pj/software/facemask/core/facemask.go:86 +0x2b8
main.main()
    /Users/pj/software/facemask/main.go:23 +0xec
exit status 2

When I try the same operation without face-detection, OR, I try to shrink to image (with or without face-detection), it works. (Note: enlarging the image by 200% without face-detection works, but takes 10-15mins on a new Apple M1)

face

pjebs commented 2 years ago

Here is the project with the files: https://github.com/rocketlaunchr/facemask

pjebs commented 2 years ago

You an modify NewWidth and NewHeight to 200.0

    opts := showerglass.Options{
        NewHeight: 100.0,
        NewWidth:  100.0,
        TriangleConfig: &showerglass.Processor{
            MaxPoints: 5000,
        },
    }

and toggle line 142 in facemask.go

pjebs commented 2 years ago

Is it normal for this algorithm to be quite slow?

esimov commented 2 years ago

I'm looking into this issue and will come back to you as soon as I can.

esimov commented 2 years ago

The issue has been fixed and it should work now. The reason was that one of the core library method used a variable which was initialized in a method which was not reachable by the publicly accessible Resize method which you've been using in your application. Thanks for notifying this issue.

pjebs commented 2 years ago

Has a new version been tagged?

esimov commented 2 years ago

Not yet. I need to fix another issue on the gui part and I will tag a new version afterwards.

esimov commented 2 years ago

@pjebs I published a new release, so please make sure you have updated to v1.4.4.

pjebs commented 2 years ago

Thanks

esimov commented 2 years ago

My pleasure.