From 35a85de7b7495878ae4dcb73449f18c28131496c Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期五, 03 二月 2023 17:17:16 +0800 Subject: [PATCH] add go test,complete --- /dev/null | 0 .gitignore | 2 shmparser/shmparser.go | 107 +++++++++-- shmparser/shmparser.h | 31 +-- ctest/main.c | 134 +++++++++----- main.go | 181 +++++++++++++++++++ shmparser/shmparser.c | 57 +++--- 7 files changed, 393 insertions(+), 119 deletions(-) diff --git a/.gitignore b/.gitignore index 957fc9d..5a6847d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ build/ test npic/* - +goshm diff --git a/c_shm b/c_shm deleted file mode 100755 index 5f45ccb..0000000 --- a/c_shm +++ /dev/null Binary files differ diff --git a/ctest/main.c b/ctest/main.c index 940becf..551ebc5 100644 --- a/ctest/main.c +++ b/ctest/main.c @@ -2,13 +2,17 @@ #include <string.h> #include <stdlib.h> #include <errno.h> +#include <sys/time.h> #include "shmparser/shmparser.h" static char* timestamp = "2023-1-31 10:05:56.998"; static char* cid = "cameraid"; static char* cname = "cameraname"; -static struct stimg pack_image(const int w, const int h, +static int printlog = 1; +static int savepic = 0; + +static struct stimg* pack_image(const int w, const int h, const unsigned char* data, const uint64_t size) { int width = w, height = h; @@ -21,22 +25,27 @@ static void print_image(void* shm, const char* file){ struct stimg* img = shm2image(shm); - char fmt[128] = {0}; - sprintf(fmt, "imag2 id [%%lu] data size [%%lu] width [%%d] height [%%d] " - "time [%%%d.%ds] cid [%%%d.%ds] cname [%%%d.%ds]", - img->timestamp_size, img->timestamp_size, - img->camera_id_size, img->camera_id_size, - img->camera_name_size, img->camera_name_size); + if (printlog){ + char fmt[128] = {0}; + sprintf(fmt, "imag2 id [%%lu] data size [%%lu] width [%%d] height [%%d] " + "time [%%%d.%ds] cid [%%%d.%ds] cname [%%%d.%ds]", + img->timestamp_size, img->timestamp_size, + img->camera_id_size, img->camera_id_size, + img->camera_name_size, img->camera_name_size); - printf(fmt, img->id, img->data_size, img->width, img->height, img->timestamp, img->camera_id, img->camera_name); - printf("\n"); + printf(fmt, img->id, img->data_size, img->width, img->height, img->timestamp, img->camera_id, img->camera_name); + printf("\n"); + } - // FILE* fp = fopen(file, "wb"); - // long pos = 0; - // while (pos != img->data_size) { - // pos += fwrite(img->data+pos, 1, img->data_size-pos, fp); - // } - // fclose(fp); + if (savepic){ + FILE* fp = fopen(file, "wb"); + long pos = 0; + while (pos != img->data_size) { + pos += fwrite(img->data+pos, 1, img->data_size-pos, fp); + } + fclose(fp); + } + free_stimg(img); } @@ -64,7 +73,7 @@ fclose(fp); } -static void test_image(char* shm, const int order){ +static void test_image(void* shm, const int order){ const char* pics[] = { "../opic/720x576.jpg", @@ -85,8 +94,9 @@ }else{ w = 1920, h = 1080; } - struct stimg img = pack_image(w, h, d, s); - image2shm(shm, &img); + struct stimg* img = pack_image(w, h, d, s); + image2shm(shm, img); + free_stimg(img); free(d); char file[128] = {0}; sprintf(file, "../npic/%dx%d.%d", w, h, i); @@ -101,8 +111,9 @@ }else{ w = 1920, h = 1080; } - struct stimg img = pack_image(w, h, d, s); - image2shm(shm, &img); + struct stimg* img = pack_image(w, h, d, s); + image2shm(shm, img); + free_stimg(img); free(d); char file[128] = {0}; sprintf(file, "../npic/%dx%d.%d", w, h, i); @@ -112,35 +123,53 @@ static void test_rule(void* shm); +static int test_once(void* shm, const int count){ + + struct timeval s, e; + gettimeofday(&s, NULL); + + for(int i = 0; i < count; i++) + test_rule(shm); + + for(int i = 0; i < count; i++){ + test_image(shm, 0); + // test_image(shm, 1); + } + for(int i = 0; i < count; i++){ + // test_image(shm, 0); + test_image(shm, 1); + } + for(int i = 0; i < count; i++){ + test_image(shm, 0); + test_image(shm, 1); + } + for(int i = 0; i < count; i++){ + test_image(shm, 1); + test_image(shm, 0); + } + + for(int i = 0; i < count; i++) + test_rule(shm); + + gettimeofday(&e, NULL); + + return (e.tv_sec- s.tv_sec)*1000 + (e.tv_usec - s.tv_usec)/1000; +} + int main(int argc, char const *argv[]) { char* shm = (char*)malloc(10*1024*1024); - char* orig = shm; - for(int i = 0; i < 1000; i++) - test_rule(shm); - for(int i = 0; i < 1000; i++){ - // test_image(shm, 0); - test_image(shm, 1); + int cntPerTest = 1000; + int cntRun = 1; + int avg = 0; + for(int i = 1; i <= cntRun; i++){ + int tm = test_once(shm, cntPerTest); + if (avg == 0) avg = tm; + else avg = (double)avg / (double) i * (double)(i-1) + (double)tm / (double)i; } - for(int i = 0; i < 1000; i++){ - // test_image(shm, 0); - test_image(shm, 1); - } - for(int i = 0; i < 1000; i++){ - test_image(shm, 0); - test_image(shm, 1); - } - for(int i = 0; i < 1000; i++){ - test_image(shm, 1); - test_image(shm, 0); - } - printf("shm %p next address %p\n", orig, shm); - // char* shm2 = (char*)malloc(10*1024*1024); - char* shm2 = shm; - for(int i = 0; i < 1000; i++) - test_rule(shm2); + printf("run %d time test, each %d use %d ms\n", cntPerTest*cntRun, cntPerTest, avg); return 0; } @@ -149,7 +178,7 @@ Target* tgts = (Target*)calloc(size, sizeof(Target)); for(int i = 0; i < size; i++){ tgts[i].id = i + 1002; - tgts[i].confidence = 99; + tgts[i].confidence = 99-i; TRect rc = {0,0,1920,1080}; memcpy(&tgts[i].rect, &rc, sizeof(TRect)); memcpy(tgts[i].type, "pack_target", 11); @@ -191,6 +220,10 @@ } for(size_t i = 0; i < sdkcnt; i++){ + for(int j = 0; j < resarray[i].count; j++){ + free(resarray[i].targets[j].feature); + free(resarray[i].targets[j].attribute); + } free(resarray[i].targets); } free(resarray); @@ -205,18 +238,21 @@ static void print_rule(void* shm){ struct strule* rule = shm2rule(shm); - printf("<rule> handletrack [%s] datatype [%s]\n", rule->handletrack, rule->datatype); + if (printlog) + printf("<rule> handletrack [%s] datatype [%s]\n", rule->handletrack, rule->datatype); for(int i = 0; i < rule->sdk_count; i++){ struct stsdk* sdk = &rule->sdk[i]; - printf("\t<sdk> [%d] type [%s] tgts [%d] id [%s] name [%s] timestamp [%s]\n", - i, sdk->sdktype, sdk->tgt_count, sdk->sdkid, sdk->sdkname, sdk->timestamp); + if (printlog){ + printf("\t<sdk> [%d] type [%s] tgts [%d] id [%s] name [%s] timestamp [%s]\n", + i, sdk->sdktype, sdk->tgt_count, sdk->sdkid, sdk->sdkname, sdk->timestamp); - print_targets(sdk->tgt, sdk->tgt_count); + print_targets(sdk->tgt, sdk->tgt_count); + } } - free(rule); + free_strule(rule); } static void test_rule(void* shm){ diff --git a/main.go b/main.go index b7323ea..c3572b3 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,184 @@ package main -import "fmt" +import ( + "fmt" + "goshm/shmparser" + "io/ioutil" + "os" + "time" +) -import "goshm/shmparser" +const ( + printlog = true + savepic = false +) + +func readFile(file string) []byte { + if f, e := os.Open(file); e == nil { + if d, ee := ioutil.ReadAll(f); ee == nil { + f.Close() + return d + } + f.Close() + } + return nil +} + +func printImage(shm []byte, saveFile string) { + img := shmparser.Shm2Image(shm) + + if printlog { + fmt.Printf("image id [%d] data size [%d] rsln [%dx%d] timestamp [%s] cid [%s] cname [%s]\n", + img.Id, len(img.Data), img.Width, img.Height, img.Timestamp, img.Cid, img.Cname) + } + + if savepic { + ioutil.WriteFile(saveFile, img.Data, 0666) + } +} + +func testImage(shm []byte, order bool) { + files := []string{ + "./opic/720x576.jpg", + "./opic/720x576.bgr", + "./opic/1920x1080.jpg", + "./opic/1920x1080.bgr", + } + + if order { + for i, f := range files { + w, h := 1920, 1080 + if i < 2 { + w, h = 720, 576 + } + + d := readFile(f) + shmparser.Image2Shm(shm, "cameraid", "cameraname", d, w, h, 1122331122) + printImage(shm, fmt.Sprintf("./npic/%dx%d.%d", w, h, i)) + } + } else { + for i := len(files) - 1; i >= 0; i-- { + w, h := 1920, 1080 + if i < 2 { + w, h = 720, 576 + } + d := readFile(files[i]) + shmparser.Image2Shm(shm, "cameraid", "cameraname", d, w, h, 1122331122) + printImage(shm, fmt.Sprintf("./npic/%dx%d.%d", w, h, i)) + } + } +} + +func testOnce(shm []byte, count int) int64 { + start := time.Now() + for i := 0; i < count; i++ { + testRule(shm) + } + + for i := 0; i < count; i++ { + testImage(shm, true) + testImage(shm, false) + } + for i := 0; i < count; i++ { + testImage(shm, false) + } + for i := 0; i < count; i++ { + testImage(shm, true) + } + for i := 0; i < count; i++ { + testImage(shm, true) + testImage(shm, false) + } + for i := 0; i < count; i++ { + testImage(shm, false) + testImage(shm, true) + } + + for i := 0; i < count; i++ { + testRule(shm) + } + return int64(time.Now().Sub(start)) +} func main() { - fmt.Println("hello") + shm := make([]byte, 10*1024*1024) + count := 1000 + countTest := 1 + + var avg int64 = 0 + for i := 1; i <= countTest; i++ { + tm := testOnce(shm, count) + if i == 1 { + avg = tm + } else { + avg = avg/int64(i)*int64(i-1) + tm/int64(i) + } + } + + fmt.Printf("run %d time test, each %d use %d ms\n", count*countTest, count, avg/1e6) +} + +func testRule(shm []byte) { + makeRule(shm) + packSdk(shm, 2, 5) + packSdk(shm, 0, 5) + for i := 0; i < 5; i++ { + packSdk(shm, 0, 5) + } + printRule(shm) +} + +func makeRule(shm []byte) { + shmparser.Rule2Shm(shm, "camera_start") +} + +func packTargets(count int, typ string) []shmparser.Target { + var t []shmparser.Target + for i := 0; i < count; i++ { + t = append(t, shmparser.Target{ + Id: uint64(i) + 123123123678, + Confidence: 99 - i, + Rc: shmparser.Rect{ + Left: 0, + Top: 0, + Right: 1920, + Bottom: 1080, + }, + Type: typ, + Feat: []byte("packTargets-feat"), + Attr: []byte("packTargets-attr"), + }) + } + return t +} + +func packSdk(shm []byte, s, e int) { + types := []string{"face", "yolo", "bike", "fire", "car"} + + for i := s; i < e; i++ { + t := packTargets(2+i, types[i]) + sdk := shmparser.Resdk{ + Type: types[i], + Timestamp: "2023-02-03 11:56:38.987", + Targets: t, + } + shmparser.AddResSdk2RuleInShm(shm, sdk) + } +} + +func printRule(shm []byte) { + rule := shmparser.Shm2Rule(shm) + if !printlog { + return + } + + fmt.Printf("<rule> handletrack [%#v] datatype [%s]\n", rule.Handletrack, rule.Datatype) + for k, v := range rule.Sdks { + fmt.Printf("\t<sdk> [%d] Type [%s] Id [%s] Name [%s] Timestamp [%s]\n", + k, v.Type, v.Id, v.Name, v.Timestamp) + for i, t := range v.Targets { + fmt.Printf("\t\t<target> [%d] Id [%d] Type [%s] Confidence [%d] Rect [%#v] Feat [%s] Attr [%s]\n", + i, t.Id, t.Type, t.Confidence, t.Rc, string(t.Feat), string(t.Attr)) + } + } } diff --git a/shmparser/shmparser.c b/shmparser/shmparser.c index 1ad70dc..49aceb7 100644 --- a/shmparser/shmparser.c +++ b/shmparser/shmparser.c @@ -113,26 +113,25 @@ ptr[7] = (uint8_t) (u); } -struct stimg make_image_ref(const uint64_t id, const unsigned char* data, const uint32_t size, +struct stimg* make_image_ref(const uint64_t id, const unsigned char* data, const uint32_t size, const uint32_t width, const uint32_t height, const char* timestamp, const uint32_t ts_size, const char* camera_id, const uint32_t cid_size, const char* camera_name,const uint32_t cname_size) { - struct stimg img; - memset(&img, 0, sizeof(img)); + struct stimg* img = (struct stimg*)calloc(1, sizeof(struct stimg)); - img.data = (unsigned char*)data; - img.data_size = size; - img.width = width; - img.height = height; - img.id = id; - img.timestamp = (char*)timestamp; - img.timestamp_size = ts_size; - img.camera_id = (char*)camera_id; - img.camera_id_size = cid_size; - img.camera_name = (char*)camera_name; - img.camera_name_size = cname_size; + img->data = (unsigned char*)data; + img->data_size = size; + img->width = width; + img->height = height; + img->id = id; + img->timestamp = (char*)timestamp; + img->timestamp_size = ts_size; + img->camera_id = (char*)camera_id; + img->camera_id_size = cid_size; + img->camera_name = (char*)camera_name; + img->camera_name_size = cname_size; return img; } @@ -551,12 +550,12 @@ /////////////////////////////////////////////////////////////// // go need function -void goimage2shm(void* shm, void* img){ +void goImage2Shm(void* shm, void* img){ struct stimg* cimg = (struct stimg*)img; image2shm(shm, cimg); } -void goimageinfo(void* img, void** data, uint64_t* size, +void goImageGet(void* img, void** data, uint64_t* size, void** ts, uint32_t* tss, void** cid, uint32_t* cids, void** cname, uint32_t* cnames, @@ -580,19 +579,19 @@ *h = cimg->height; } -void gotargetsdel(void* tgts){ +void goTargetsDel(void* tgts){ if (tgts) { struct sttgt* t = (struct sttgt*)tgts; free(t); } } -void* gotargetsnew(const uint32_t size){ +void* goTargetsNew(const uint32_t size){ struct sttgt* t = (struct sttgt*)calloc(size, sizeof(struct sttgt)); return t; } -void gotargetsadd(void* tgts, int idx, uint64_t id, char* type, uint32_t tsize, int32_t confidence, +void goTargetAdd(void* tgts, int idx, uint64_t id, char* type, uint32_t tsize, int32_t confidence, int left, int top, int right, int bottom, unsigned char* feat, uint32_t featsize, unsigned char* attr, uint32_t attrsize) @@ -617,7 +616,7 @@ ts[idx] = t; } -void goruleaddsdk(void* shm, void* tgts, uint32_t tgtcnt, +void goSdkPut(void* shm, void* tgts, uint32_t tgtcnt, char* type, uint32_t tsize, char* timestamp, uint32_t tmsize) { @@ -649,29 +648,31 @@ //////////////////// unserialize -void gorulehandletrack(void* rule, void** data, uint32_t* size){ +void goHandletrackGet(void* rule, void** data, uint32_t* size){ struct strule* r = (struct strule*)rule; *data = r->handletrack; *size = r->handletrack_size; } -void goruledatatype(void* rule, void** data, uint32_t* size){ +void goDatatypeGet(void* rule, void** data, uint32_t* size){ struct strule* r = (struct strule*)rule; *data = r->datatype; *size = r->datatype_size; } -void gorulesdk(void* rule, void** data, uint32_t* size){ +void goSdkArrayGet(void* rule, void** data, uint32_t* size){ struct strule* r = (struct strule*)rule; *data = r->sdk; *size = r->sdk_count; } -void gorulesdkinfo(void* sdk, int idx, void** t, uint32_t* ts, +void goSdkGet(void* sdk, int idx, void** t, uint32_t* ts, void** i, uint32_t* is, void** n, uint32_t* ns, void** tm, uint32_t* tms, void** data, uint32_t* size) { - struct stsdk* s = (struct stsdk*)sdk; + struct stsdk* ss = (struct stsdk*)sdk; + struct stsdk* s = &ss[idx]; + *t = s->sdktype; *ts = s->sdktype_size; @@ -687,12 +688,14 @@ *size = s->tgt_count; } -void gorulesdktargetinfo(void* tgt, int idx, uint64_t* id, int32_t* c, +void goTargetGet(void* tgt, int idx, uint64_t* id, int32_t* c, int32_t* l,int32_t* t,int32_t* r,int32_t* b, void** tp, uint32_t* tps, void** feat, uint32_t* fs, void** attr, uint32_t* attrs) { - struct sttgt* tt = (struct sttgt*)tgt; + struct sttgt* ta = (struct sttgt*)tgt; + struct sttgt* tt = &ta[idx]; + *id = tt->id; *c = tt->confidence; *l = tt->rect.left; diff --git a/shmparser/shmparser.go b/shmparser/shmparser.go index 56e6de0..d814eed 100644 --- a/shmparser/shmparser.go +++ b/shmparser/shmparser.go @@ -22,8 +22,8 @@ return *(*string)(unsafe.Pointer(&d)) } -// Image2shm fill image to shm -func Image2shm(shm []byte, cid, cname string, data []byte, w, h int, fid int64) { +// Image2Shm fill image to shm +func Image2Shm(shm []byte, cid, cname string, data []byte, w, h int, fid int64) { timestamp := strings.Replace(time.Now().Format("2006-01-02 15:04:05.000"), ".", ":", -1) dataptr := (*C.uchar)(unsafe.Pointer(&data[0])) @@ -43,7 +43,8 @@ ) shmptr := unsafe.Pointer(&shm[0]) - C.goimage2shm(shmptr, unsafe.Pointer(&cimg)) + C.goImage2Shm(shmptr, unsafe.Pointer(cimg)) + C.free_stimg(cimg) } // ImageShm Image struct in Shm @@ -57,11 +58,20 @@ Cname string } +func uintptr2byte(p unsafe.Pointer, size uint64) []byte { + if (^uint(0) >> 63) == 0 { + const maxLen = 0x7fffffff + return (*(*[maxLen]byte)(p))[:size:size] + } else { + const maxLen = 0xffffffffffff + return (*(*[maxLen]byte)(p))[:size:size] + } +} + func Shm2Image(shm []byte) ImageShm { cimg := C.shm2image(unsafe.Pointer(&shm[0])) var goimg ImageShm - const maxLen = 0xffffffffffff var data, ts, cid, cname unsafe.Pointer var sd, id C.ulong @@ -69,16 +79,16 @@ p := unsafe.Pointer(cimg) - C.goimageinfo(p, &data, &sd, &ts, &sts, &cid, &scid, &cname, &scname, &id, &w, &h) - goimg.Data = (*[maxLen]byte)(data)[:uint64(sd):uint64(sd)] + C.goImageGet(p, &data, &sd, &ts, &sts, &cid, &scid, &cname, &scname, &id, &w, &h) + goimg.Data = uintptr2byte(data, uint64(sd)) - tmp := (*[maxLen]byte)(ts)[:int(sts):int(sts)] + tmp := uintptr2byte(ts, uint64(sts)) goimg.Timestamp = byte2str(tmp) - tmp = (*[maxLen]byte)(cid)[:int(scid):int(scid)] + tmp = uintptr2byte(cid, uint64(scid)) goimg.Cid = byte2str(tmp) - tmp = (*[maxLen]byte)(cname)[:int(scname):int(scname)] + tmp = uintptr2byte(cname, uint64(scname)) goimg.Cname = byte2str(tmp) goimg.Width = int(w) @@ -136,14 +146,14 @@ // AddResSdk2RuleInShm add sdk message to rule in shm func AddResSdk2RuleInShm(shm []byte, sdk Resdk) { - ctgts := C.gotargetsnew(C.uint(len(sdk.Targets))) + ctgts := C.goTargetsNew(C.uint(len(sdk.Targets))) for k, v := range sdk.Targets { tpbyte := str2byte(v.Type) tptr := (*C.char)(unsafe.Pointer(&tpbyte[0])) featptr := (*C.uchar)(unsafe.Pointer(&v.Feat[0])) attrptr := (*C.uchar)(unsafe.Pointer(&v.Attr[0])) - C.gotargetsadd(ctgts, C.int(k), C.ulong(v.Id), tptr, C.uint(len(v.Type)), + C.goTargetAdd(ctgts, C.int(k), C.ulong(v.Id), tptr, C.uint(len(v.Type)), C.int(v.Confidence), C.int(v.Rc.Left), C.int(v.Rc.Top), C.int(v.Rc.Right), C.int(v.Rc.Bottom), featptr, C.uint(len(v.Feat)), attrptr, C.uint(len(v.Attr))) @@ -156,11 +166,11 @@ tp := str2byte(sdk.Type) tpstr := (*C.char)(unsafe.Pointer(&tp[0])) - C.goruleaddsdk(shmptr, ctgts, C.uint(len(sdk.Targets)), + C.goSdkPut(shmptr, ctgts, C.uint(len(sdk.Targets)), tpstr, C.uint(len(sdk.Type)), tsptr, C.uint(len(sdk.Timestamp))) - C.gotargetsdel(ctgts) + C.goTargetsDel(ctgts) } // Shm2Rule get Rule from shm @@ -170,22 +180,77 @@ crule := C.shm2rule(unsafe.Pointer(&shm[0])) - const maxLen = 0xffffffffffff - - var data unsafe.Pointer - var s32 C.uint + var ht unsafe.Pointer + var sht C.uint p := unsafe.Pointer(crule) - C.gorulehandletrack(p, &data, &s32) - tmp := (*[maxLen]byte)(data)[:int(s32):int(s32)] + C.goHandletrackGet(p, &ht, &sht) + tmp := uintptr2byte(ht, uint64(sht)) rule.Handletrack = byte2str(tmp) - C.goruledatatype(p, &data, &s32) - tmp = (*[maxLen]byte)(data)[:int(s32):int(s32)] + var dt unsafe.Pointer + var sdt C.uint + C.goDatatypeGet(p, &dt, &sdt) + tmp = uintptr2byte(dt, uint64(sdt)) rule.Datatype = byte2str(tmp) //////////////////////////////////////////////// + var csdk unsafe.Pointer + var s32 C.uint + C.goSdkArrayGet(p, &csdk, &s32) + + for i := 0; i < int(s32); i++ { + var ctype, cid, cname, cts, ctgt unsafe.Pointer + var st, si, sn, sts, stgt C.uint + var sdk Resdk + + C.goSdkGet(csdk, C.int(i), &ctype, &st, &cid, &si, + &cname, &sn, &cts, &sts, &ctgt, &stgt) + tmp = uintptr2byte(ctype, uint64(st)) + sdk.Type = byte2str(tmp) + + tmp = uintptr2byte(cid, uint64(si)) + sdk.Id = byte2str(tmp) + + tmp = uintptr2byte(cname, uint64(sn)) + sdk.Name = byte2str(tmp) + tmp = uintptr2byte(cts, uint64(sts)) + sdk.Timestamp = byte2str(tmp) + + for j := 0; j < int(stgt); j++ { + var tid C.ulong + var tc, tl, tt, tr, tb C.int + var tp, tfeat, tattr unsafe.Pointer + var stp, stf, sta C.uint + + var tgt Target + + C.goTargetGet(ctgt, C.int(j), &tid, &tc, &tl, &tt, &tr, &tb, + &tp, &stp, &tfeat, &stf, &tattr, &sta) + + tgt.Id = uint64(tid) + tgt.Confidence = int(tc) + tgt.Rc.Left = int(tl) + tgt.Rc.Top = int(tt) + tgt.Rc.Right = int(tr) + tgt.Rc.Bottom = int(tb) + + tmp = uintptr2byte(tp, uint64(stp)) + tgt.Type = byte2str(tmp) + + tmp = uintptr2byte(tfeat, uint64(stf)) + tgt.Feat = tmp + + tmp = uintptr2byte(tattr, uint64(sta)) + tgt.Attr = tmp + + sdk.Targets = append(sdk.Targets, tgt) + } + + rule.Sdks = append(rule.Sdks, sdk) + } + C.free_strule(crule) return rule diff --git a/shmparser/shmparser.h b/shmparser/shmparser.h index 9fe8732..d5fb983 100644 --- a/shmparser/shmparser.h +++ b/shmparser/shmparser.h @@ -84,7 +84,7 @@ 杩斿洖涓�涓� struct stimg 缁撴瀯鐨勬寚閽堬紝闇�瑕佽皟鐢� free_stimg 閲婃斁 free_stimg 閲婃斁 shm2image 杩斿洖鐨勬寚閽� */ -struct stimg make_image_ref(const uint64_t id, const unsigned char* data, const uint32_t size, +struct stimg* make_image_ref(const uint64_t id, const unsigned char* data, const uint32_t size, const uint32_t width, const uint32_t height, const char* timestamp, const uint32_t ts_size, const char* camera_id, const uint32_t cid_size, @@ -110,42 +110,37 @@ /////////////////////////////////////////////////////////////// // go need function // go image -void goimage2shm(void* shm, void* img); -void goimageinfo(void* img, void** data, uint64_t* size, +void goImage2Shm(void* shm, void* img); +void goImageGet(void* img, void** data, uint64_t* size, void** ts, uint32_t* tss, void** cid, uint32_t* cids, void** cname, uint32_t* cnames, uint64_t* id, uint32_t* w, uint32_t* h); // go rule/sdk/result -void gotargetsdel(void* tgts); -void* gotargetsnew(const uint32_t size); -void gotargetsadd(void* tgts, int idx, uint64_t id, char* type, uint32_t tsize, int32_t confidence, +void goTargetsDel(void* tgts); +void* goTargetsNew(const uint32_t size); +void goTargetAdd(void* tgts, int idx, uint64_t id, char* type, uint32_t tsize, int32_t confidence, int left, int top, int right, int bottom, unsigned char* feat, uint32_t featsize, unsigned char* attr, uint32_t attrsize); -void goruleaddsdk(void* shm, void* tgts, uint32_t tgtcnt, +void goSdkPut(void* shm, void* tgts, uint32_t tgtcnt, char* type, uint32_t tsize, char* timestamp, uint32_t tmsize); // unserialize -void gorulehandletrack(void* rule, void** data, uint32_t* size); -void goruledatatype(void* rule, void** data, uint32_t* size); +void goHandletrackGet(void* rule, void** data, uint32_t* size); +void goDatatypeGet(void* rule, void** data, uint32_t* size); -void gorulesdk(void* rule, void** data, uint32_t* size); -void gorulesdkinfo(void* sdk, int idx, void** t, uint32_t* ts, +void goSdkArrayGet(void* rule, void** data, uint32_t* size); +void goSdkGet(void* sdk, int idx, void** t, uint32_t* ts, void** i, uint32_t* is, void** n, uint32_t* ns, void** tm, uint32_t* tms, void** data, uint32_t* size); -void gorulesdktargetinfo(void* tgt, int idx, uint64_t* id, int32_t* c, +void goTargetGet(void* tgt, int idx, uint64_t* id, int32_t* c, int32_t* l,int32_t* t,int32_t* r,int32_t* b, void** tp, uint32_t* tps, void** feat, uint32_t* fs, void** attr, uint32_t* attrs); -////////////////////////////////////////////////////////////// -// no use -void* gosdknew(); -void gosdkadd(void* sdk, char* type, uint32_t tsize, char* id, uint32_t idsize, - char* name, uint32_t nsize, char* timestamp, uint32_t tmsize, - uint32_t tgtcnt, void* tgts); + #ifdef __cplusplus } -- Gitblit v1.8.0