Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Writing a Video with OpenCV on Ubuntu

I'm trying to save a displayed video from my camera with OpenCV, but none of the codes I use are working. I'm using Ubuntu 14.04 and Qt as my IDE. What could you guys recommend me? The camera is Zed from stereolabs. I'm using the code they provided in their webpage, which produce a window with the camera stream. I just want to save that video. This is the code:

include <iostream>;

// OpenCV

include <opencv2 core="" core.hpp="">;

include <opencv2 highgui="" highgui.hpp="">;

include <opencv2 imgproc="" imgproc.hpp="">;

// ZED

include <zed camera.hpp="">;

// Input from keyboard char keyboard = ' ';

int main(int argc, char* argv) { // Initialize ZED color stream in HD and depth in Performance mode sl::zed::Camera zed = new sl::zed::Camera(sl::zed::HD1080); sl::zed::ERRCODE err = zed->init(sl::zed::MODE::PERFORMANCE, 0, true);

// Quit if an error occurred if (err != sl::zed::SUCCESS) { std::cout << "Unable to init the ZED:" << errcode2str(err) << std::endl; delete zed; return 1; }

// Initialize color image and depth int width = zed->getImageSize().width; int height = zed->getImageSize().height; cv::Mat image(height, width, CV_8UC4,1); cv::Mat depth(height, width, CV_8UC4,1);

// Create OpenCV windows cv::namedWindow("Image", cv::WINDOW_AUTOSIZE); cv::namedWindow("Depth", cv::WINDOW_AUTOSIZE);

// Settings for windows cv::Size displaySize(720, 404); cv::Mat imageDisplay(displaySize, CV_8UC4); cv::Mat depthDisplay(displaySize, CV_8UC4);

// Loop until 'q' is pressed while (keyboard != 'q') {

// Grab frame and compute depth in FULL sensing mode if (!zed->grab(sl::zed::SENSING_MODE::FULL)) {

// Retrieve left color image sl::zed::Mat left = zed->retrieveImage(sl::zed::SIDE::LEFT); memcpy(image.data,left.data,widthheight4*sizeof(uchar));

// Retrieve depth map sl::zed::Mat depthmap = zed->normalizeMeasure(sl::zed::MEASURE::DEPTH); memcpy(depth.data,depthmap.data,widthheight4*sizeof(uchar));

// Display image in OpenCV window cv::resize(image, imageDisplay, displaySize); cv::imshow("Image", imageDisplay);

// Display depth map in OpenCV window cv::resize(depth, depthDisplay, displaySize); cv::imshow("Depth", depthDisplay); }

keyboard = cv::waitKey(30);

}

delete zed;

}

Any suggestion will be appreciated! Thanks in advance.

Writing a Video with OpenCV on Ubuntu

I'm trying to save a displayed video from my camera with OpenCV, but none of the codes I use are working. I'm using Ubuntu 14.04 and Qt as my IDE. What could you guys recommend me? The camera is Zed from stereolabs. I'm using the code they provided in their webpage, which produce a window with the camera stream. I just want to save that video. This The complete code source is the code:

include <iostream>;

// OpenCV

include <opencv2 core="" core.hpp="">;

include <opencv2 highgui="" highgui.hpp="">;

include <opencv2 imgproc="" imgproc.hpp="">;

// ZED

include <zed camera.hpp="">;

// Input from keyboard char keyboard = ' ';

int main(int argc, char* argv) { // Initialize ZED color stream in HD and depth in Performance mode sl::zed::Camera zed = new sl::zed::Camera(sl::zed::HD1080); sl::zed::ERRCODE err = zed->init(sl::zed::MODE::PERFORMANCE, 0, true);

// Quit if an error occurred if (err != sl::zed::SUCCESS) { std::cout << "Unable to init the ZED:" << errcode2str(err) << std::endl; delete zed; return 1; }

// Initialize color image and depth int width = zed->getImageSize().width; int height = zed->getImageSize().height; cv::Mat image(height, width, CV_8UC4,1); cv::Mat depth(height, width, CV_8UC4,1);

// Create OpenCV windows cv::namedWindow("Image", cv::WINDOW_AUTOSIZE); cv::namedWindow("Depth", cv::WINDOW_AUTOSIZE);

// Settings for windows cv::Size displaySize(720, 404); cv::Mat imageDisplay(displaySize, CV_8UC4); cv::Mat depthDisplay(displaySize, CV_8UC4);

// Loop until 'q' is pressed while (keyboard != 'q') {

// Grab frame and compute depth in FULL sensing mode if (!zed->grab(sl::zed::SENSING_MODE::FULL)) {

// Retrieve left color image sl::zed::Mat left = zed->retrieveImage(sl::zed::SIDE::LEFT); memcpy(image.data,left.data,widthheight4*sizeof(uchar));

// Retrieve depth map sl::zed::Mat depthmap = zed->normalizeMeasure(sl::zed::MEASURE::DEPTH); memcpy(depth.data,depthmap.data,widthheight4*sizeof(uchar));

// Display image in OpenCV window cv::resize(image, imageDisplay, displaySize); cv::imshow("Image", imageDisplay);

// Display depth map in OpenCV window cv::resize(depth, depthDisplay, displaySize); cv::imshow("Depth", depthDisplay); }

keyboard = cv::waitKey(30);

}

delete zed;

}here: https://www.stereolabs.com/blog/index.php/2015/06/28/zed-with-opencv/

Any suggestion will be appreciated! Thanks in advance.

click to hide/show revision 3
No.3 Revision

updated 2016-06-20 14:07:52 -0600

berak gravatar image

Writing a Video with OpenCV on Ubuntu

I'm trying to save a displayed video from my camera with OpenCV, but none of the codes I use are working. I'm using Ubuntu 14.04 and Qt as my IDE. What could you guys recommend me? The camera is Zed from stereolabs. I'm using the code they provided in their webpage, which produce a window with the camera stream. I just want to save that video. The complete code source This is here: https://www.stereolabs.com/blog/index.php/2015/06/28/zed-with-opencv/the code:

#include <iostream>;

// OpenCV
#include <opencv2/core/core.hpp>;
#include <opencv2/highgui/highgui.hpp>;
#include <opencv2/imgproc/imgproc.hpp>;

// ZED
#include <zed/Camera.hpp>;

// Input from keyboard
char keyboard = ' ';

int main(int argc, char** argv)
{
// Initialize ZED color stream in HD and depth in Performance mode
sl::zed::Camera* zed = new sl::zed::Camera(sl::zed::HD1080);
sl::zed::ERRCODE err = zed->init(sl::zed::MODE::PERFORMANCE, 0, true);

// Quit if an error occurred
if (err != sl::zed::SUCCESS) {
std::cout << "Unable to init the ZED:" << errcode2str(err) << std::endl;
delete zed;
return 1;
}

// Initialize color image and depth
int width = zed->getImageSize().width;
int height = zed->getImageSize().height;
cv::Mat image(height, width, CV_8UC4,1);
cv::Mat depth(height, width, CV_8UC4,1);

// Create OpenCV windows
cv::namedWindow("Image", cv::WINDOW_AUTOSIZE);
cv::namedWindow("Depth", cv::WINDOW_AUTOSIZE);

// Settings for windows
cv::Size displaySize(720, 404);
cv::Mat imageDisplay(displaySize, CV_8UC4);
cv::Mat depthDisplay(displaySize, CV_8UC4);

// Loop until 'q' is pressed
while (keyboard != 'q') {

 // Grab frame and compute depth in FULL sensing mode
 if (!zed->grab(sl::zed::SENSING_MODE::FULL))
 {

 // Retrieve left color image
 sl::zed::Mat left = zed->retrieveImage(sl::zed::SIDE::LEFT);
 memcpy(image.data,left.data,width*height*4*sizeof(uchar));

// Retrieve depth map
 sl::zed::Mat depthmap = zed->normalizeMeasure(sl::zed::MEASURE::DEPTH);
 memcpy(depth.data,depthmap.data,width*height*4*sizeof(uchar));

 // Display image in OpenCV window
 cv::resize(image, imageDisplay, displaySize);
 cv::imshow("Image", imageDisplay);

 // Display depth map in OpenCV window
 cv::resize(depth, depthDisplay, displaySize);
 cv::imshow("Depth", depthDisplay);
 }

keyboard = cv::waitKey(30);

}

delete zed;

}

Any suggestion will be appreciated! Thanks in advance.