mirror of
https://github.com/sipeed/MaixCDK.git
synced 2026-09-11 06:09:42 -05:00
feat: app_uvc_camera 1280x720
This commit is contained in:
9
projects/app_uvc_camera/.gitignore
vendored
Normal file
9
projects/app_uvc_camera/.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
build
|
||||
dist
|
||||
.config.mk
|
||||
.flash.conf.json
|
||||
data
|
||||
|
||||
/CMakeLists.txt
|
||||
|
||||
12
projects/app_uvc_camera/app.yaml
Normal file
12
projects/app_uvc_camera/app.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
id: uvc_camera
|
||||
name: UVC Camera
|
||||
name[zh]: UVC相机
|
||||
version: 1.0.0
|
||||
icon: assets/uvc_camera.json
|
||||
author: Sipeed Ltd
|
||||
desc: UVC Camera APP, show pictures on your PC
|
||||
desc[zh]: UVC照相机应用,在你的电脑上显示画面
|
||||
files:
|
||||
app.yaml: app.yaml
|
||||
assets: assets
|
||||
|
||||
BIN
projects/app_uvc_camera/assets/ret.png
Normal file
BIN
projects/app_uvc_camera/assets/ret.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 548 B |
1
projects/app_uvc_camera/assets/uvc_camera.json
Normal file
1
projects/app_uvc_camera/assets/uvc_camera.json
Normal file
File diff suppressed because one or more lines are too long
9
projects/app_uvc_camera/compile/priority.conf
Normal file
9
projects/app_uvc_camera/compile/priority.conf
Normal file
@@ -0,0 +1,9 @@
|
||||
# component register priority
|
||||
# The upper components have higher priority
|
||||
# comments start with `#`
|
||||
|
||||
basic
|
||||
lvgl
|
||||
main
|
||||
uvc
|
||||
|
||||
74
projects/app_uvc_camera/main/CMakeLists.txt
Normal file
74
projects/app_uvc_camera/main/CMakeLists.txt
Normal file
@@ -0,0 +1,74 @@
|
||||
############### Add include ###################
|
||||
list(APPEND ADD_INCLUDE "include"
|
||||
)
|
||||
list(APPEND ADD_PRIVATE_INCLUDE "")
|
||||
###############################################
|
||||
|
||||
############ Add source files #################
|
||||
# list(APPEND ADD_SRCS "src/main.c"
|
||||
# "src/test.c"
|
||||
# )
|
||||
append_srcs_dir(ADD_SRCS "src") # append source file in src dir to var ADD_SRCS
|
||||
# list(REMOVE_ITEM COMPONENT_SRCS "src/test2.c")
|
||||
# FILE(GLOB_RECURSE EXTRA_SRC "src/*.c")
|
||||
# FILE(GLOB EXTRA_SRC "src/*.c")
|
||||
# list(APPEND ADD_SRCS ${EXTRA_SRC})
|
||||
# aux_source_directory(src ADD_SRCS) # collect all source file in src dir, will set var ADD_SRCS
|
||||
# append_srcs_dir(ADD_SRCS "src") # append source file in src dir to var ADD_SRCS
|
||||
# list(REMOVE_ITEM COMPONENT_SRCS "src/test.c")
|
||||
# set(ADD_ASM_SRCS "src/asm.S")
|
||||
# list(APPEND ADD_SRCS ${ADD_ASM_SRCS})
|
||||
# SET_PROPERTY(SOURCE ${ADD_ASM_SRCS} PROPERTY LANGUAGE C) # set .S ASM file as C language
|
||||
# SET_SOURCE_FILES_PROPERTIES(${ADD_ASM_SRCS} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp -D BBBBB")
|
||||
###############################################
|
||||
|
||||
###### Add required/dependent components ######
|
||||
list(APPEND ADD_REQUIREMENTS basic nn vision)
|
||||
###############################################
|
||||
|
||||
###### Add link search path for requirements/libs ######
|
||||
# list(APPEND ADD_LINK_SEARCH_PATH "${CONFIG_TOOLCHAIN_PATH}/lib")
|
||||
# list(APPEND ADD_REQUIREMENTS pthread m) # add system libs, pthread and math lib for example here
|
||||
# set (OpenCV_DIR opencv/lib/cmake/opencv4)
|
||||
# find_package(OpenCV REQUIRED)
|
||||
###############################################
|
||||
|
||||
############ Add static libs ##################
|
||||
# list(APPEND ADD_STATIC_LIB "lib/libtest.a")
|
||||
###############################################
|
||||
|
||||
#### Add compile option for this component ####
|
||||
#### Just for this component, won't affect other
|
||||
#### modules, including component that depend
|
||||
#### on this component
|
||||
# list(APPEND ADD_DEFINITIONS_PRIVATE -DAAAAA=1)
|
||||
|
||||
#### Add compile option for this component
|
||||
#### and components depend on this component
|
||||
# list(APPEND ADD_DEFINITIONS -DAAAAA222=1
|
||||
# -DAAAAA333=1)
|
||||
###############################################
|
||||
|
||||
############ Add static libs ##################
|
||||
#### Update parent's variables like CMAKE_C_LINK_FLAGS
|
||||
# set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--start-group libmaix/libtest.a -ltest2 -Wl,--end-group" PARENT_SCOPE)
|
||||
###############################################
|
||||
|
||||
######### Add files need to download #########
|
||||
# list(APPEND ADD_FILE_DOWNLOADS "{
|
||||
# 'url': 'https://*****/abcde.tar.xz',
|
||||
# 'urls': [], # backup urls, if url failed, will try urls
|
||||
# 'sites': [], # download site, user can manually download file and put it into dl_path
|
||||
# 'sha256sum': '',
|
||||
# 'filename': 'abcde.tar.xz',
|
||||
# 'path': 'toolchains/xxxxx',
|
||||
# 'check_files': []
|
||||
# }"
|
||||
# )
|
||||
#
|
||||
# then extracted file in ${DL_EXTRACTED_PATH}/toolchains/xxxxx,
|
||||
# you can directly use then, for example use it in add_custom_command
|
||||
##############################################
|
||||
|
||||
# register component, DYNAMIC or SHARED flags will make component compiled to dynamic(shared) lib
|
||||
register_component()
|
||||
0
projects/app_uvc_camera/main/Kconfig
Normal file
0
projects/app_uvc_camera/main/Kconfig
Normal file
3
projects/app_uvc_camera/main/include/main.h
Normal file
3
projects/app_uvc_camera/main/include/main.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
105
projects/app_uvc_camera/main/src/main.cpp
Normal file
105
projects/app_uvc_camera/main/src/main.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#include <bits/stdc++.h>
|
||||
#include <functional>
|
||||
|
||||
using namespace std;
|
||||
using namespace chrono_literals;
|
||||
|
||||
#include "maix_basic.hpp"
|
||||
#include "maix_vision.hpp"
|
||||
#include "maix_touchscreen.hpp"
|
||||
#include "maix_uvc_stream.hpp"
|
||||
|
||||
using namespace maix;
|
||||
|
||||
#include "main.h"
|
||||
|
||||
static std::unique_ptr<camera::Camera> pCam = nullptr;
|
||||
|
||||
int my_uvc_video_fill_mjpg_buffer(void *buf, uint32_t *size) {
|
||||
static uint64_t frame_count = 0;
|
||||
static uint64_t last_ms;
|
||||
if (!pCam) return 1;
|
||||
|
||||
image::Image *img = pCam->read();
|
||||
if (!img) return 1;
|
||||
uint64_t curr_ms_takeframe = time::ticks_ms();
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << "frame[" << img->width() << "x" << img->height() << "]: " << frame_count;
|
||||
img->draw_string(4, 32, oss.str(), image::Color::from_rgb(255, 0, 0), 1.3);
|
||||
|
||||
uvc::helper_fill_mjpg_image(buf, size, img);
|
||||
uint64_t curr_ms_mjpgframe = time::ticks_ms();
|
||||
|
||||
delete img;
|
||||
#if 0
|
||||
char result_bin_name[32];
|
||||
sprintf((char *)result_bin_name, "/root/res/res_%llu.jpg", frame_count);
|
||||
ofstream((const char*)result_bin_name, std::ios::binary)
|
||||
.write(reinterpret_cast<char*>(buf), *size);
|
||||
#endif
|
||||
|
||||
uint64_t curr_ms = time::ticks_ms();
|
||||
static uint32_t flip = 1;
|
||||
if(flip^=1) log::info("[%llu]loop use %lld ms, %.2ffps, %d bytes\r\n"
|
||||
"\ttake: %lld ms\r\n"
|
||||
"\tto_mjpg: %lld ms\r\n", frame_count++, curr_ms - last_ms, 1000.f/(curr_ms - last_ms), *size,
|
||||
curr_ms_takeframe - last_ms, curr_ms_mjpgframe - curr_ms_takeframe);
|
||||
last_ms = curr_ms;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _main(int argc, char *argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
log::info("Program start");
|
||||
|
||||
|
||||
image::Image *ret_img = image::load("./assets/ret.png", image::Format::FMT_RGB888);
|
||||
if (!ret_img)
|
||||
{
|
||||
log::error("load ret image failed");
|
||||
return -12345;
|
||||
}
|
||||
display::Display disp = display::Display();
|
||||
image::Image img(disp.width(), disp.height());
|
||||
img.draw_image(0, 0, *ret_img);
|
||||
disp.show(img);
|
||||
|
||||
log::info("open camera now");
|
||||
camera::Camera cam = camera::Camera(1280, 720, image::Format::FMT_RGB888, "", 60, 3);
|
||||
if(!pCam) pCam = make_unique<camera::Camera>(std::move(cam));
|
||||
log::info("open camera success");
|
||||
|
||||
touchscreen::TouchScreen ts;
|
||||
int ts_x = 0, ts_y = 0;
|
||||
bool ts_pressed = false;
|
||||
|
||||
std::unique_ptr<uvc::UvcServer> pUvc = std::make_unique<uvc::UvcServer>(my_uvc_video_fill_mjpg_buffer);
|
||||
pUvc->run();
|
||||
img.draw_string(100, disp.height()/2, std::string("UVC started."), image::Color::from_rgb(0, 255, 0), 1.3);
|
||||
disp.show(img);
|
||||
while (!app::need_exit())
|
||||
{
|
||||
std::this_thread::sleep_for(300ms);
|
||||
ts.read(ts_x, ts_y, ts_pressed);
|
||||
if (ts_pressed && ts_x < 40 + 60 && ts_y < 40)
|
||||
break;
|
||||
}
|
||||
pUvc->stop();
|
||||
|
||||
log::info("Program exit");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Catch signal and process
|
||||
sys::register_default_signal_handle();
|
||||
|
||||
// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
|
||||
// if we don't catch exception, when program throw exception, the objects will not be destructed.
|
||||
// So we catch exception here to let resources be released(call objects' destructor) before exit.
|
||||
CATCH_EXCEPTION_RUN_RETURN(_main, -1, argc, argv);
|
||||
}
|
||||
Reference in New Issue
Block a user