stream a webcam image from a c++ opencv dll, through to a c# windows form?

asked 2017-06-12 05:58:08 -0500

antithing gravatar image

updated 2017-06-12 06:34:13 -0500

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 (!
                std::cout << "cam not up" << std::endl;

                cap >> frame;

                cv::imshow(":", frame);


        __declspec(dllexport)uchar*  img(void)




//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);

            Thread displayThread = new Thread(stream);


When i run buttonConnect, the camera starts, and the c++ window runs fine. But the c# image in teh picturebox stays black.

edit retag flag offensive close merge delete


It is not an opencv problem. You can use tags in this forum or this one

LBerger gravatar imageLBerger ( 2017-06-12 06:27:27 -0500 )edit

tag added. thank you.

antithing gravatar imageantithing ( 2017-06-12 06:57:33 -0500 )edit