Hy everyone!
as you might have noticed, I was pretty absent from this comunity nowadays. Well, that is because I was developing my first serious project, an ocr application called image power.
image power is my first non game-related piece of usable software, so bare with me for the first few releases, I am new to this stuff.
besides the usual features you might expect from an ocr program(image and pdf document scanning, text extraction, etc), the thing I want to include in image power is something that I've seen plenty much used in phones, but never, to my knowledge, in laptops and PCs in general, the ability to capture fotos for processing directly from the users webcam, either embedded in the laptop or external.
The application development has gon, surprisingly, pretty well indeed, but for the camera problem.
for a verry long time, I searched for a passable solution for accessing the camera from within a winforms application, but couldn't find anything that isn't either for uwp or uses some huge sdk that includes far many things that I wouldn't need, thus just occupying unnecessary space both in the executable itself and the mapped memory sections.
finally I settled on the OpenCV library along with it's wrapper for .net, OpenCVSharp. Here arises my problem, though.
Since I didn't want to put my project at risc, I creatted a new console application to test it on. Once I installed those two packages(OpenCVSharp4 and OpenCV runtime windows), the code builds successfully, but it throws a dll not found exception, exactly as if I wouldn't have installed the runtime. Any ideas?
I am pasting here the program.cs file just in case.
//beginning of program.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Drawing;
using OpenCvSharp;
using OpenCvSharp.Extensions;
namespace CameraTest
{
public class CameraDriver
{
VideoCapture capture;
Mat frame;
Bitmap image;
public void CameraInit()
{
frame = new Mat();
capture = new VideoCapture(0);
capture.Open(0);
}//func
public Bitmap StartCapture()
{
do
{
Thread.Sleep(300);
}
while (capture.IsOpened() == false);
capture.Read(frame);
image = BitmapConverter.ToBitmap(frame);
return image;
}
public void CameraRelease()
{
capture.Release();
}
//other functions
}//class
class Program
{
static void Main(string[] args)
{
CameraDriver drv = new CameraDriver();
drv.CameraInit();
var Img = drv.StartCapture();
Console.WriteLine("got the image. Now we shall ocr it, part not relevant here because it's out of context"); Console.WriteLine("\n" + "press any key to continue...");
Console.ReadKey();
drv.CameraRelease();
}
}
}
//end of program.cs
I really hope there is an overlooked step on my side, not something wrong done by the package manager, installing the unix version of the runtime instead of the windows one, not for any particular reason, but I got something about libopencvextrn.so, or something like that during the package install process.
O, and here is the exception text for those of you who are wandering.
//begin of exception text
Unhandled Exception: System.TypeInitializationException: The type initializer for 'OpenCvSharp.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'OpenCvSharpExtern': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at OpenCvSharp.NativeMethods.redirectError(CvErrorCallback errCallback, IntPtr userdata, IntPtr& prevUserdata)
at OpenCvSharp.NativeMethods.LoadLibraries(IEnumerable`1 additionalPaths)
at OpenCvSharp.NativeMethods..cctor()
--- End of inner exception stack trace ---
at OpenCvSharp.NativeMethods.core_Mat_new1(IntPtr& returnValue)
at OpenCvSharp.Mat..ctor()
at CameraTest.CameraDriver.CameraInit() in Program.cs:line 21
at CameraTest.Program.Main(String[] args) in Program.cs:line 48
Press any key to continue . . .
//end of exception text.
I had to edit that text, removing the real path that could identify where I keep my projects and such, you know, less easy for attackers to extract any useful info out of the exception text, small as they may be, those paths can be really compromising for my project lol.