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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:10:32+00:00 2026-06-15T02:10:32+00:00

I have been porting some video processing code to C++ using OpenCV 2.4.3. The

  • 0

I have been porting some video processing code to C++ using OpenCV 2.4.3. The following test program closely mimics how my code will read each frame from a video, operate on its contents, and then write new frames to a new video file.

Strangely, the output frames are entirely black when the pixels are set individually, but are written correctly when the entire frame is cloned.

In practice, I’d use the two macros to access and assign desired values, but the sequential scan used in the example shows the idea more clearly.

Does anyone know where I’m going wrong?

test.cpp:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <string>
using namespace std;
using namespace cv;

#define RGB_REF(PR,NC,R,C,CH) (*((PR) + ((3*(NC)*(R)+(C))+(CH))))
#define GRAY_REF(PR,NC,R,C) (*((PR) + (NC)*(R)+(C)))

int main(int argc, char* argv[])
{
    string video_path(argv[1]);
    cerr << "Video path is " + video_path + "\n";
    VideoCapture capture(video_path);
    if ( !capture.isOpened() )
    {
        cerr << "Input file could not be opened\n";
        return 1;
    } else
    {
        string output_path(argv[2]);
        VideoWriter output;
        int ex = (int)capture.get(CV_CAP_PROP_FOURCC);
        Size S = Size((int) capture.get(CV_CAP_PROP_FRAME_WIDTH),
                (int) capture.get(CV_CAP_PROP_FRAME_HEIGHT));
        output.open(output_path,ex,capture.get(CV_CAP_PROP_FPS),S,true);
        if ( !output.isOpened() )
        {
            cerr << "Output file could not be opened\n";
            return 1;
        }
        unsigned int numFrames = (unsigned int) capture.get(CV_CAP_PROP_FRAME_COUNT);
        unsigned int m = (unsigned int) capture.get(CV_CAP_PROP_FRAME_HEIGHT);
        unsigned int n = (unsigned int) capture.get(CV_CAP_PROP_FRAME_WIDTH);
        unsigned char* im = (unsigned char*) malloc(m*n*3*sizeof(unsigned char));
        unsigned char* bw = (unsigned char*) malloc(m*n*3*sizeof(unsigned char));
        Mat frame(m,n,CV_8UC3,im);
        Mat outputFrame(m,n,CV_8UC3,bw);
        for (size_t i=0; i<numFrames; i++)
        {
            capture >> frame;
            for (size_t x=0;x<(3*m*n);x++)
            {
                bw[x] = im[x];
            }
            output << outputFrame; // blank frames
//            output << frame;  // works
//            output << (outputFrame = frame); // works
        }
    }
}
  • 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-15T02:10:33+00:00Added an answer on June 15, 2026 at 2:10 am

    When you query a frame from VideoCapture as capture >> frame;, frame is modified. Say, it has a new data buffer. So im no longer points to the buffer of frame.
    Try
    bm[x] = frame.ptr()[x];

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

Sidebar

Related Questions

I have been working on porting some Oracle DB code to Postgres, and I
I'm just porting some code over from .net to Java. I've been using the
I have been reading up on porting ASP.NET Membership Provider into .NET 3.5 using
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been asked to investigate porting Wii games and some (Sony) PSOne games
Myself and some teammates have been unable to understand why the following snippet of
I have been using std::string in my code. I was going to make a
I've been thinking about what I would miss in porting some Python code to
I have been trying to post some variables to a site using POST method,
I've been porting a big chunk of Java code to C++ and have had

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.