47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
|
|
// Code scaffolded by goctl. Safe to edit.
|
||
|
|
// goctl 1.10.1
|
||
|
|
|
||
|
|
package logic
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"img_infinite_canvas/internal/domain/design"
|
||
|
|
"img_infinite_canvas/internal/svc"
|
||
|
|
"img_infinite_canvas/internal/types"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
type RecognizeObjectLogic struct {
|
||
|
|
logx.Logger
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewRecognizeObjectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RecognizeObjectLogic {
|
||
|
|
return &RecognizeObjectLogic{
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *RecognizeObjectLogic) RecognizeObject(req *types.RecognizeObjectRequest) (resp *types.RecognizeObjectResponse, err error) {
|
||
|
|
box := toDomainNormalizedBox(req.BoundingBox)
|
||
|
|
if box.Width <= 0 || box.Height <= 0 {
|
||
|
|
box = toDomainNormalizedBox(req.BBox)
|
||
|
|
}
|
||
|
|
result, err := l.svcCtx.DesignService.RecognizeObject(l.ctx, design.ObjectRecognitionRequest{
|
||
|
|
ImageBase64: req.ImageBase64,
|
||
|
|
ImageURL: req.ImageUrl,
|
||
|
|
BoundingBox: box,
|
||
|
|
Lang: req.Lang,
|
||
|
|
Prompt: req.Prompt,
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
return toRecognizeObjectResponse(result), nil
|
||
|
|
}
|