I want to pass a image from a python code to a c++ function. My c++ function is in a .so file and is being loaded to python using ctypes. The c++ function takes argument of type Mat
. The argument (i.e. the image) is passed from Python (using opencv).
When i try to run the above scenario, it throws error as below;
ctypes.ArgumentError: argument 1: : Don't know how to convert parameter 1
My code is given below: test.py
import cv2
from ctypes import *
testso = CDLL("./libvideoread.so")
cap = cv2.VideoCapture("Bigbunny.mp4")
if(cap.isOpened == False):
print("error")
else:
frame_width = int(cap.get(3))
frame_height = int(cap.get(4))
cv2.namedWindow('frame',cv2.WINDOW_NORMAL)
while(cap.isOpened):
ret,frame = cap.read()
if ret:
testso.imgread(frame)
else:
break
cap.release()
cv2.destroyAllWindows()
cpp code:
void imgread(Mat frame)
{
/*Do something*/
}
Checked for the error online and came to know that Opencv-python converts image data to numpy array. And Opencv-c++ uses Mat type. So how can I convert numpy array to Mat type or Pass Image from python to c++ function.
I do not want to use Boost::python
Thanks.