Note that there are some explanatory texts on larger screens.

plurals
  1. POCopy grayscale, color and canny images(3) all into one large IplImage:Opencv Error?
    text
    copied!<p>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.</p> <p>But I'm getting segmentation fault(Core dumped).</p> <p>Core dump:</p> <pre><code>GNU gdb (GDB) 7.0.1-debian Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt; 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: &lt;http://www.gnu.org/software/gdb/bugs/&gt;... 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&amp;) 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) </code></pre> <p>Here line 55 of test.cpp is:</p> <p>...... cvCopy(gray, gray_sub);</p> <p>......</p> <p>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?</p> <pre class="lang-c prettyprint-override"><code>#include &lt;cv.h&gt; #include &lt;highgui.h&gt; #include &lt;stdio.h&gt; int main( int argc, char** argv ) { IplImage *frame; CvCapture *capture = NULL; if(( argc &lt; 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++ &lt; f) { cvGrabFrame(capture); img = cvRetrieveFrame(capture); color_sub = cvCreateImageHeader(size, long_img-&gt;depth, long_img-&gt;nChannels); color_sub-&gt;origin = long_img-&gt;origin; color_sub-&gt;widthStep = long_img-&gt;widthStep; color_sub-&gt;imageData = long_img-&gt;imageData; cvCopy(img, color_sub); cvConvertImage(img, gray); gray_sub = cvCreateImageHeader(size, IPL_DEPTH_8U, 1); gray_sub-&gt;origin = long_img-&gt;origin; gray_sub-&gt;widthStep = long_img-&gt;widthStep; gray_sub-&gt;imageData = long_img-&gt;imageData + size.height * long_img-&gt;widthStep + size.width * long_img-&gt;nChannels; cvCopy(gray, gray_sub); cvCanny(gray, canny, 100, 200); canny_sub = cvCreateImageHeader(size, IPL_DEPTH_8U, 1); canny_sub-&gt;origin = long_img-&gt;origin; canny_sub-&gt;widthStep = long_img-&gt;widthStep; canny_sub-&gt;imageData = long_img-&gt;imageData + size.height * long_img-&gt;widthStep + (size.width * 2) * long_img-&gt;nChannels; cvCopy(canny, canny_sub); cvShowImage("ALLONE", long_img); key = cvWaitKey(10); if(key == 27) break; printf("%d\n", key); } cvReleaseCapture( &amp;capture ); return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload