|
|
@@ -1,9 +1,8 @@
|
|
|
#include "uvc_camera_impl.h"
|
|
|
-#include "core/image_utility.hpp"
|
|
|
-#include "core/image_utility_v2.h"
|
|
|
#include "core/utility.hpp"
|
|
|
-#include "image_process/cuda_impl/pixel_convert.cuh"
|
|
|
#include "third_party/scope_guard.hpp"
|
|
|
+#include "image_process_v5/sp_image.h"
|
|
|
+#include "image_process_v5/image_process.h"
|
|
|
|
|
|
#include <opencv2/imgcodecs.hpp>
|
|
|
#include <opencv2/imgproc.hpp>
|
|
|
@@ -92,34 +91,23 @@ namespace uvc_camera_impl {
|
|
|
return dev_info_list;
|
|
|
}
|
|
|
|
|
|
- auto mjpeg_frame_to_image(uvc_frame_t *frame) { // TODO: accelerate with CUDA
|
|
|
+ sp_image mjpeg_frame_to_image(uvc_frame_t *frame) { // TODO: accelerate with CUDA
|
|
|
assert(frame->frame_format == UVC_FRAME_FORMAT_MJPEG);
|
|
|
auto img_data = cv::_InputArray((uchar *) frame->data, frame->data_bytes);
|
|
|
auto img_bgr = cv::imdecode(img_data, cv::IMREAD_UNCHANGED);
|
|
|
- if (img_bgr.empty()) return image_u8c3(); // TODO: ugly hacked, find out why
|
|
|
- auto img_rgb_info = create_image_info<uchar3>(img_bgr.size(), MEM_HOST);
|
|
|
- cv::cvtColor(img_bgr, img_rgb_info.as_mat(), cv::COLOR_BGR2RGB);
|
|
|
- return create_image(img_rgb_info);
|
|
|
+ if (img_bgr.empty()) return {};
|
|
|
+ const auto img_rgb = sp_image::create(CV_8UC3, img_bgr.size());
|
|
|
+ const auto helper = write_access_helper(img_rgb.host());
|
|
|
+ auto img_rgb_mat = img_rgb.cv_mat(helper.ptr());
|
|
|
+ cv::cvtColor(img_bgr, img_rgb_mat, cv::COLOR_BGR2RGB);
|
|
|
+ return img_rgb;
|
|
|
}
|
|
|
|
|
|
- image_ptr yuyv_frame_to_image(uvc_frame_t *frame) {
|
|
|
+ sp_image yuyv_frame_to_image(uvc_frame_t *frame) {
|
|
|
assert(frame->frame_format == UVC_FRAME_FORMAT_YUYV);
|
|
|
auto img_size = cv::Size(frame->width, frame->height);
|
|
|
- auto img_yuyv = create_image(img_size, CV_8UC2);
|
|
|
- if (img_yuyv->size_in_bytes() != frame->data_bytes) return nullptr;
|
|
|
- auto yuyv_mem = img_yuyv->memory(MEM_HOST);
|
|
|
- memcpy(yuyv_mem.start_ptr(), frame->data, frame->data_bytes);
|
|
|
- return img_yuyv;
|
|
|
- }
|
|
|
-
|
|
|
- image_u8c3 image_yuyv_to_rgb(const image_ptr &img_yuyv,
|
|
|
- smart_cuda_stream *stream) {
|
|
|
- auto img_rgb = create_image(img_yuyv->size(), CV_8UC3);
|
|
|
- call_yuyv_to_rgb(img_yuyv->cuda<uchar2>(stream),
|
|
|
- img_rgb->cuda<uchar3>(stream),
|
|
|
- stream->cuda);
|
|
|
- img_rgb->cuda_modified(stream);
|
|
|
- return img_rgb->v1<uchar3>();
|
|
|
+ if (img_size.area() * sizeof(uchar2) != frame->data_bytes) return {};
|
|
|
+ return sp_image::create<uchar2>(img_size, frame->data);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -178,10 +166,11 @@ void uvc_camera::impl::frame_callback(uvc_frame *frame) {
|
|
|
break;
|
|
|
}
|
|
|
case UVC_FRAME_FORMAT_YUYV: {
|
|
|
- auto img_yuv = yuyv_frame_to_image(frame);
|
|
|
- if (img_yuv == nullptr) break;
|
|
|
+ auto img_yuyv = yuyv_frame_to_image(frame);
|
|
|
+ if (img_yuyv.empty()) break;
|
|
|
boost::asio::post(*conf.ctx, [=, this] { // handle CUDA context problem
|
|
|
- auto img_rgb = image_yuyv_to_rgb(img_yuv, conf.stream);
|
|
|
+ // TODO: check why CUDA commands cannot be used in this thread
|
|
|
+ auto img_rgb = image_yuyv_to_rgb(img_yuyv);
|
|
|
OBJ_SAVE(img_name, img_rgb);
|
|
|
});
|
|
|
break;
|
|
|
@@ -190,7 +179,6 @@ void uvc_camera::impl::frame_callback(uvc_frame *frame) {
|
|
|
RET_ERROR;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
void uvc_camera::impl::start(start_config conf) {
|