Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

imread from a splitted frame

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!

imread from a splitted frame

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.