Ask Your Question
-2

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 -0600

usuf gravatar image

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

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"
#include<sstream>
#define _CRT_SECURE_NO_WARNINGS
 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
        continue;
    }

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

    if (frame_count == 70)
    {

        break;
    }
}
    /* @function readme */

}

edit retag flag offensive close merge delete

Comments

and the errror is ?

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

1 answer

Sort by ยป oldest newest most voted
1

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

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

Comments

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 -0600 )edit

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

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

problem solved....thanks buddy...

usuf gravatar imageusuf ( 2017-10-06 01:41:58 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-10-06 01:01:01 -0600

Seen: 341 times

Last updated: Oct 06 '17