stream a webcam image from a c++ opencv dll, through to a c# windows form?
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" {
cv::Mat frame;
__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.
It is not an opencv problem. You can use tags in this forum or this one
tag added. thank you.
Hello !
This question has been asked for a while. I would like to know if there has been a solution. I am currently experiencing the same problem.
Thks!
@DamVinho please ask a new question.first comment is visible only for a few people.