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 8627527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:18:10+00:00 2026-06-12T08:18:10+00:00

I am trying to access openCV matrix element which comes from converting video frame

  • 0

I am trying to access openCV matrix element which comes from converting video frame into grayscale. My code is like this:

int C = 3; 
cv::Mat grayPrevious;
cv::cvtColor ( previousFrame, grayPrevious, CV_RGB2GRAY  );
double* grayPtr = grayPrevious.ptr <double> ();

double mean [600][800][3];

///... // set some values to mean here

for ( int i = 0; i < 600; i ++ )
{
    for ( int j = 0; j < 800; j ++ )
    {
        for ( int m = 0; m < C; m ++ )
        {
            diff [i][j][m]= abs(grayPtr[ 800* (i-1)+j] - mean[i][j][m]);
        }

    }
}

But it crashes in the for loop. Is this something related to datatypes? How can I change it?

Besides, my second question is, I tried to see the elements of grayPrevious matrix on the screen using “grayPrevious.at”, but it shows values like ” -5.235125e+30″ for “double”, or “-11242433” for “int”. This is also confusing me, I was expecting to see values between 0 and 255.

  • 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-12T08:18:11+00:00Added an answer on June 12, 2026 at 8:18 am

    You should use uchar instead of int or double since you are dealing with grayscale images. (You can cast the uchar to print: cout<<(int)grayPrevious.at<uchar>(i,j);)

    Is there any reason you are trying to access pixels directly “the hard way”?
    You could do grayprevious.at<uchar>(i,j) (assuming your image is 800×600) which is easier to debug and then use direct pixel access.

    Edit: I think it should be:

    uchar* grayPtr = grayPrevious.ptr <uchar> (); and then grayPtr[grayPrevious.cols*i+j];

    You could also do grayPrevious.data[grayPrevious.cols*i+j]; (Still direct access without ptr)

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

Sidebar

Related Questions

i am trying access an asp label within an asp repeater from my code
This is a continuation question from Opencv video frame giving me an error I
Im trying to access the org.testng.reporters.XMLReporter from my Java code. I am writing code
Trying to access a Servlet from a button on HTML page //Html Page FORM
I am trying to access all the data from database listOfFolder table folder and
Hi I'm trying to access a WCF service which returns a JSON Array using
I'm trying to access the resources of a derived abstract class (from PhoneApplicationPage) in
I'm trying to play a video using opencv (the video is an avi file
Im trying to access information from two different arrays within my viewModel with two
someone trying to access pages like //mysqladmin//scripts/setup.php Is it some hack attempt or ..

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.