Fixed memory leaks. And fixes for Web-camera and IP-camera.

This commit is contained in:
AlexeyAB
2018-05-04 23:52:05 +03:00
parent 4232ace376
commit 89354d0a0c
9 changed files with 109 additions and 44 deletions

View File

@ -44,6 +44,12 @@ using std::cerr;
using std::endl;
#include "opencv2/opencv.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/imgproc/imgproc_c.h"
#ifndef CV_VERSION_EPOCH
#include "opencv2/videoio/videoio.hpp"
#endif
using namespace cv;
#include "http_stream.h"
@ -196,6 +202,18 @@ void send_mjpeg(IplImage* ipl, int port, int timeout, int quality) {
}
// ----------------------------------------
CvCapture* get_capture_video_stream(char *path) {
CvCapture* cap = NULL;
try {
cap = (CvCapture*)new cv::VideoCapture(path);
}
catch (...) {
std::cout << " Error: Web-camera " << path << " can't be opened! \n";
}
return cap;
}
// ----------------------------------------
CvCapture* get_capture_webcam(int index) {
CvCapture* cap = NULL;
try {
@ -215,14 +233,18 @@ IplImage* get_webcam_frame(CvCapture *cap) {
try {
cv::VideoCapture &cpp_cap = *(cv::VideoCapture *)cap;
cv::Mat frame;
if (cpp_cap.isOpened()) {
if (cpp_cap.isOpened())
{
cpp_cap >> frame;
src = cvCreateImageHeader(cvSize(frame.cols, frame.rows), 8, frame.channels());
*src = frame;
IplImage tmp = frame;
src = cvCloneImage(&tmp);
}
else {
std::cout << " Video-stream stoped! \n";
}
}
catch (...) {
std::cout << " Web-camera stoped! \n";
std::cout << " Video-stream stoped! \n";
}
return src;
}