mirror of
https://github.com/LdDl/go-darknet.git
synced 2025-10-04 07:16:42 +08:00
Compare commits
4 Commits
yolov4-rel
...
v1.3.6
Author | SHA1 | Date | |
---|---|---|---|
![]() |
51c7e39572 | ||
![]() |
7e34b459e6 | ||
![]() |
a18a9cf3e0 | ||
![]() |
3d4b8507dc |
3
Makefile
3
Makefile
@@ -2,7 +2,8 @@
|
||||
.PHONY: prepare_cuda prepare_cudnn download_darknet build_darknet build_darknet_gpu clean clean_cuda clean_cudnn sudo_install
|
||||
|
||||
# Latest battletested AlexeyAB version of Darknet commit
|
||||
LATEST_COMMIT?=f056fc3b6a11528fa0522a468eca1e909b7004b7
|
||||
# LATEST_COMMIT?=f056fc3b6a11528fa0522a468eca1e909b7004b7
|
||||
LATEST_COMMIT?=9d40b619756be9521bc2ccd81808f502daaa3e9a
|
||||
|
||||
# Temporary folder for building Darknet
|
||||
TMP_DIR?=/tmp/
|
||||
|
36
README.md
36
README.md
@@ -35,7 +35,7 @@ Example of such project here: https://github.com/LdDl/license_plate_recognition#
|
||||
|
||||
## Requirements
|
||||
|
||||
You need to install fork of [darknet](https://github.com/AlexeyAB/darknet). Latest commit I've tested is [here](https://github.com/AlexeyAB/darknet/commit/f056fc3b6a11528fa0522a468eca1e909b7004b7)
|
||||
You need to install fork of [darknet](https://github.com/AlexeyAB/darknet). Latest commit I've tested is [here](https://github.com/AlexeyAB/darknet/commit/9d40b619756be9521bc2ccd81808f502daaa3e9a). It corresponds last official [YOLOv4 release](https://github.com/AlexeyAB/darknet/releases/tag/yolov4)
|
||||
|
||||
Use provided [Makefile](Makefile).
|
||||
|
||||
@@ -114,15 +114,15 @@ Building and running program:
|
||||
|
||||
Output should be something like this:
|
||||
```shell
|
||||
traffic light (9): 73.5039% | start point: (238,73) | end point: (251, 106)
|
||||
traffic light (9): 73.5040% | start point: (238,73) | end point: (251, 106)
|
||||
truck (7): 96.6401% | start point: (95,79) | end point: (233, 287)
|
||||
truck (7): 96.4774% | start point: (662,158) | end point: (800, 321)
|
||||
truck (7): 96.1841% | start point: (0,77) | end point: (86, 333)
|
||||
truck (7): 46.8695% | start point: (434,173) | end point: (559, 216)
|
||||
truck (7): 46.8694% | start point: (434,173) | end point: (559, 216)
|
||||
car (2): 99.7370% | start point: (512,188) | end point: (741, 329)
|
||||
car (2): 99.2533% | start point: (260,191) | end point: (422, 322)
|
||||
car (2): 99.2532% | start point: (260,191) | end point: (422, 322)
|
||||
car (2): 99.0333% | start point: (425,201) | end point: (547, 309)
|
||||
car (2): 83.3919% | start point: (386,210) | end point: (437, 287)
|
||||
car (2): 83.3920% | start point: (386,210) | end point: (437, 287)
|
||||
car (2): 75.8621% | start point: (73,199) | end point: (102, 274)
|
||||
car (2): 39.1925% | start point: (386,206) | end point: (442, 240)
|
||||
bicycle (1): 76.3121% | start point: (189,298) | end point: (253, 402)
|
||||
@@ -136,19 +136,19 @@ Building and running program:
|
||||
|
||||
Output should be something like this:
|
||||
```shell
|
||||
truck (7): 49.5197% | start point: (0,136) | end point: (85, 311)
|
||||
car (2): 36.3747% | start point: (95,152) | end point: (186, 283)
|
||||
truck (7): 48.4384% | start point: (95,152) | end point: (186, 283)
|
||||
truck (7): 45.6590% | start point: (694,178) | end point: (798, 310)
|
||||
car (2): 76.8379% | start point: (1,145) | end point: (84, 324)
|
||||
truck (7): 25.5731% | start point: (107,89) | end point: (215, 263)
|
||||
car (2): 99.8783% | start point: (511,185) | end point: (748, 328)
|
||||
car (2): 99.8194% | start point: (261,189) | end point: (427, 322)
|
||||
car (2): 99.6408% | start point: (426,197) | end point: (539, 311)
|
||||
car (2): 74.5610% | start point: (692,186) | end point: (796, 316)
|
||||
car (2): 72.8053% | start point: (388,206) | end point: (437, 276)
|
||||
bicycle (1): 72.2932% | start point: (178,270) | end point: (268, 406)
|
||||
person (0): 97.3026% | start point: (143,135) | end point: (268, 343)
|
||||
truck (7): 49.5123% | start point: (0,136) | end point: (85, 311)
|
||||
car (2): 36.3694% | start point: (95,152) | end point: (186, 283)
|
||||
truck (7): 48.4177% | start point: (95,152) | end point: (186, 283)
|
||||
truck (7): 45.6520% | start point: (694,178) | end point: (798, 310)
|
||||
car (2): 76.8402% | start point: (1,145) | end point: (84, 324)
|
||||
truck (7): 25.5920% | start point: (107,89) | end point: (215, 263)
|
||||
car (2): 99.8782% | start point: (511,185) | end point: (748, 328)
|
||||
car (2): 99.8193% | start point: (261,189) | end point: (427, 322)
|
||||
car (2): 99.6405% | start point: (426,197) | end point: (539, 311)
|
||||
car (2): 74.5627% | start point: (692,186) | end point: (796, 316)
|
||||
car (2): 72.7975% | start point: (388,206) | end point: (437, 276)
|
||||
bicycle (1): 72.2760% | start point: (178,270) | end point: (268, 406)
|
||||
person (0): 97.3007% | start point: (143,135) | end point: (268, 343)
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
15
image.c
15
image.c
@@ -11,3 +11,18 @@ void set_data_f32_val(float* data, int index, float value) {
|
||||
data[index] = value;
|
||||
}
|
||||
|
||||
void to_float_and_fill_image(image* im, int w, int h, uint8_t* data) {
|
||||
int x, y, idx_source;
|
||||
int pixel_count = w * h;
|
||||
int idx = 0;
|
||||
|
||||
for (y = 0; y < h; y++) {
|
||||
for (x = 0; x < w; x++) {
|
||||
idx_source = (y*w + x) * 4;
|
||||
im->data[(pixel_count*0) + idx] = (float)data[idx_source] / 255;
|
||||
im->data[(pixel_count*1) + idx] = (float)data[idx_source+1] / 255;
|
||||
im->data[(pixel_count*2) + idx] = (float)data[idx_source+2] / 255;
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
40
image.go
40
image.go
@@ -14,61 +14,33 @@ import (
|
||||
type DarknetImage struct {
|
||||
Width int
|
||||
Height int
|
||||
ans []float32
|
||||
image C.image
|
||||
}
|
||||
|
||||
// Close and release resources.
|
||||
func (img *DarknetImage) Close() error {
|
||||
C.free_image(img.image)
|
||||
img.ans = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/33186783/get-a-pixel-array-from-from-golang-image-image/59747737#59747737
|
||||
func imgTofloat32(src image.Image) []float32 {
|
||||
func Image2Float32(src image.Image) (*DarknetImage, error) {
|
||||
bounds := src.Bounds()
|
||||
width, height := bounds.Max.X, bounds.Max.Y
|
||||
srcRGBA := image.NewRGBA(src.Bounds())
|
||||
draw.Copy(srcRGBA, image.Point{}, src, src.Bounds(), draw.Src, nil)
|
||||
srcRGBA := image.NewRGBA(bounds)
|
||||
draw.Copy(srcRGBA, image.Point{}, src, bounds, draw.Src, nil)
|
||||
|
||||
red := make([]float32, 0, width*height)
|
||||
green := make([]float32, 0, width*height)
|
||||
blue := make([]float32, 0, width*height)
|
||||
for y := 0; y < height; y++ {
|
||||
for x := 0; x < width; x++ {
|
||||
idxSource := (y*width + x) * 4
|
||||
pix := srcRGBA.Pix[idxSource : idxSource+4]
|
||||
rpix, gpix, bpix := float32(pix[0])/257.0, float32(pix[1])/257.0, float32(pix[2])/257.0
|
||||
red = append(red, rpix)
|
||||
green = append(green, gpix)
|
||||
blue = append(blue, bpix)
|
||||
}
|
||||
}
|
||||
srcRGBA = nil
|
||||
|
||||
ans := make([]float32, len(red)+len(green)+len(blue))
|
||||
copy(ans[:len(red)], red)
|
||||
copy(ans[len(red):len(red)+len(green)], green)
|
||||
copy(ans[len(red)+len(green):], blue)
|
||||
red = nil
|
||||
green = nil
|
||||
blue = nil
|
||||
return ans
|
||||
return ImageRGBA2Float32(srcRGBA)
|
||||
}
|
||||
|
||||
// Image2Float32 Returns []float32 representation of image.Image
|
||||
func Image2Float32(img image.Image) (*DarknetImage, error) {
|
||||
// ans := imgTofloat32(img)
|
||||
func ImageRGBA2Float32(img *image.RGBA) (*DarknetImage, error) {
|
||||
width := img.Bounds().Dx()
|
||||
height := img.Bounds().Dy()
|
||||
imgDarknet := &DarknetImage{
|
||||
Width: width,
|
||||
Height: height,
|
||||
ans: imgTofloat32(img),
|
||||
image: C.make_image(C.int(width), C.int(height), 3),
|
||||
}
|
||||
C.fill_image_f32(&imgDarknet.image, C.int(width), C.int(height), 3, (*C.float)(unsafe.Pointer(&imgDarknet.ans[0])))
|
||||
C.to_float_and_fill_image(&imgDarknet.image, C.int(width), C.int(height), (*C.uint8_t)(unsafe.Pointer(&img.Pix[0])))
|
||||
return imgDarknet, nil
|
||||
}
|
||||
|
||||
|
3
image.h
3
image.h
@@ -3,4 +3,5 @@
|
||||
#include <darknet.h>
|
||||
|
||||
extern void fill_image_f32(image *im, int w, int h, int c, float* data);
|
||||
extern void set_data_f32_val(float* data, int index, float value);
|
||||
extern void set_data_f32_val(float* data, int index, float value);
|
||||
extern void to_float_and_fill_image(image *im, int w, int h, uint8_t* data);
|
||||
|
Reference in New Issue
Block a user