Ask Your Question

DT0311's profile - activity

2020-09-04 08:37:46 -0600 received badge  Popular Question (source)
2020-02-29 17:32:03 -0600 received badge  Popular Question (source)
2016-11-10 11:55:50 -0600 asked a question How to take average every X frames

Hi, I want to take average of every 15 images

This is currently what I have:

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

    std::vector<cv::Mat> images(9000);
    for (framenumb = 0; framenumb < 9000; ++framenumb)
    {
        Mat frame;
        cap >> frame;
        if (frame.empty()) break; // end of video stream
        if (waitKey(1) == 27) break; // stop capturing by pressing ESC 
        images[framenumb].create(480, 640, CV_8UC3);
        frame.copyTo(images[framenumb]);
        imshow("webcam", images[framenumb]);
    }
    for (int i = 0; i < 600; i++)
            {
                Mat avgImg(480, 640, CV_32FC3, Scalar());
                for (framenumb = 15 * i; framenumb < (15 * i) + 15; ++framenumb)
                {
                    cv::accumulate(images[framenumb], avgImg);
                }
                //stacking every 15 images into a single image
                avgImg = avgImg / 15;
                avgImg.convertTo(avgImg, CV_8UC3);
                char filename[80];
                sprintf(filename, "C:/AvgPics/test_%d.jpeg", framenumb);
                imwrite(filename, avgImg);

However, this will need me to create a vector of 9000 images, which is a bit excessive. Is there a way for me to accomplish this without having to use a vector?

2016-10-06 04:00:38 -0600 received badge  Enthusiast
2016-10-04 14:59:53 -0600 asked a question Analyze images in group of 10

Hi, I am currently using this function for image averaging:

cv::Mat avgImg;
avgImg.create(width, height,CV_32FC3);

for(i = 1; i <= N; i++){
  image = imread(fileName.c_str(),0);
  cv::accumulate(image, avgImg);
}

avgImg = avgImg / N;

After this, instead of taking average of all images, I wish to take the average of several groups of 10 images. For example, average of image_1 to image_10, then average of image_11 to image_20 and so on. Is there a function that allows for this?

2016-09-25 16:40:13 -0600 received badge  Editor (source)
2016-09-25 14:40:16 -0600 asked a question 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.

2016-08-30 14:35:40 -0600 asked a question Raw video stream for CCD camera

Hi, I'm currently trying to access the raw video stream from my webcam for scientific research. The camera and its associated programme does not seem to have built-in option for RAW mode. Is there a way to access the stream before it is compressed and processed? I am trying to utilise rawCapture function but haven't found much success with it.

Just in case if this information is needed: I'm using TS Moon and Planetary Astro CCD Camera with 1.25" connection

2016-08-30 14:24:08 -0600 commented answer Pixel datas in a circular region

I have tested this and it works perfectly. Thanks a lot!

2016-08-30 14:23:45 -0600 received badge  Supporter (source)
2016-08-26 18:40:31 -0600 asked a question Pixel datas in a circular region

Hi, Just want to ask if it is possible to access the intensity value of all pixels in a circular region at the center of an image? I am very new to openCV and for now I can only set the ROI into a square region.

Thousands of thanks!