opencvsharp
opencvsharp copied to clipboard
A Rosetta Stone for OpenCvSharp 3.0
This is small piece of code that returns a few errors. I'm making this sheet for myself an others moving into OpenCvSharp 3.0 as so much has changed. Most of it works, however the two errors it is returning are new to me. Any help would be appreciated.
Thanks, Tharyn
// STANDARD
// (Works)
Mat image = new Mat(640, 480, MatType.CV_8U);
// (Works)
Window window = new Window(windowName);
// (Works) Reads image
Mat sourceAmat = Cv2.ImRead(AssetDatabase.GetAssetPath(sourceA), ImreadModes.Color);
// (Works) Displays image in window
Cv2.ImShow(windowName, sourceAmat);
// (???) Create capture but light does not turn on webcam
VideoCapture capture = new VideoCapture();
capture.Read(sourceAmat);
/* ERROR:
OpenCVException: !fixedSize( )
OpenCvSharp.NativeMethods.<.cctor>b__0 (ErrorCode status, System.String funcName, System.String errMsg, System.String fileName, Int32 line, IntPtr userdata)
(wrapper native-to-managed) OpenCvSharp.NativeMethods:<.cctor>b__0 (OpenCvSharp.ErrorCode,intptr,intptr,intptr,int,intptr)
OpenCvSharp.VideoCapture.Read (OpenCvSharp.Mat image)
MatToTexture2D.Start () (at Assets/Scripts/MatToTexture2D.cs:39)
*/
Debug.Log(image); // (Works returns) Mat [ 640*480*CV_8UC1, IsContinuous=True, IsSubmatrix=False, Ptr=0x363150, Data=0x33056020 ]
Debug.Log(capture); // (Works returns ) OpenCvSharp.VideoCapture
Debug.Log(capture.Gain); // (Not working returns) 0
Debug.Log(capture.Brightness); // (Not working returns) 0
Debug.Log(capture.Fps); // (Not working returns) 0
// NATIVE
IntPtr camera = NativeMethods.videoio_VideoCapture_new1();
IntPtr mat = NativeMethods.core_Mat_new1();
Debug.Log(camera); // (Works returns) 704276736
Debug.Log(mat); // (Works returns) 702924480
IntPtr matPtr = NativeMethods.videoio_VideoCapture_read(camera, mat);
//Error 5 Cannot implicitly convert type 'int' to 'System.IntPtr'. An explicit conversion exists (are you missing a cast?)
Maybe you should call Open method of VideoCapture before calling Read.
That did activate the camera, but now it has trouble reading the frame...
// (Works)
Mat image = new Mat();
// (Works)
Window window = new Window(windowName)
// (Works)
VideoCapture capture = new VideoCapture();
// (Works)
capture.Open(0);
capture.Read(image);
// ERROR
OpenCVException: Unknown/unsupported array type OpenCvSharp.NativeMethods.<.cctor>b__0 (ErrorCode status, System.String funcName,
System.String errMsg, System.String fileName, Int32 line, IntPtr userdata) (wrapper native-to-managed)
OpenCvSharp.NativeMethods:<.cctor>b__0 (OpenCvSharp.ErrorCode,intptr,intptr,intptr,int,intptr)
OpenCvSharp.VideoCapture.Read (OpenCvSharp.Mat image)
Please see: https://github.com/shimat/opencvsharp/issues/142
Yep that worked thank you!