I have this code using c#.
public partial class MainForm : Form
{
private CvCapture VideoCapture;
private IplImage frame;
private IplImage imgMain;
public MainForm()
{
InitializeComponent();
}
private void btnVideo_Click(object sender, EventArgs e)
{
double vidWidth, vidHeight;
try
{
VideoCapture = highgui.CvCreateCameraCapture(0);
}
catch (Exception except)
{
MessageBox.Show(except.Message);
}
if (btnVideo.Text.CompareTo("Start Video") == 0)
{
if (VideoCapture.ptr == IntPtr.Zero)
{
MessageBox.Show("badtrip ah!!!");
return;
}
btnVideo.Text = "Stop Video";
highgui.CvSetCaptureProperty(ref VideoCapture, highgui.CV_CAP_PROP_FRAME_WIDTH, 640);
highgui.CvSetCaptureProperty(ref VideoCapture, highgui.CV_CAP_PROP_FRAME_HEIGHT, 480);
highgui.CvQueryFrame(ref VideoCapture);
vidWidth = highgui.cvGetCaptureProperty(VideoCapture, highgui.CV_CAP_PROP_FRAME_WIDTH);
vidHeight = highgui.cvGetCaptureProperty(VideoCapture, highgui.CV_CAP_PROP_FRAME_HEIGHT);
picBoxMain.Width = (int)vidWidth;
picBoxMain.Height = (int)vidHeight;
timerGrab.Enabled = true;
timerGrab.Interval = 42;
timerGrab.Start();
}
else
{
btnVideo.Text = "Start Video";
timerGrab.Enabled = false;
if (VideoCapture.ptr == IntPtr.Zero)
{
highgui.CvReleaseCapture(ref VideoCapture);
VideoCapture.ptr = IntPtr.Zero;
}
}
}
private void timerGrab_Tick(object sender, EventArgs e)
{
try
{
frame = highgui.CvQueryFrame(ref VideoCapture);
if (frame.ptr == IntPtr.Zero)
{
timerGrab.Stop();
MessageBox.Show("??");
return;
}
imgMain = cxcore.CvCreateImage(cxcore.CvGetSize(ref frame), 8, 3);
picBoxMain.Image = highgui.ToBitmap(imgMain, false);
cxcore.CvReleaseImage(ref imgMain);
//cxcore.CvReleaseImage(ref frame);
}
catch (Exception excpt)
{
MessageBox.Show(excpt.Message);
}
}
}
The problem is after i break all and step through the debugger the program stops at a certain code.
the code where it stops is here: frame = highgui.CvQueryFrame(ref VideoCapture); the error is that it says that cannot evaluate expression because a native frame is on top of the call stack.
and then when i try to shift+F11 it. there is another error saying that system.accessviolationexception.
the stack trace says that: at System.Runtime.InteropServices.Marshal.CopyToManaged(IntPtr source, Object destination, Int32 startIndex, Int32 length) at CxCore.IplImage.get_ImageDataDb()
Here is the error i get when i changed the c# opencv wrapper i used from the cvlib to cvwrapcs230d.
Also the DLL's used in the project is included in the folder.
But when i changed the wrapper from cvwrapcs230d to cvwrap230 here is the error i get.
The first Note is the cvwrapcs230d wrapper used while the second is the cvwrapcs230 wrapper.
1st Note: cvwrapcs230d -Thrown: "Unable to load DLL 'cvwrapcpp230': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" (System.DllNotFoundException) Exception Message = "Unable to load DLL 'cvwrapcpp230': The specified module could not be found. (Exception from HRESULT: 0x8007007E)", Exception Type = "System.DllNotFoundException" Exception Message "Unable to load DLL 'cvwrapcpp230': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" string Exception Type "System.DllNotFoundException" string -Thrown: "The type initializer for 'cvlib' threw an exception." (System.TypeInitializationException) Exception Message = "The type initializer for 'cvlib' threw an exception.", Exception Type = "System.TypeInitializationException" Exception Message "The type initializer for 'cvlib' threw an exception." string Exception Type "System.TypeInitializationException" string Stopped at Exception
2nd Note: cvwrapcs230 -Thrown: "Unable to load DLL 'cvwrapcpp230': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" (System.DllNotFoundException) Exception Message = "Unable to load DLL 'cvwrapcpp230': The specified module could not be found. (Exception from HRESULT: 0x8007007E)", Exception Type = "System.DllNotFoundException" Exception Message "Unable to load DLL 'cvwrapcpp230': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" string Exception Type "System.DllNotFoundException" string -cvCreateCameraCapture cvlib.cvCreateCameraCapture(index = {unknown}) index {unknown} int