Hi, as above. I have an opencv dll application that i need to run through a windows forms application. I have this code compiling, but the resulting image is just black. Where am i going wrong here?
//c++ dll code:
extern "C" {
__declspec(dllexport) void camera()
{
cv::VideoCapture cap;
if (!cap.open(0))
std::cout << "cam not up" << std::endl;
while(true)
{
cap >> frame;
cv::imshow(":", frame);
cv::waitKey(1);
}
}
__declspec(dllexport)uchar* img(void)
{
return frame.data;
}
};
//c# form code:
[DllImport("Cranium.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void camera();
[DllImport("Cranium.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr img();
private void stream()
{
Bitmap a = new Bitmap(640, 480, 3 * 640, PixelFormat.Format24bppRgb, img());
pictureImg.Image = a;
}
private void buttonConnect_Click(object sender, EventArgs e)
{
Thread connectThread = new Thread(camera);
connectThread.Start();
Thread displayThread = new Thread(stream);
displayThread.Start();
}
When i run buttonConnect
, the camera starts, and the c++ window runs fine. But the c# image in teh picturebox stays black.