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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:20:05+00:00 2026-06-06T00:20:05+00:00

I’ve a source code(test.cpp) that supposed to display three images(color, grayscale and canny) copied

  • 0

I’ve a source code(test.cpp) that supposed to display three images(color, grayscale and canny) copied to a large image from a avi file(frame by frame) and showed in a single window. I’m using OpenCV library with c++ compiler(gnu) on linux platform.

But I’m getting segmentation fault(Core dumped).

Core dump:

GNU gdb (GDB) 7.0.1-debian
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/ad/Desktop/opencv_exercises/ch4/ex1_b/test...done.

warning: Can't read pathname for load map: Input/output error.
Cannot access memory at address 0x5454505052525555
(gdb) r test.avi
Starting program: /home/ad/Desktop/opencv_exercises/ch4/ex1_b/test test.avi
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff627f831 in memcpy () from /lib/libc.so.6
(gdb) bt
#0  0x00007ffff627f831 in memcpy () from /lib/libc.so.6
#1  0x00007ffff6e5ee42 in cv::Mat::copyTo(cv::Mat&) const ()
   from /usr/lib/libcxcore.so.2.1
#2  0x00007ffff6e629fb in cvCopy () from /usr/lib/libcxcore.so.2.1
#3  0x0000000000400e0a in main (argc=2, argv=0x7fffffffe3a8) at test.cpp:55
(gdb) 

Here line 55 of test.cpp is:

……
cvCopy(gray, gray_sub);

……

The program is(test.cpp) given below. Is it possible to copy three images(color, grayscale and canny on single IplImage)? I’m definitely doing something wrong. Is it possible to kindly help me find out what I am doing wrong?

#include <cv.h>
#include <highgui.h>
#include <stdio.h>


int main( int argc, char** argv )
{
    IplImage *frame;
    CvCapture *capture = NULL;


    if(( argc < 2 ) || !(capture = cvCreateFileCapture( argv[1] )))
    {
        printf("Failed to open %s\n", argv[1] );
        return -1;
    }

    double f = cvGetCaptureProperty(
        capture,
        CV_CAP_PROP_FRAME_COUNT
        );
    double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);



    CvSize size = cvSize(cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH), cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT));
    IplImage *img = NULL;
    double index = 0;
    IplImage *gray = cvCreateImage(size,IPL_DEPTH_8U,1);
    IplImage *canny = cvCreateImage(size,IPL_DEPTH_8U,1);
    IplImage *long_img = cvCreateImage(cvSize(size.width*3, size.height),IPL_DEPTH_8U, 3);
    IplImage *color_sub, *gray_sub, *canny_sub;
    cvNamedWindow("ALLONE", 1);
    int key = 0;

    while( index++ < f)
    {       
            cvGrabFrame(capture);
        img = cvRetrieveFrame(capture);

        color_sub = cvCreateImageHeader(size, long_img->depth, long_img->nChannels);
        color_sub->origin = long_img->origin;
        color_sub->widthStep = long_img->widthStep;
        color_sub->imageData = long_img->imageData;

        cvCopy(img, color_sub);



        cvConvertImage(img, gray);
        gray_sub = cvCreateImageHeader(size, IPL_DEPTH_8U, 1);
        gray_sub->origin = long_img->origin;
        gray_sub->widthStep = long_img->widthStep;
        gray_sub->imageData = long_img->imageData + size.height * long_img->widthStep + size.width * long_img->nChannels;

        cvCopy(gray, gray_sub);


        cvCanny(gray, canny, 100, 200);
        canny_sub = cvCreateImageHeader(size, IPL_DEPTH_8U, 1);
        canny_sub->origin = long_img->origin;
        canny_sub->widthStep = long_img->widthStep;
        canny_sub->imageData = long_img->imageData + size.height * long_img->widthStep + (size.width * 2) * long_img->nChannels;

        cvCopy(canny, canny_sub);



        cvShowImage("ALLONE", long_img);

        key = cvWaitKey(10);
        if(key == 27) break;
        printf("%d\n", key);
    }




    cvReleaseCapture( &capture );

    return 0;
}
  • 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-06T00:20:07+00:00Added an answer on June 6, 2026 at 12:20 am

    I found the solution. Those who are interested the code is given below:

    #include <cv.h>
    #include <highgui.h>
    #include <stdio.h>
    
    
    int main( int argc, char** argv )
    {
        IplImage *frame;
        CvCapture *capture = NULL;
    
    
        if(( argc < 2 ) || !(capture = cvCreateFileCapture( argv[1] )))
        {
            printf("Failed to open %s\n", argv[1] );
            return -1;
        }
    
        double f = cvGetCaptureProperty(
            capture,
            CV_CAP_PROP_FRAME_COUNT
            );
        double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
    
    
    
        CvSize size = cvSize(cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH), cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT));
        IplImage *img = NULL;
        double index = 0;
        IplImage *gray = cvCreateImage(size,IPL_DEPTH_8U,1);
        IplImage *canny = cvCreateImage(size,IPL_DEPTH_8U,1);
        IplImage *long_img = cvCreateImage(cvSize(size.width*3, size.height),IPL_DEPTH_8U, 3);
        IplImage *color_sub, *gray_sub, *canny_sub;
        cvNamedWindow("ALLONE", 1);
        int key = 0;
    
        while( index++ < f)
        {       cvGrabFrame(capture);
            img = cvRetrieveFrame(capture);
    
            color_sub = cvCreateImageHeader(size, long_img->depth, long_img->nChannels);
            color_sub->origin = long_img->origin;
            color_sub->widthStep = long_img->widthStep;
            color_sub->imageData = long_img->imageData;
    
            cvCopy(img, color_sub);
    
    
    
            cvCvtColor(img, gray, CV_BGR2GRAY);
            gray_sub = cvCreateImageHeader(size,  long_img->depth,long_img->nChannels);
            gray_sub->origin = long_img->origin;
            gray_sub->widthStep = long_img->widthStep;
            gray_sub->imageData = long_img->imageData  + (size.width * long_img->nChannels);
    
            cvMerge(gray , gray, gray, NULL, gray_sub);
    
    
            cvCanny(gray, canny, 100, 200);
            canny_sub = cvCreateImageHeader(size, long_img->depth, long_img->nChannels);
            canny_sub->origin = long_img->origin;
            canny_sub->widthStep = long_img->widthStep;
            canny_sub->imageData = long_img->imageData +  ((size.width * 2)  * long_img->nChannels);
    
            cvMerge(canny , canny, canny, NULL, canny_sub);
    
            cvShowImage("ALLONE", long_img);
    
            key = (char) cvWaitKey(1000/fps);
            if(key == 27) break;
            printf("%d\n", key);
        }
    
    
    
    
        cvReleaseCapture( &capture );
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

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.