E
E
Elnur Tazhimbetov2021-02-10 16:55:50
C++ / C#
Elnur Tazhimbetov, 2021-02-10 16:55:50

Why is this code using so much memory?

The code below uses a lot of memory, can you tell me how to make it not use so much?

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;
using System.Windows.Forms;

// Important: include the opencvsharp library in your code
using OpenCvSharp;
using OpenCvSharp.Extensions;

namespace CameraApp
{
    public partial class Form1 : Form
    {

        private Thread camera;

        private void CaptureCamera()
        {
            camera = new Thread(new ThreadStart(CaptureCameraCallback));
            camera.Start();
        }
        private void CaptureCameraCallback()
        {

            VideoCapture capture = new VideoCapture(0);
            capture.Open(0);

            while (true)
            {
                pictureBox1.Image = BitmapConverter.ToBitmap(capture.RetrieveMat());
            }
        }

        public Form1()
        {
            InitializeComponent();
            CaptureCamera();
        }


        // When the user clicks on the start/stop button, start or release the camera and setup flags
        private void button1_Click(object sender, EventArgs e)
        {
            pictureBox1.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            pictureBox1.Hide();
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2021-02-10
@tazhimbetov

'Cause you're in a loop (mother of God) taking pictures from a camera that don't immediately release

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question