The script darknet.py loads the image directly with a filepath. I'd like to use the detect function with a numpy image loaded from OpenCV. How can I do this? Thanks.
You can convert a numpy array to the format Darknet expects using this function (borrowed from this script you can use as reference)
def array_to_image(arr):
import numpy as np
# need to return old values to avoid python freeing memory
arr = arr.transpose(2,0,1)
c = arr.shape[0]
h = arr.shape[1]
w = arr.shape[2]
arr = np.ascontiguousarray(arr.flat, dtype=np.float32) / 255.0
data = arr.ctypes.data_as(POINTER(c_float))
im = IMAGE(w,h,c,data)
return im, arr
ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: expected IMAGE instance instead of tuple
the snippet you shared is coming from the original repo, hence it seems like the classes used aren't compatible with Alexey's repo.
@louisondumont I added it.
Just uncomment these lines: https://github.com/AlexeyAB/darknet/blob/573d7e80814a4cc3c08897f6c0f67ea189339856/darknet.py#L221-L223
And comment this line: https://github.com/AlexeyAB/darknet/blob/573d7e80814a4cc3c08897f6c0f67ea189339856/darknet.py#L260
Most helpful comment
@louisondumont I added it.
Just uncomment these lines: https://github.com/AlexeyAB/darknet/blob/573d7e80814a4cc3c08897f6c0f67ea189339856/darknet.py#L221-L223
And comment this line: https://github.com/AlexeyAB/darknet/blob/573d7e80814a4cc3c08897f6c0f67ea189339856/darknet.py#L260