Community
cancel
Showing results for 
Search instead for 
Did you mean: 
idata
Community Manager
1,288 Views

Cannot open cv::VideoWriter() with ISS IoT Edition C++

I'm developing the software which saves the movie captured by using webcam as video file (output.avi etc) to local of Intel Edison(/home/root/temp etc).

 

I'm using ISS IoT Edition C++ as IDE, and OpenCV2.4.9 as Image Processing Library.

When I tried to create video file(/home/root/temp/output.avi) using cv::VideoWriter() method which is prepared by OpenCV2.4.9, I found that video file was not created.

I don't know the cause of this problem...Are there any other packages to install such as codec?

If someone knows how to deal with this problem , could you please tell me that?

For your information in detail, I show you the code I created below.

 

Best regards, thanks.

# include

 

# include

 

# include

 

# include

 

# include

const int videolength = 3;

 

const int width = 640;

 

const int height = 480;

 

const double framerate = 20.0;

 

const int imgnums = int(videolength*framerate);

int main()

 

{

 

cv::Mat frames[imgnums];

 

cv::VideoCapture cap(0);

 

if(!cap.isOpened())

 

{

 

std::cerr << "Error: Camera not found" << std::endl;<p>  return -1;

 

}

std::cout << "Camera found" << std::endl;

cap.set(CV_CAP_PROP_FRAME_WIDTH,width); //width=640pix

 

cap.set(CV_CAP_PROP_FRAME_HEIGHT,height); //height=480pix

 

cap.set(CV_CAP_PROP_FPS,framerate); //framerate=20fps

int i = 0;

 

char buf[256];

 

while (cap.isOpened())

 

{

 

if(!cap.read(frames[i]))

 

{

 

std::cerr << "Error: Blank frame grabbed" << std::endl;<p>  break;

 

}

 

sprintf(buf, "/home/root/output_%02d.jpg", i);

 

cv::imwrite(std::string(buf), frames[i++]);

 

if (i == imgnums)

 

{

 

i = 0;

 

}

if(cv::waitKey(30) >= 0)

 

{

 

std::cout << "Key input was occurred" << std::endl;<p>  break;

 

}

 

}

cap.release();

//Video output

 

cv::VideoWriter out;

 

int codec = CV_FOURCC('M', 'J', 'P', 'G');

 

std::string filename = "/home/root/output.avi";

try

 

{

 

out.open(filename, codec, framerate, cv::Size(width, height));

 

}

 

catch (cv::Exception& e)

 

{

 

const char* err_msg = e.what();

 

std::cerr << err_msg << std::endl;<p>  return -1;

 

}

if(!out.isOpened())

 

{

 

std::cerr << "Could not open the output video file" << std::endl; ⇒⇒⇒ that is why out.isOpened() == false.<p>  return -1;

 

}

for (i = 0; i < imgnums; i++)

 

{

 

out.write(frames[i]);

 

}

out.release();

 

return 0;

 

}
0 Kudos
4 Replies
idata
Community Manager
40 Views

Hi Yk0207,

 

 

Thank you for contacting us.

 

 

I'm don't have too much experience using OpenCV, but I will try my best to help you with this.

 

 

I want to run your code under the same conditions than you, so are you following any specific guide to install OpenCV 2.4.9? Could you please provide it? Please include any additional step that you have taken to do this.

 

 

I'll be waiting for your reply.

 

 

Have a nice day.

 

 

Regards,

 

Leonardo R.
idata
Community Manager
40 Views

Hi Leonardo R san

Thank you for your kindness.

I showed the specific guide to install OpenCV2.4.9 bellow.

Setting Intel System Studio(ISS) for IoT edition C++

1. Add OpenCV2.4.9 to Docker container which is used by ISS.

1-1. From Properties for my project(Sample etc), select Intel Package Manager.

1-2. When pushing Add new Packages... button, package Manager Utility dialog launches,

1-3. Type "opencv" word in edit box of package Manager Utility dialog.

1-4. Select all lists(libopencv-calib3d-dev, libopencv-calib3d2.4, .........too many) shown by following 1.3 step.

1-5. Push Add selected package(s) button.

Setting Intel edison

2. Synchronize Intel edison and Docker container.

2-1. When right-clicking target name shown in Connection tab, there is Synchronize packages.

2-2. When selecting Synchronize packages, Libraries related to OpenCV2.4.9 are installed to local directory in edison(/user/lib)

idata
Community Manager
40 Views

Hi Yk0207,

 

 

Thanks for the information.

 

 

I'm going to test it, and I'll contact you when I have updates.

 

 

Have a nice day.

 

 

Regards,

 

Leonardo R.
idata
Community Manager
40 Views

Hi Yk0207,

 

 

I was trying to test your code and I was not able to build the project, it seems that some packages were not installed.

 

 

Nevertheless, I was investigating more about this and it noticed that you can use different codec on the function VideoWriter(), so I recommend you to give it a try to different codec because when I checked your code it looked fine to me. Take a look at the documentation: http://docs.opencv.org/2.4.9/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight... VideoWriter::VideoWriter()

 

 

Have a nice day.

 

 

Regards,

 

Leonardo R.
Reply