Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8886885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:40:04+00:00 2026-06-14T21:40:04+00:00

I am trying to implement computer vision algorithm on my NVidia GPU with openCV.

  • 0

I am trying to implement computer vision algorithm on my NVidia GPU with openCV. I am using openCV 2.4 and I am currently writing very simple programs to get accustomed to openCV. I wrote a simple code of transposing a matrix and also to implementing canny edge detection on GPU. The program is running perfectly but I need to deallocate the memory in both the CPU and GPU. So I am posting my code below :

int main(int argc,char *argv[])
{
  int k;
  cv::Mat src;
  cv::Mat dest;
  cv::Mat dest_1;
  cv::gpu::GpuMat im_source;
  cv::gpu::GpuMat im_dest;
  cv::gpu::GpuMat im_dest_1;
  cv::gpu::Stream::Null;

  k = cv::gpu :: getCudaEnabledDeviceCount();
  printf("%d\n",k);

  src = cv::imread("lena.jpg",0);
  cv::imshow("lena_org",src);
  im_source.upload(src);

  cv::gpu::transpose(im_source,im_dest);

   im_dest.download(dest);

   cv::imshow("lena_trans",dest);

   cv::gpu::Canny(im_source,im_dest_1,100,100,3,false);

   im_dest_1.download(dest_1);
   cv::imshow("lena_edge",dest_1);
   cv::waitKey();

} 

So from the code above I believe the memory is not getting freed in both the CPU and GPU. I was searching the internet a bit and I came across with cv::Mat::Release for cpu and cv::gpu::GpuMat::Release for the GPU side. But I am not getting how to use them or how I should use this functions in my code so that I could free bot my CPU and GPU memories. It would be very much helpful if someone could guide me through correct usage of the Release apis so that I could free the memory successfully. Thanks for all your support.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:40:07+00:00Added an answer on June 14, 2026 at 9:40 pm

    The destructor for cv::Mat objects automatically frees the memory, making calls to the release function you describe. At the level of your code, you shouldn’t have to worry about that. Once the matrix leaves scope, it gets destroyed.

    If you want to manually destroy your reference to the data, you can call, for example, src.release(). There is a good tutorial on memory management in the OpenCV documentation, available here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement an algorithm in computer vision and I want to
I am trying to research and implement some computer vision techniques e.g. motion tracking
For my Computer Networking class, I'm trying to implement Traceroute using raw sockets with
I'm currently trying to implement the game of Nim using Java, I want to
I trying to implement some relatively simple 2D sprite batching in OpenGL ES 2.0
I was trying to implement the Sorry! board game using C++ such that 4
I'm trying to implement a polyline simplification algorithm. The original article can be found
I am trying to implement privileges using NHibernate, and what I want to do,
OK. So I have been trying to implement a timer. Now a very weird
I am doing HCI (Human Computer Interaction) using face tracking. I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.