change(kamite): bring Kamite auto snip size in line with Kamite's default

This commit is contained in:
Piotr Grabowski 2022-07-13 18:46:24 +02:00
parent be7101c76d
commit e0d5717365

View file

@ -30,10 +30,12 @@ import (
) )
const ( const (
kamiteRecognizeImageSnipDimensionPx = 500 kamiteRecognizeImageSnipWidthPx = 550
kamiteCMDEndpointBaseTpl = "http://localhost:%d/cmd/" kamiteRecognizeImageSnipHeightPx = 900
kamiteOCRImageEndpoint = "ocr/image"
kamiteOCRManualBlockEndpoint = "ocr/manual-block" kamiteCMDEndpointBaseTpl = "http://localhost:%d/cmd/"
kamiteOCRImageEndpoint = "ocr/image"
kamiteOCRManualBlockEndpoint = "ocr/manual-block"
bytesPerPixel = 3 bytesPerPixel = 3
) )
@ -105,11 +107,12 @@ func (app *App) kamiteRecognizeImageUnderCursorBlock() {
srcRowstride := srcPixbuf.GetRowstride() srcRowstride := srcPixbuf.GetRowstride()
// 4. Grab area around the cursor // 4. Grab area around the cursor
snipDim := kamiteRecognizeImageSnipDimensionPx snipW := kamiteRecognizeImageSnipWidthPx
snipSourceX0, snipSourceY0 := targetX-(snipDim/2), targetY-(snipDim/2) snipH := kamiteRecognizeImageSnipHeightPx
snipBytes := make([]byte, snipDim*snipDim*bytesPerPixel) snipSourceX0, snipSourceY0 := targetX-(snipW/2), targetY-(snipH/2)
for y := 0; y < snipDim; y++ { snipBytes := make([]byte, snipW*snipH*bytesPerPixel)
for x := 0; x < snipDim; x++ { for y := 0; y < snipH; y++ {
for x := 0; x < snipW; x++ {
srcX, srcY := snipSourceX0+x, snipSourceY0+y srcX, srcY := snipSourceX0+x, snipSourceY0+y
var r, g, b byte var r, g, b byte
if srcX < 0 || srcY < 0 || srcX >= srcW || srcY >= srcH { if srcX < 0 || srcY < 0 || srcX >= srcW || srcY >= srcH {
@ -119,7 +122,7 @@ func (app *App) kamiteRecognizeImageUnderCursorBlock() {
idx := srcY*srcRowstride + srcX*srcNChannels idx := srcY*srcRowstride + srcX*srcNChannels
r, g, b = srcPixels[idx], srcPixels[idx+1], srcPixels[idx+2] r, g, b = srcPixels[idx], srcPixels[idx+1], srcPixels[idx+2]
} }
idx := ((y * snipDim) + x) * bytesPerPixel idx := ((y * snipW) + x) * bytesPerPixel
snipBytes[idx] = r snipBytes[idx] = r
snipBytes[idx+1] = g snipBytes[idx+1] = g
snipBytes[idx+2] = b snipBytes[idx+2] = b
@ -130,8 +133,8 @@ func (app *App) kamiteRecognizeImageUnderCursorBlock() {
go kamiteSendOCRImageCommand( go kamiteSendOCRImageCommand(
app.Config.KamitePort, app.Config.KamitePort,
snipBytes, snipBytes,
snipDim, snipW,
snipDim, snipH,
) )
} }