Open github-0-searcher opened 1 year ago
Hi @github-0-searcher
I generated a 40000x40000 png file using this code:
package main
import (
"image"
"image/color"
"image/png"
"math/rand"
"os"
)
func main() {
// Create a new 40000x40000 pixels image
img := image.NewRGBA(image.Rect(0, 0, 40000, 40000))
// Fill the image with random color
for x := 0; x < 40000; x++ {
for y := 0; y < 40000; y++ {
img.Set(x, y, color.RGBA{uint8(rand.Intn(256)), uint8(rand.Intn(256)), uint8(rand.Intn(256)), 255})
}
}
// Save the image as a PNG file
file, _ := os.Create("large_image.png")
defer file.Close()
png.Encode(file, img)
}
Then, with this sample code:
package main
import (
"fmt"
"gocv.io/x/gocv"
)
func main() {
img := gocv.IMRead("large_image.png", gocv.IMReadAnyColor)
if img.Empty() {
fmt.Println("image is empty")
return
}
defer img.Close()
fmt.Printf("image is %d cols x %d rows\n", img.Cols(), img.Rows())
}
I managed to load the image setting OPENCV_IO_MAX_IMAGE_PIXELS
environment variable.
Like this:
OPENCV_IO_MAX_IMAGE_PIXELS=1600000000 go run .
Output was image is 40000 cols x 40000 rows
so I assume that setting that environment variable you should be fine.
Cheers!
I am trying to load a very large image (40000,40000). I got these error.
I gather that there is an approach in python opencv by setting an environment variable OPENCV_IO_MAX_IMAGE_PIXELS.
Is there anything similar in gocv?
Starting: C:\Users\me\go\bin\dlv.exe dap --listen=127.0.0.1:13540 from C:\Users\me\Desktop\annotator DAP server listening at: 127.0.0.1:13540 Type 'dlv help' for list of commands. Exception 0x20474343 0x12c6b82cf60 0x0 0x7fff92464c3c PC=0x7fff92464c3c signal arrived during external code execution
runtime.cgocall(0x7ff6574d06f1, 0xc0000b9cc0) C:/Programs/Go/src/runtime/cgocall.go:157 +0x3e fp=0xc0000b9c90 sp=0xc0000b9c58 pc=0x7ff6573e557e gocv.io/x/gocv._Cfunc_Image_IMRead(0x12c6b87cfd0, 0x0) _cgo_gotypes.go:2140 +0x56 fp=0xc0000b9cc0 sp=0xc0000b9c90 pc=0x7ff6574c9fb6 gocv.io/x/gocv.IMRead({0x7ff65751fc56, 0x5}, 0x0) C:/Users/me/go/pkg/mod/gocv.io/x/gocv@v0.34.0/imgcodecs.go:139 +0x91 fp=0xc0000b9d58 sp=0xc0000b9cc0 pc=0x7ff6574ca931 annotator/anno.(*ImagePair).ScanBBox(0xc0000b9ef0, 0x5) C:/Users/me/Desktop/annotator/anno/pairs.go:40 +0x4e fp=0xc0000b9ee0 sp=0xc0000b9d58 pc=0x7ff6574caece main.main() C:/Users/me/Desktop/annotator/main.go:25 +0x48 fp=0xc0000b9f68 sp=0xc0000b9ee0 pc=0x7ff6574cb728 runtime.main() C:/Programs/Go/src/runtime/proc.go:267 +0x247 fp=0xc0000b9fe0 sp=0xc0000b9f68 pc=0x7ff65741d9c7 runtime.goexit() C:/Programs/Go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc0000b9fe8 sp=0xc0000b9fe0 pc=0x7ff657446861
goroutine 2 [force gc (idle)]: runtime.gopark(0x7ff65752ab28, 0x7ff6575c7f40, 0x11, 0x14, 0x1) C:/Programs/Go/src/runtime/proc.go:398 +0xfc fp=0xc000055f80 sp=0xc000055f50 pc=0x7ff65741de1c runtime.goparkunlock(0x0?, 0x0?, 0x0?, 0x0?) C:/Programs/Go/src/runtime/proc.go:404 +0x25 fp=0xc000055fb0 sp=0xc000055f80 pc=0x7ff65741dea5 runtime.forcegchelper() C:/Programs/Go/src/runtime/proc.go:322 +0xb5 fp=0xc000055fe0 sp=0xc000055fb0 pc=0x7ff65741dc35 runtime.goexit() C:/Programs/Go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc000055fe8 sp=0xc000055fe0 pc=0x7ff657446861 created by runtime.init.6 in goroutine 1 C:/Programs/Go/src/runtime/proc.go:310 +0x1a
goroutine 3 [GC sweep wait]: runtime.gopark(0x7ff65752ab28, 0x7ff6575c8120, 0xc, 0x14, 0x1) C:/Programs/Go/src/runtime/proc.go:398 +0xfc fp=0xc000057f50 sp=0xc000057f20 pc=0x7ff65741de1c runtime.goparkunlock(0x0?, 0x0?, 0x0?, 0x0?) C:/Programs/Go/src/runtime/proc.go:404 +0x25 fp=0xc000057f80 sp=0xc000057f50 pc=0x7ff65741dea5 runtime.bgsweep(0x0?) C:/Programs/Go/src/runtime/mgcsweep.go:280 +0xa5 fp=0xc000057fc8 sp=0xc000057f80 pc=0x7ff657406485 runtime.gcenable.func1() C:/Programs/Go/src/runtime/mgc.go:200 +0x25 fp=0xc000057fe0 sp=0xc000057fc8 pc=0x7ff6573fa8c5 runtime.goexit() C:/Programs/Go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc000057fe8 sp=0xc000057fe0 pc=0x7ff657446861 created by runtime.gcenable in goroutine 1 C:/Programs/Go/src/runtime/mgc.go:200 +0x66
goroutine 4 [GC scavenge wait]: runtime.gopark(0x7ff65752ab28, 0x7ff6575c8280, 0xd, 0x14, 0x2) C:/Programs/Go/src/runtime/proc.go:398 +0xfc fp=0xc000065f40 sp=0xc000065f10 pc=0x7ff65741de1c runtime.goparkunlock(0x7ff65752ff70?, 0x1?, 0x0?, 0xc000052b60?) C:/Programs/Go/src/runtime/proc.go:404 +0x25 fp=0xc000065f70 sp=0xc000065f40 pc=0x7ff65741dea5 runtime.(*scavengerState).park(0x7ff6575c8280) C:/Programs/Go/src/runtime/mgcscavenge.go:425 +0x45 fp=0xc000065f98 sp=0xc000065f70 pc=0x7ff657403705 runtime.bgscavenge(0x0?) C:/Programs/Go/src/runtime/mgcscavenge.go:653 +0x45 fp=0xc000065fc8 sp=0xc000065f98 pc=0x7ff657403c65 runtime.gcenable.func2() C:/Programs/Go/src/runtime/mgc.go:201 +0x25 fp=0xc000065fe0 sp=0xc000065fc8 pc=0x7ff6573fa865 runtime.goexit() C:/Programs/Go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc000065fe8 sp=0xc000065fe0 pc=0x7ff657446861 created by runtime.gcenable in goroutine 1 C:/Programs/Go/src/runtime/mgc.go:201 +0xa5
goroutine 18 [finalizer wait]: runtime.gopark(0x7ff65752aa10, 0x7ff65761d748, 0x10, 0x14, 0x1) C:/Programs/Go/src/runtime/proc.go:398 +0xfc fp=0xc000059e28 sp=0xc000059df8 pc=0x7ff65741de1c runtime.runfinq() C:/Programs/Go/src/runtime/mfinal.go:193 +0xfa fp=0xc000059fe0 sp=0xc000059e28 pc=0x7ff6573f997a runtime.goexit() C:/Programs/Go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc000059fe8 sp=0xc000059fe0 pc=0x7ff657446861 created by runtime.createfing in goroutine 1 C:/Programs/Go/src/runtime/mfinal.go:163 +0x45 rax 0x12c6b82d270 rbx 0x12c6b82cf60 rcx 0x12c06040002 rdi 0x7066d460 rsi 0x707b01e0 rbp 0x12c6b82cfe0 rsp 0x10cffff5d0 r8 0x12c6b82d270 r9 0x12c6b820754 r10 0x80 r11 0x191042abf r12 0x12c6b82d000 r13 0x12c6b82aa80 r14 0x10cffff9b0 r15 0x10cffff96c rip 0x7fff92464c3c rflags 0x204 cs 0x33 fs 0x53 gs 0x2b Process 25580 has exited with status 2 Detaching