| | |
| | | } |
| | | return imgs; |
| | | } |
| | | |
| | | void *create_fake_image(const int size){ |
| | | unsigned char *img = (unsigned char*)malloc(size); |
| | | memset(img, 0, size); |
| | | return img; |
| | | } |
| | | |
| | | int fill_images(void *imgs, const int size, const int index, void *data, const int w, const int h, const int c){ |
| | | c_img *images = (c_img*)imgs; |
| | | images[index].data_ = (unsigned char*)data; |
| | |
| | | handle unsafe.Pointer |
| | | result unsafe.Pointer |
| | | batchSize int |
| | | fakeImage unsafe.Pointer |
| | | } |
| | | |
| | | // NewHumanTracker new |
| | |
| | | } |
| | | if h.result != nil { |
| | | C.free(h.result) |
| | | } |
| | | if h.fakeImage != nil { |
| | | C.free(h.fakeImage) |
| | | } |
| | | } |
| | | |
| | |
| | | return nil, errors.New("create C images error") |
| | | } |
| | | defer C.free(cImgs) |
| | | fake := make([]byte, wid*hei*chn) |
| | | for k, v := range imgs { |
| | | logo.Infoln("batch~~~~~~", k, " image: ", v) |
| | | if v == nil { |
| | | C.fill_images(cImgs, C.int(h.batchSize), C.int(k), unsafe.Pointer(&fake[0]), C.int(wid), C.int(hei), C.int(chn)) |
| | | if h.fakeImage == nil { |
| | | h.fakeImage = C.create_fake_image(wid * hei * chn) |
| | | } |
| | | C.fill_images(cImgs, C.int(h.batchSize), C.int(k), h.fakeImage, C.int(wid), C.int(hei), C.int(chn)) |
| | | } else { |
| | | C.fill_images(cImgs, C.int(h.batchSize), C.int(k), unsafe.Pointer(&v.Data[0]), C.int(v.Width), C.int(v.Height), C.int(v.Channel)) |
| | | } |