mirror of
https://github.com/nihui/opencv-mobile.git
synced 2025-09-26 20:41:56 +08:00
hw jpg encoder for orion o6 (#189)
This commit is contained in:
5
.github/workflows/release.yml
vendored
5
.github/workflows/release.yml
vendored
@@ -76,6 +76,7 @@ jobs:
|
||||
rm -rf modules/ts
|
||||
sed -e 's/__VERSION__/${{ env.opencv-version }}/g' ../patches/Info.plist > ./Info.plist
|
||||
cp ../opencv2_cmake_options.txt ./options.txt
|
||||
cp -r ../toolchains .
|
||||
cd ..
|
||||
mv opencv-${{ env.opencv-version }} opencv-mobile-${{ env.opencv-version }}
|
||||
zip -9 -r opencv-mobile-${{ env.opencv-version }}.zip opencv-mobile-${{ env.opencv-version }}
|
||||
@@ -153,6 +154,7 @@ jobs:
|
||||
rm -rf modules/dnn
|
||||
sed -e 's/__VERSION__/${{ env.opencv-version }}/g' ../patches/Info.plist > ./Info.plist
|
||||
cp ../opencv3_cmake_options.txt ./options.txt
|
||||
cp -r ../toolchains .
|
||||
cd ..
|
||||
mv opencv-${{ env.opencv-version }} opencv-mobile-${{ env.opencv-version }}
|
||||
zip -9 -r opencv-mobile-${{ env.opencv-version }}.zip opencv-mobile-${{ env.opencv-version }}
|
||||
@@ -228,6 +230,7 @@ jobs:
|
||||
rm -rf modules/dnn
|
||||
sed -e 's/__VERSION__/${{ env.opencv-version }}/g' ../patches/Info.plist > ./Info.plist
|
||||
cp ../opencv4_cmake_options.txt ./options.txt
|
||||
cp -r ../toolchains .
|
||||
cd ..
|
||||
mv opencv-${{ env.opencv-version }} opencv-mobile-${{ env.opencv-version }}
|
||||
zip -9 -r opencv-mobile-${{ env.opencv-version }}.zip opencv-mobile-${{ env.opencv-version }}
|
||||
@@ -1787,7 +1790,7 @@ jobs:
|
||||
echo "fine :)"
|
||||
setup-test-env-cmd: |
|
||||
echo "fine :)"
|
||||
cmake-options: -DWITH_RPI=ON
|
||||
cmake-options: -DWITH_KLEIDICV=ON -DWITH_RPI=ON -DWITH_CIX=ON
|
||||
|
||||
- name: milkv-duo
|
||||
single-core: true
|
||||
|
@@ -5,6 +5,7 @@ option(WITH_CVI "build with cvi" OFF)
|
||||
option(WITH_AW "build with aw" OFF)
|
||||
option(WITH_RK "build with rk" OFF)
|
||||
option(WITH_RPI "build with rpi" OFF)
|
||||
option(WITH_CIX "build with cix" OFF)
|
||||
|
||||
set(highgui_srcs
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/exif.cpp
|
||||
@@ -61,6 +62,13 @@ if(WITH_RPI)
|
||||
message(STATUS "highgui rpi enabled")
|
||||
endif()
|
||||
|
||||
if(WITH_CIX)
|
||||
list(APPEND highgui_srcs
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/jpeg_encoder_v4l_cix.cpp)
|
||||
add_definitions(-DCV_WITH_CIX=1)
|
||||
message(STATUS "highgui cix enabled")
|
||||
endif()
|
||||
|
||||
file(GLOB highgui_ext_hdrs
|
||||
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/*.hpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp"
|
||||
|
@@ -54,6 +54,9 @@
|
||||
#if CV_WITH_RPI
|
||||
#include "jpeg_encoder_v4l_rpi.h"
|
||||
#endif
|
||||
#if CV_WITH_CIX
|
||||
#include "jpeg_encoder_v4l_cix.h"
|
||||
#endif
|
||||
#if defined __linux__ && !__ANDROID__
|
||||
#include "display_fb.h"
|
||||
#endif
|
||||
@@ -454,6 +457,56 @@ bool imwrite(const String& filename, InputArray _img, const std::vector<int>& pa
|
||||
}
|
||||
}
|
||||
}
|
||||
// fallback to stb_image_write
|
||||
}
|
||||
#endif
|
||||
#if CV_WITH_CIX
|
||||
if (jpeg_encoder_v4l_cix::supported(img.cols, img.rows, c))
|
||||
{
|
||||
// anything to bgr
|
||||
if (!img.isContinuous())
|
||||
{
|
||||
img = img.clone();
|
||||
}
|
||||
|
||||
int quality = 95;
|
||||
for (size_t i = 0; i < params.size(); i += 2)
|
||||
{
|
||||
if (params[i] == IMWRITE_JPEG_QUALITY)
|
||||
{
|
||||
quality = params[i + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// cache jpeg_encoder_v4l_cix context
|
||||
static int old_w = 0;
|
||||
static int old_h = 0;
|
||||
static int old_ch = 0;
|
||||
static int old_quality = 0;
|
||||
static jpeg_encoder_v4l_cix e;
|
||||
if (img.cols == old_w && img.rows == old_h && c == old_ch && quality == old_quality)
|
||||
{
|
||||
int ret = e.encode(img.data, filename.c_str());
|
||||
if (ret == 0)
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int ret = e.init(img.cols, img.rows, c, quality);
|
||||
if (ret == 0)
|
||||
{
|
||||
ret = e.encode(img.data, filename.c_str());
|
||||
if (ret == 0)
|
||||
{
|
||||
old_w = img.cols;
|
||||
old_h = img.rows;
|
||||
old_ch = c;
|
||||
old_quality = quality;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to stb_image_write
|
||||
}
|
||||
@@ -808,6 +861,39 @@ bool imencode(const String& ext, InputArray _img, std::vector<uchar>& buf, const
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// fallback to stb_image_write
|
||||
}
|
||||
#endif
|
||||
#if CV_WITH_CIX
|
||||
if (jpeg_encoder_v4l_cix::supported(img.cols, img.rows, c))
|
||||
{
|
||||
// anything to bgr
|
||||
if (!img.isContinuous())
|
||||
{
|
||||
img = img.clone();
|
||||
}
|
||||
|
||||
int quality = 95;
|
||||
for (size_t i = 0; i < params.size(); i += 2)
|
||||
{
|
||||
if (params[i] == IMWRITE_JPEG_QUALITY)
|
||||
{
|
||||
quality = params[i + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
jpeg_encoder_v4l_cix e;
|
||||
int ret = e.init(img.cols, img.rows, c, quality);
|
||||
if (ret == 0)
|
||||
{
|
||||
ret = e.encode(img.data, buf);
|
||||
if (ret == 0)
|
||||
{
|
||||
e.deinit();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to stb_image_write
|
||||
}
|
||||
|
1230
highgui/src/jpeg_encoder_v4l_cix.cpp
Normal file
1230
highgui/src/jpeg_encoder_v4l_cix.cpp
Normal file
File diff suppressed because it is too large
Load Diff
47
highgui/src/jpeg_encoder_v4l_cix.h
Normal file
47
highgui/src/jpeg_encoder_v4l_cix.h
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Copyright (C) 2025 nihui
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#ifndef JPEG_ENCODER_V4L_CIX_H
|
||||
#define JPEG_ENCODER_V4L_CIX_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace cv {
|
||||
|
||||
class jpeg_encoder_v4l_cix_impl;
|
||||
class jpeg_encoder_v4l_cix
|
||||
{
|
||||
public:
|
||||
static bool supported(int width, int height, int ch);
|
||||
|
||||
jpeg_encoder_v4l_cix();
|
||||
~jpeg_encoder_v4l_cix();
|
||||
|
||||
int init(int width, int height, int ch, int quality);
|
||||
|
||||
int encode(const unsigned char* bgrdata, std::vector<unsigned char>& outdata) const;
|
||||
|
||||
int encode(const unsigned char* bgrdata, const char* outfilepath) const;
|
||||
|
||||
int deinit();
|
||||
|
||||
private:
|
||||
jpeg_encoder_v4l_cix_impl* const d;
|
||||
};
|
||||
|
||||
} // namespace cv
|
||||
|
||||
#endif // JPEG_ENCODER_V4L_CIX_H
|
Reference in New Issue
Block a user