Ask Your Question
0

imread from a splitted frame

asked 2016-09-25 14:40:16 -0600

DT0311 gravatar image

updated 2016-09-25 16:40:13 -0600

I have recently used this piece of code to save frame data from a webcam:

#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <opencv2/opencv.hpp>
using namespace cv;

#include <fstream>
using namespace std;

int main(int argc, char** argv)
{
VideoCapture cap(0); // open the default camera
if (!cap.isOpened())  // check if we succeeded
    return -1;
cap.set(CV_CAP_PROP_FPS, 15);

Mat edges;
namedWindow("image", 1);
std::vector<cv::Mat> images(100);
for (int i = 0; i < 100; ++i) {
    // this is optional, preallocation so there's no allocation
    // during capture
    images[i].create(480, 640, CV_8UC3);
}
for (int i = 0; i < 100; ++i)
{
    Mat frame;
    cap >> frame; // get a new frame from camera
    frame.copyTo(images[i]);
}
cap.release();

for (int i = 0; i < 100; ++i)
{
    imshow("image", images[i]);
    if (waitKey(30) >= 0) break; }

After this, I want to use imread to analyse the newly splitted frames. However, I cannot think of a way to accomplish this. Thanks in advance for any help!

Editted: Or can I ask about how to save these frames/images into sequential JPGs (e.g. image1.jpg; image2.jpg; etc)? I will then create another piece of code to analyse them after that.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-09-25 18:00:27 -0600

Tetragramm gravatar image

If you're going to analyze them immediately after, you probably don't want to same them as images, just use the vector you've got there. If you need to analyze them repeatedly, or some time later, then you can save them using the imwrite function.

For other simple questions like this, check out the documentation. There are also tutorials there on how to do many basic tasks. That can save you a lot of time.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-09-25 14:40:16 -0600

Seen: 212 times

Last updated: Sep 25 '16