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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:13:46+00:00 2026-05-30T18:13:46+00:00

I am processing video frames in real time. I loop through each pixel one

  • 0

I am processing video frames in real time. I loop through each pixel one at a time, do some math, and then set the pixel to a specific color (if necessary).

In a nutshell, my algorithm looks like this:

     //videoFrame is IplImage, 8 bit, 4 channel
     for(int i=0;i<videoFrame.width;i++){
        for(int j=0;j<videoFrame.height;j++){

            CvScalar pixel = cvGet2D(&videoFrame, i, j);

            double red = pixel.val[0];
            double green = pixel.val[1];
            double blue = pixel.val[2];

            //do some math


            if (someCondition) {
                cvSet2D(&videoFrame, i, j, white);
            }
        }       
    }

but i find that calls cvGet2D(&videoFrame, i, j); and cvSet2D(&videoFrame, i, j, white); are really expensive(slow). Is there an alternative faster way I can access red/green/blue value of each pixel?

Thanks!

  • 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-05-30T18:13:47+00:00Added an answer on May 30, 2026 at 6:13 pm

    Try accessing the data directly with pointer as following.

    for(int i=0;i<videoFrame.width;i++){
      for(int j=0;j<videoFrame.height;j++){
        uchar B =((uchar *)(videoFrame.imageData + j*videoFrame.widthStep))[i*videoFrame.nChannels + 0];                      
        uchar G =((uchar *)(videoFrame.imageData + j*videoFrame.widthStep))[i*videoFrame.nChannels + 1];       
        uchar R =((uchar *)(videoFrame.imageData + j*videoFrame.widthStep))[i*videoFrame.nChannels + 2];       
    
    
        //do some math
    
        ((uchar *)(videoFrame.imageData + j*videoFrame.widthStep))[i*videoFrame.nChannels + 0] = B;
        ((uchar *)(videoFrame.imageData + j*videoFrame.widthStep))[i*videoFrame.nChannels + 1] = G;
        ((uchar *)(videoFrame.imageData + j*videoFrame.widthStep))[i*videoFrame.nChannels + 2] = R;
    
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an image processing program to perform real time processing of video frames.
I have a loop which goes through a video with some processing/calculations of the
I am processing frames in a video and displaying it live (real time). The
I'm doing some processing on some very large video files (often up to 16MP),
I'm implementing live video capture through DirectShow for live processing and display. (Augmented Reality
I am making an application that shows the video feed in real time and
I'm experimenting with video processing and I'm looking for uncompressed video frames from iPhone.
I am working on a video processing library in C# and would like to
We are working on a video processing application using EmguCV and recently had to
Processing time doubles as Y goes to the right. Can anybody tell me why?

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.