-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix + cimbar_recv
, a test decoder app + ...
#61
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d5dc994
WIP for cimbar_recv
sz3 8c23f60
Reorder various things... still not working...
sz3 e1fdcc7
good lord
sz3 8069560
The test was wrong :scream:
sz3 c3f26f7
Cleanup, things are working*
sz3 97b118a
Resize the gl viewport to match the window + ...
sz3 d3dc2bd
Adding a background grid cimbarjs to (maybe) help with autofocus
sz3 8cbd4f3
Set FPS?
sz3 7f19118
Clean up headers a bit
sz3 395d9ea
Wire up FPS
sz3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
project(cimbar_recv) | ||
|
||
set (SOURCES | ||
recv.cpp | ||
) | ||
|
||
add_executable ( | ||
cimbar_recv | ||
${SOURCES} | ||
) | ||
|
||
target_link_libraries(cimbar_recv | ||
|
||
cimb_translator | ||
extractor | ||
|
||
correct_static | ||
wirehair | ||
zstd | ||
|
||
GL | ||
glfw | ||
${OPENCV_LIBS} | ||
opencv_videoio | ||
) | ||
|
||
add_custom_command( | ||
TARGET cimbar_recv POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:cimbar_recv> cimbar_recv.dbg | ||
COMMAND ${CMAKE_STRIP} -g $<TARGET_FILE:cimbar_recv> | ||
) | ||
|
||
install( | ||
TARGETS cimbar_recv | ||
DESTINATION bin | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* This code is subject to the terms of the Mozilla Public License, v.2.0. http://mozilla.org/MPL/2.0/. */ | ||
#include "cimb_translator/Config.h" | ||
#include "compression/zstd_decompressor.h" | ||
#include "encoder/Decoder.h" | ||
#include "extractor/Extractor.h" | ||
#include "fountain/fountain_decoder_sink.h" | ||
#include "gui/window_glfw.h" | ||
|
||
#include "cxxopts/cxxopts.hpp" | ||
#include "serialize/str.h" | ||
|
||
#include <GLFW/glfw3.h> | ||
#include <opencv2/videoio.hpp> | ||
|
||
#include <chrono> | ||
#include <iostream> | ||
#include <string> | ||
#include <thread> | ||
using std::string; | ||
|
||
namespace { | ||
|
||
template <typename TP> | ||
TP wait_for_frame_time(unsigned delay, const TP& start) | ||
{ | ||
unsigned millis = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start).count(); | ||
if (delay > millis) | ||
std::this_thread::sleep_for(std::chrono::milliseconds(delay-millis)); | ||
return std::chrono::high_resolution_clock::now(); | ||
} | ||
} | ||
|
||
|
||
int main(int argc, char** argv) | ||
{ | ||
cxxopts::Options options("cimbar video decoder", "Use the camera to decode data!"); | ||
|
||
unsigned colorBits = cimbar::Config::color_bits(); | ||
unsigned ecc = cimbar::Config::ecc_bytes(); | ||
unsigned defaultFps = 60; | ||
options.add_options() | ||
("i,in", "Video source.", cxxopts::value<string>()) | ||
("o,out", "Output directory (decoding).", cxxopts::value<string>()) | ||
("c,colorbits", "Color bits. [0-3]", cxxopts::value<int>()->default_value(turbo::str::str(colorBits))) | ||
("e,ecc", "ECC level", cxxopts::value<unsigned>()->default_value(turbo::str::str(ecc))) | ||
("f,fps", "Target decode FPS", cxxopts::value<unsigned>()->default_value(turbo::str::str(defaultFps))) | ||
("h,help", "Print usage") | ||
; | ||
options.show_positional_help(); | ||
options.parse_positional({"in", "out"}); | ||
options.positional_help("<in> <out>"); | ||
|
||
auto result = options.parse(argc, argv); | ||
if (result.count("help") or !result.count("in") or !result.count("out")) | ||
{ | ||
std::cout << options.help() << std::endl; | ||
return 0; | ||
} | ||
|
||
string source = result["in"].as<string>(); | ||
string outpath = result["out"].as<string>(); | ||
|
||
colorBits = std::min(3, result["colorbits"].as<int>()); | ||
ecc = result["ecc"].as<unsigned>(); | ||
unsigned fps = result["fps"].as<unsigned>(); | ||
if (fps == 0) | ||
fps = defaultFps; | ||
unsigned delay = 1000 / fps; | ||
|
||
cv::VideoCapture vc(source.c_str()); | ||
if (!vc.isOpened()) | ||
{ | ||
std::cerr << "failed to open video device :(" << std::endl; | ||
return 70; | ||
} | ||
vc.set(cv::CAP_PROP_FRAME_WIDTH, 1920); | ||
vc.set(cv::CAP_PROP_FRAME_HEIGHT, 1200); | ||
vc.set(cv::CAP_PROP_FPS, fps); | ||
|
||
// set max camera res, and use aspect ratio for window size... | ||
|
||
std::cout << fmt::format("width: {}, height {}, exposure {}", vc.get(cv::CAP_PROP_FRAME_WIDTH), vc.get(cv::CAP_PROP_FRAME_HEIGHT), vc.get(cv::CAP_PROP_EXPOSURE)) << std::endl; | ||
|
||
double ratio = vc.get(cv::CAP_PROP_FRAME_WIDTH) / vc.get(cv::CAP_PROP_FRAME_HEIGHT); | ||
int height = 600; | ||
int width = height * ratio; | ||
std::cout << "got dimensions " << width << "," << height << std::endl; | ||
|
||
cimbar::window_glfw window(width, height, "cimbar_recv"); | ||
if (!window.is_good()) | ||
{ | ||
std::cerr << "failed to create window :(" << std::endl; | ||
return 70; | ||
} | ||
window.auto_scale_to_window(); | ||
|
||
Extractor ext; | ||
Decoder dec; | ||
|
||
unsigned chunkSize = cimbar::Config::fountain_chunk_size(ecc); | ||
fountain_decoder_sink<cimbar::zstd_decompressor<std::ofstream>> sink(outpath, chunkSize); | ||
|
||
cv::Mat mat; | ||
|
||
unsigned count = 0; | ||
std::chrono::time_point start = std::chrono::high_resolution_clock::now(); | ||
while (true) | ||
{ | ||
++count; | ||
|
||
// delay, then try to read frame | ||
start = wait_for_frame_time(delay, start); | ||
if (window.should_close()) | ||
break; | ||
|
||
if (!vc.read(mat)) | ||
{ | ||
std::cerr << "failed to read from cam" << std::endl; | ||
continue; | ||
} | ||
|
||
cv::UMat img = mat.getUMat(cv::ACCESS_RW); | ||
cv::cvtColor(mat, mat, cv::COLOR_BGR2RGB); | ||
|
||
// draw some stats on mat? | ||
window.show(mat, 0); | ||
|
||
// extract | ||
bool shouldPreprocess = true; | ||
int res = ext.extract(img, img); | ||
if (!res) | ||
{ | ||
//std::cerr << "no extract " << mat.cols << "," << mat.rows << std::endl; | ||
continue; | ||
} | ||
else if (res == Extractor::NEEDS_SHARPEN) | ||
shouldPreprocess = true; | ||
|
||
// decode | ||
int bytes = dec.decode_fountain(img, sink, shouldPreprocess); | ||
if (bytes > 0) | ||
std::cerr << "got some bytes " << bytes << std::endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ground zero -- tried to get clever, wrote a bad test, convinced myself wrong logic was right... 😡