Ask Your Question

Iam writing a sample code to copy a image to specific folder but it show error at run time?

asked 2017-10-06 01:01:01 -0500

usuf gravatar image

updated 2017-10-06 01:10:37 -0500

berak gravatar image
 #include <stdio.h>
 #include <iostream>
  #include "opencv2/core.hpp"
 #include "opencv2/imgproc.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/calib3d.hpp"
#include "opencv2/xfeatures2d.hpp"
 using namespace cv;
 using namespace cv::xfeatures2d;
 /* @function main */
 int main(int argc, char** argv)

char filename[128];
Mat frame;
cv::VideoCapture cap(0);
if (!cap.isOpened())
    std::cerr << "ERROR: Could not open video " << std::endl;
    return 1;
cvNamedWindow("MyVideo", CV_WINDOW_AUTOSIZE);
int frame_count = 0;
bool should_stop = false;

while (!should_stop)

    cv::Mat frame;
    cap >> frame; //get a new frame from the video
    if (frame.empty())
        should_stop = true; //we arrived to the end of the video

    sprintf(filename, "frame_%06d.jpg", frame_count);
    cv::imwrite(filename, frame);

    if (frame_count == 70)

    /* @function readme */


edit retag flag offensive close merge delete


and the errror is ?

berak gravatar imageberak ( 2017-10-06 01:10:09 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2017-10-06 01:15:06 -0500

berak gravatar image

strcpy - you got src & dest in the wrong order.

not an opencv problem at all, please get a c++ book !

maybe even you should avoid using those c string functions, and use:

cv::String filename = cv::format( "frame_%06d.jpg", frame_count);
cv::imwrite(filename, frame);
edit flag offensive delete link more


above command working fine...but i need to save that images to the specific folder... cv::String filename = cv::format( "E:\vs\frame_%06d.jpg", frame_count); so i am try like this, it shows the error

"bool cv::imwrite(const cv::String &,cv::InputArray,const std::vector<int,std::allocator<_ty>> &)': cannot convert argument 2 from 'cv::String' to 'cv::InputArray'"

usuf gravatar imageusuf ( 2017-10-06 01:30:29 -0500 )edit

how to store the set of images to the specific folder?

usuf gravatar imageusuf ( 2017-10-06 01:31:11 -0500 )edit

problem solved....thanks buddy...

usuf gravatar imageusuf ( 2017-10-06 01:41:58 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-10-06 01:01:01 -0500

Seen: 149 times

Last updated: Oct 06 '17