Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions highgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ set(highgui_srcs
${CMAKE_CURRENT_LIST_DIR}/src/kanna_rotate.cpp
${CMAKE_CURRENT_LIST_DIR}/src/videocapture.cpp
${CMAKE_CURRENT_LIST_DIR}/src/videowriter.cpp
${CMAKE_CURRENT_LIST_DIR}/src/writer_http.cpp

# dnn
${CMAKE_CURRENT_LIST_DIR}/src/nms.cpp
)
)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND highgui_srcs
${CMAKE_CURRENT_LIST_DIR}/src/capture_v4l2.cpp
${CMAKE_CURRENT_LIST_DIR}/src/display_fb.cpp
${CMAKE_CURRENT_LIST_DIR}/src/writer_http.cpp)
)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
Expand Down Expand Up @@ -121,3 +122,4 @@ else()
ocv_highgui_configure_target()
endif()
endif()

156 changes: 67 additions & 89 deletions highgui/src/videowriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,83 +20,68 @@
#include <stdio.h>
#include <string.h>

#if defined __linux__ && !__ANDROID__
#if (defined __linux__ && !__ANDROID__) || _WIN32
#include "writer_http.h"
#endif

namespace cv {
class VideoWriterImpl {
public:
VideoWriterImpl();

public:
bool is_opened;
int width;
int height;
float fps;

#if (defined __linux__ && !__ANDROID__) || _WIN32
writer_http wt_http;
#endif
};

class VideoWriterImpl
{
public:
VideoWriterImpl();
VideoWriterImpl::VideoWriterImpl() {
is_opened = false;
width = 0;
height = 0;
fps = 0;
}

public:
bool is_opened;
int width;
int height;
float fps;
VideoWriter::VideoWriter() : d(new VideoWriterImpl) {
}

#if defined __linux__ && !__ANDROID__
writer_http wt_http;
#endif
};

VideoWriterImpl::VideoWriterImpl()
{
is_opened = false;
width = 0;
height = 0;
fps = 0;
}

VideoWriter::VideoWriter() : d(new VideoWriterImpl)
{
}

VideoWriter::~VideoWriter()
{
release();

delete d;
}

bool VideoWriter::open(const String& name, int port)
{
if (d->is_opened)
{
VideoWriter::~VideoWriter() {
release();

delete d;
}

if (name == "httpjpg")
{
#if defined __linux__ && !__ANDROID__
if (writer_http::supported())
{
int ret = d->wt_http.open(port);
if (ret == 0)
{
d->is_opened = true;
bool VideoWriter::open(const String &name, int port) {
if (d->is_opened) {
release();
}

#if (defined __linux__ && !__ANDROID__) || _WIN32
if (name == "httpjpg") {
if (writer_http::supported()) {
int ret = d->wt_http.open(port);
if (ret == 0) {
d->is_opened = true;
}
}
}
else
#endif
{
}
}

return d->is_opened;
}
return d->is_opened;
}

bool VideoWriter::isOpened() const
{
return d->is_opened;
}
bool VideoWriter::isOpened() const {
return d->is_opened;
}

void VideoWriter::release()
{
if (!d->is_opened)
return;
void VideoWriter::release() {
if (!d->is_opened)
return;

#if defined __linux__ && !__ANDROID__
if (writer_http::supported())
Expand All @@ -105,40 +90,33 @@ void VideoWriter::release()
}
else
#endif
{
}
{
}

d->is_opened = false;
d->width = 0;
d->height = 0;
d->fps = 0;
}
d->is_opened = false;
d->width = 0;
d->height = 0;
d->fps = 0;
}

VideoWriter& VideoWriter::operator<<(const Mat& image)
{
write(image);
VideoWriter &VideoWriter::operator<<(const Mat &image) {
write(image);

return *this;
}
return *this;
}

void VideoWriter::write(const Mat& image)
{
if (!d->is_opened)
return;
void VideoWriter::write(const Mat &image) {
if (!d->is_opened)
return;

#if defined __linux__ && !__ANDROID__
if (writer_http::supported())
{
// encode jpg
std::vector<uchar> buf;
cv::imencode(".JPG", image, buf);
#if (defined __linux__ && !__ANDROID__) || _WIN32
if (writer_http::supported()) {
// encode jpg
std::vector<uchar> buf;
cv::imencode(".JPG", image, buf);

d->wt_http.write_jpgbuf(buf);
}
else
d->wt_http.write_jpgbuf(buf);
}
#endif
{
}
}

} // namespace cv
Loading