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

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

antithing gravatar image

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

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.

edit retag flag offensive close merge delete

Comments

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 -0600 )edit
1

tag added. thank you.

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

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 gravatar imageDamVinho ( 2020-10-15 10:15:39 -0600 )edit

@DamVinho please ask a new question.first comment is visible only for a few people.

sturkmen gravatar imagesturkmen ( 2020-10-15 10:33:33 -0600 )edit