springkim/YOLOv3_SpringEdition

YoloDetectFromFile produces different results than YoloDetectFromPyImage

srasilla opened this issue · 1 comments

I have done different tests and I have noticed that YoloDetectFromFile produces different results than other methods exported. This happens using the same bitmap without compression.
I have also added a method to detect from SystemDrawing.BitmapData from C # and there are also different results.

`
typedef struct bitmapDataStruct {
int width;
int height;
int nChannels;
int widthStep;
unsigned char* imageData;
} bitmapDataStruct;

image bitmapData_to_image(bitmapDataStruct* src)
{
unsigned char *data = (unsigned char *)src->imageData;
int w = src->width;
int h = src->height;
int c = src->nChannels;
int step = src->widthStep;

image im = make_image(w, h, c);

/* Test 1 ***
int i, j, k, count = 0;;
for (k = 0; k < c; ++k) {
	for (i = 0; i < h; ++i) {
		for (j = 0; j < w; ++j) {
			const float tof = data[i*step + j * c + k];
			im.data[count++] = tof / 255.;
		}
	}
}
*/

/* Test 2 ***
int i, j, k;
for (i = 0; i < h; ++i) {
	for (k = 0; k < c; ++k) {
		for (j = 0; j < w; ++j) {
			im.data[k*w*h + i * w + j] = data[i*step + j * c + k] / 255.;
		}
	}
}
*/

int i, j, k;
for (k = 0; k < c; ++k) {
	for (j = 0; j < h; ++j) {
		for (i = 0; i < w; ++i) {
			int dst_index = i + w*j + w*h*k;
			int src_index = k + c*i + c*w*j;
			im.data[dst_index] = (float)data[src_index] / 255.;
		}
	}
}

return im;

}

image wrappToImage(unsigned char* bytes, int width, int height, int channels, int stride)
{
bitmapDataStruct out;
out.imageData = bytes;
out.width = width;
out.height = height;
out.nChannels = channels;
out.widthStep = stride;

image im = bitmapData_to_image(&out);
//rgbgr_image(im);
return im;

}

DLL_MACRO int YoloDetectFromBitmapData(unsigned char* bitmapData, int W, int H, int C, int stride, int* net, float threshold, float* result, int result_sz)
{
const image im = wrappToImage(bitmapData, W, H, C, stride);
const int r = YoloDetect(im, net, threshold, result, result_sz);
free(im.data);
return r;
}`

Now it works, apparently it needs this line in some cases.

rgbgr_image(im);