测试image

This commit is contained in:
Cai1Cai1 2025-12-24 09:00:38 +08:00
parent 04faa3d95b
commit bd241447c6
8 changed files with 93 additions and 183 deletions

Binary file not shown.

View File

@ -133,7 +133,6 @@ func NewCSVManager(config ManagerConfig) *CSVManager {
if config.MaxOpenFiles <= 0 {
config.MaxOpenFiles = DefaultConfig.MaxOpenFiles
}
return &CSVManager{
handles: sync.Map{},
nextHandle: 1,

102
csv/csv.h
View File

@ -1,102 +0,0 @@
/* Code generated by cmd/cgo; DO NOT EDIT. */
/* package command-line-arguments */
#line 1 "cgo-builtin-export-prolog"
#include <stddef.h>
#ifndef GO_CGO_EXPORT_PROLOGUE_H
#define GO_CGO_EXPORT_PROLOGUE_H
#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
extern size_t _GoStringLen(_GoString_ s);
extern const char *_GoStringPtr(_GoString_ s);
#endif
#endif
/* Start of preamble from import "C" comments. */
#line 3 "csv.go"
#include <stdlib.h>
#line 1 "cgo-generated-wrapper"
/* End of preamble from import "C" comments. */
/* Start of boilerplate cgo prologue. */
#line 1 "cgo-gcc-export-header-prolog"
#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H
typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef size_t GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
#ifdef _MSC_VER
#if !defined(__cplusplus) || _MSVC_LANG <= 201402L
#include <complex.h>
typedef _Fcomplex GoComplex64;
typedef _Dcomplex GoComplex128;
#else
#include <complex>
typedef std::complex<float> GoComplex64;
typedef std::complex<double> GoComplex128;
#endif
#else
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
#endif
/*
static assertion to make sure the file is being used on architecture
at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef _GoString_ GoString;
#endif
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
#endif
/* End of boilerplate cgo prologue. */
#ifdef __cplusplus
extern "C" {
#endif
// ===================== C 函数导入 ==================
// OpenCSVFile 打开/创建CSV文件
//
extern __declspec(dllexport) char* OpenCSVFile(char* filename, char delimiter, int hasHeader);
// UpdateCSVRowSafe 修改csv文件行数据
//
extern __declspec(dllexport) char* UpdateCSVRowSafe(long long int handleID, int rowNum, char* newRow);
#ifdef __cplusplus
}
#endif

View File

@ -1,8 +0,0 @@
"isbn","价格","库存","日志","三方平台id"
"9787107267505","30.80","1","上传成功","877133619369"
"9787200066883","23.17","1","上传成功","877132920079"
"9787115524539","8.87","","调用过于频繁,请调整调用频率",""
"9787810791373","32.02","","调用过于频繁,请调整调用频率",""
"9787548745600","151.30","","商品价格不在设置的价格区间",""
"9787111546955","8.47","","商品信息中包含违规内容",""
"9787303284382","62.76","1","上传成功","877133371509"
1 isbn 价格 库存 日志 三方平台id
2 9787107267505 30.80 1 上传成功 877133619369
3 9787200066883 23.17 1 上传成功 877132920079
4 9787115524539 8.87 调用过于频繁,请调整调用频率
5 9787810791373 32.02 调用过于频繁,请调整调用频率
6 9787548745600 151.30 商品价格不在设置的价格区间
7 9787111546955 8.47 商品信息中包含违规内容
8 9787303284382 62.76 1 上传成功 877133371509

1
es/es.go Normal file
View File

@ -0,0 +1 @@
package main

View File

@ -87,7 +87,7 @@ type Statistics struct {
}
// NewESClient 初始化 ES 客户端
// 说明:与 main(2).go 保持一致的连接方式(禁用证书校验、设置超时和连接池参数)
// 说明:保持一致的连接方式(禁用证书校验、设置超时和连接池参数)
func NewESClient(addresses []string, username, password string) (*ESClient, error) {
cfg := elasticsearch.Config{
Addresses: addresses,

View File

@ -11,9 +11,10 @@ import (
// ImageDLL 图片处理DLL结构
type imageDLL struct {
dll *syscall.DLL
processImage *syscall.Proc
freeCString *syscall.Proc
dll *syscall.DLL
processImage *syscall.Proc
createWhiteBottomCenteredImage *syscall.Proc
freeCString *syscall.Proc
}
// 初始化imageDLL
@ -26,9 +27,10 @@ func InitImageDll() (*imageDLL, error) {
return nil, fmt.Errorf("加载image DLL 失败: %s", err)
} else {
return &imageDLL{
dll: dll,
processImage: dll.MustFindProc("ProcessImage"),
freeCString: dll.MustFindProc("FreeCString"),
dll: dll,
processImage: dll.MustFindProc("ProcessImage"),
createWhiteBottomCenteredImage: dll.MustFindProc("CreateWhiteBottomCenteredImage"),
freeCString: dll.MustFindProc("FreeCString"),
}, nil
}
}
@ -44,6 +46,21 @@ func (m *imageDLL) ProcessImage(config *Config) error {
return nil
}
func (m *imageDLL) CreateWhiteBottomCenteredImage(config *Config, w int, h int) (string, error) {
proc, err2 := m.dll.FindProc("CreateWhiteBottomCenteredImage")
if err2 != nil {
return "", err2
}
marshal, err := json.Marshal(config)
if err != nil {
return "", fmt.Errorf("json转换失败: %s", err)
}
fromString, _ := syscall.BytePtrFromString(string(marshal))
info, _, _ := proc.Call(uintptr(unsafe.Pointer(fromString)), uintptr(w), uintptr(h))
return cStr(info), nil
}
// cStr 将 C 字符串指针转换为 Go 字符串
func cStr(ptr uintptr) string {
if ptr == 0 {
@ -61,27 +78,32 @@ func cStr(ptr uintptr) string {
return string(b)
}
//
//func main() {
//
// config := &Config{
// InputDir: "D:\\www\\wwwroot\\imageTool\\img\\image", // 输入图片目录
// OutputDir: "D:\\isbn_images\\result", // 输出根目录
// FileName: "D:\\isbn_images\\result\\9771671688095.jpg",
// MatchDir: "matched", // 满足条件的图片目录
// UnmatchDir: "unmatched", // 不满足条件的图片目录
// EqualHeightDir: "equalHeight",
// MinWhitePct: 0.1, // 纯白占比下限 10%
// MaxWhitePct: 0.65, // 纯白占比上限 90%
// Extensions: []string{"jpg", "jpeg", "png", "gif", "bmp", "webp"},
// }
//
// dll, err := InitImageDll()
// if err != nil {
// fmt.Println(err)
// }
// err = dll.ProcessImage(config)
// if err != nil {
// fmt.Println(err)
// }
//}
func main() {
config := &Config{
OutputDir: "D:\\isbn_images\\result", // 输出根目录
FileName: "D:\\isbn_images\\result\\9771671688095.jpg",
MatchDir: "matched", // 满足条件的图片目录
UnmatchDir: "unmatched", // 不满足条件的图片目录
WhiteDir: "white",
EqualHeightDir: "equalHeight",
MinWhitePct: 0.1, // 纯白占比下限 10%
MaxWhitePct: 0.65, // 纯白占比上限 90%
Extensions: []string{"jpg", "jpeg", "png", "gif", "bmp", "webp"},
}
dll, err := InitImageDll()
if err != nil {
fmt.Println(err)
}
//err = dll.ProcessImage(config)
//if err != nil {
// fmt.Println(err)
//}
image, err := dll.CreateWhiteBottomCenteredImage(config, 800, 800)
if err != nil {
fmt.Println(err)
}
fmt.Println(image)
}

View File

@ -1,43 +1,41 @@
package main
import "fmt"
func main() {
// ==================== 在这里设置你的参数 ====================
config := &Config{
OutputDir: "D:\\isbn_images\\result", // 输出根目录
FileName: "D:\\isbn_images\\result\\9771671688095.jpg",
MatchDir: "matched", // 满足条件的图片目录
UnmatchDir: "unmatched", // 不满足条件的图片目录
EqualHeightDir: "equalHeight",
WhiteDir: "white",
WhiteBorderPngDir: "whiteBorderPng",
MinWhitePct: 0.1, // 纯白占比下限 10%
MaxWhitePct: 0.65, // 纯白占比上限 90%
Extensions: []string{"jpg", "jpeg", "png", "gif", "bmp", "webp"},
}
//err := processImage(config)
//if err != nil {
// fmt.Println(err)
//}
//
//file, err := resizeToHeightQuality(config, 700)
//if err != nil {
// fmt.Println(err)
//}
//fmt.Println(file)
//config.FileName = file
//fmt.Println(config)
//file1, err := createWhiteBottomCenteredImage(config, 800, 800)
//if err != nil {
// fmt.Println(err)
//}
//fmt.Println(file1)
png, err := removeWhiteBorderAndPNG(config)
if err != nil {
fmt.Println(err)
}
fmt.Println(png)
}
//func main() {
// // ==================== 在这里设置你的参数 ====================
// config := &Config{
// OutputDir: "D:\\isbn_images\\result", // 输出根目录
// FileName: "D:\\isbn_images\\result\\9771671688095.jpg",
// MatchDir: "matched", // 满足条件的图片目录
// UnmatchDir: "unmatched", // 不满足条件的图片目录
// EqualHeightDir: "equalHeight",
// WhiteDir: "white",
// WhiteBorderPngDir: "whiteBorderPng",
// MinWhitePct: 0.1, // 纯白占比下限 10%
// MaxWhitePct: 0.65, // 纯白占比上限 90%
// Extensions: []string{"jpg", "jpeg", "png", "gif", "bmp", "webp"},
// }
//
// //err := processImage(config)
// //if err != nil {
// // fmt.Println(err)
// //}
// //
// //file, err := resizeToHeightQuality(config, 700)
// //if err != nil {
// // fmt.Println(err)
// //}
// //fmt.Println(file)
// //config.FileName = file
// //fmt.Println(config)
// //file1, err := createWhiteBottomCenteredImage(config, 800, 800)
// //if err != nil {
// // fmt.Println(err)
// //}
// //fmt.Println(file1)
//
// png, err := removeWhiteBorderAndPNG(config)
// if err != nil {
// fmt.Println(err)
// }
// fmt.Println(png)
//}