Skip to content

Commit

Permalink
Develop (#36)
Browse files Browse the repository at this point in the history
* do not compile qtmultimedia from source (#34)

* Android open cv (#35)

* Use the latest release of openCV action and work also for android

* Only look for core and objdetect components of openCV

* Added request permission for a camera

* Ask for permission and look for a backcamera

* Choose the lowest resolution format

* Use threads for decoding

* Set public USE_EMSCRIPTEN

* added flash for Android
  • Loading branch information
EddyTheCo authored Sep 27, 2023
1 parent 5166d23 commit 17847ea
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 268 deletions.
2 changes: 1 addition & 1 deletion Config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick Svg OPTIONAL_COMPONENTS Multimedia )
find_dependency(OpenCV QUIET )
find_dependency(OpenCV REQUIRED COMPONENTS core objdetect )
include ( "${CMAKE_CURRENT_LIST_DIR}/qrCodeTargets.cmake" )
100 changes: 51 additions & 49 deletions QrDec/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
find_package(OpenCV)
if(NOT OpenCV_FOUND AND NOT ANDROID)
set(builturl "https://github.com/EddyTheCo/install-OpenCV-action/releases/download/v0.0.14/OpenCV-ubuntu-latest-wasm_false.tar")
if(WIN32)
set(builturl "https://github.com/EddyTheCo/install-OpenCV-action/releases/download/v0.0.14/OpenCV-windows-latest-wasm_false.tar")
endif(WIN32)
if (APPLE)
set(builturl "https://github.com/EddyTheCo/install-OpenCV-action/releases/download/v0.0.14/OpenCV-macos-latest-wasm_false.tar")
endif(APPLE)
if(EMSCRIPTEN)
set(builturl "https://github.com/EddyTheCo/install-OpenCV-action/releases/download/v0.0.14/OpenCV-ubuntu-latest-wasm_true.tar")
endif(EMSCRIPTEN)
FetchContent_Declare(
OpenCV
DOWNLOAD_EXTRACT_TIMESTAMP true
URL ${builturl}
)
FetchContent_GetProperties(OpenCV)
if(NOT OpenCV_POPULATED)
message(STATUS "OpenCV prebuilt will be downloaded from ${builturl} if not found on the system")
FetchContent_Populate(OpenCV)
message(STATUS "OpenCV is installed in ${opencv_SOURCE_DIR}")
set(OpenCV_DIR ${opencv_SOURCE_DIR}/lib/cmake/opencv4)
if(WIN32)
set(OpenCV_DIR ${opencv_SOURCE_DIR})
endif(WIN32)
find_package(OpenCV)
endif()
find_package(OpenCV COMPONENTS core objdetect )
if(NOT OpenCV_FOUND )
set(builturl "https://github.com/EddyTheCo/install-OpenCV-action/releases/latest/download/OpenCV-ubuntu-latest-wasm_false-android_none.tar")
if(WIN32)
set(builturl "https://github.com/EddyTheCo/install-OpenCV-action/releases/latest/download/OpenCV-windows-latest-wasm_false-android_none.tar")
endif(WIN32)
if (APPLE)
set(builturl "https://github.com/EddyTheCo/install-OpenCV-action/releases/latest/download/OpenCV-macos-latest-wasm_false-android_none.tar")
endif(APPLE)
if(EMSCRIPTEN)
set(builturl "https://github.com/EddyTheCo/install-OpenCV-action/releases/latest/download/OpenCV-ubuntu-latest-wasm_true-android_none.tar")
endif(EMSCRIPTEN)
if(ANDROID)
set(builturl "https://github.com/EddyTheCo/install-OpenCV-action/releases/latest/download/OpenCV-ubuntu-latest-wasm_false-android_${ANDROID_ABI}.tar")
endif(ANDROID)
FetchContent_Declare(
OpenCV
DOWNLOAD_EXTRACT_TIMESTAMP true
URL ${builturl}
)
FetchContent_GetProperties(OpenCV)
if(NOT OpenCV_POPULATED)
message(STATUS "OpenCV prebuilt will be downloaded from ${builturl} if not found on the system")
FetchContent_Populate(OpenCV)
message(STATUS "OpenCV is installed in ${opencv_SOURCE_DIR}")
set(OpenCV_DIR ${opencv_SOURCE_DIR}/lib/cmake/opencv4)
if(WIN32)
set(OpenCV_DIR ${opencv_SOURCE_DIR})
endif(WIN32)
if(ANDROID)
set(OpenCV_DIR ${opencv_SOURCE_DIR}/sdk/native/jni)
endif(ANDROID)
find_package(OpenCV COMPONENTS core objdetect)
endif()
endif()



if(OpenCV_FOUND)

add_library(QrDec qrcodedec.cpp)

set_target_properties(QrDec PROPERTIES POSITION_INDEPENDENT_CODE ON)

target_include_directories(QrDec PRIVATE ${OpenCV_INCLUDE_DIRS})
target_link_libraries(QrDec PRIVATE ${OpenCV_LIBS})

target_include_directories(QrDec PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/qrCode>")

install(TARGETS QrDec
EXPORT qrCodeTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Qr
)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qrCode
COMPONENT Qr
)
add_library(QrDec qrcodedec.cpp)

target_include_directories(QrDec PUBLIC $<BUILD_INTERFACE:${OpenCV_INCLUDE_DIRS}>)
target_link_libraries(QrDec PUBLIC ${OpenCV_LIBS})

target_include_directories(QrDec PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/qrCode>")
install(TARGETS QrDec
EXPORT qrCodeTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Qr
)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qrCode
COMPONENT Qr
)
else()
message(STATUS "OpenCV was not found")
message(STATUS "OpenCV was not found")
endif(OpenCV_FOUND)
14 changes: 8 additions & 6 deletions QrDec/include/qrcodedec.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#pragma once
#include<iostream>
#include<opencv2/opencv.hpp>
#include <opencv2/objdetect.hpp>
#include<string>
#include<vector>

namespace qrcodedec {
class QRDecoder : public cv::QRCodeDetector
{

std::string decode_grey(unsigned char* img, int rows,int cols);
public:
QRDecoder(){};
std::string decode_grey(unsigned char* img, int rows,int cols);
};


}
24 changes: 6 additions & 18 deletions QrDec/qrcodedec.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
#include<qrcodedec.hpp>
#include<opencv2/opencv.hpp>

namespace qrcodedec {
using namespace std;
using namespace cv;
string decode_grey(unsigned char* img,int rows ,int cols)
{
Mat greyImg = Mat(rows,cols, CV_8UC1, img);
QRCodeDetector* decoder = new QRCodeDetector();
auto str=decoder->detectAndDecode(greyImg);
delete decoder;
return str;
}
std::string QRDecoder::decode_grey(unsigned char* img,int rows ,int cols)
{
cv::Mat greyImg = cv::Mat(rows,cols, CV_8UC1, img);
return detectAndDecodeCurved(greyImg);
}



}
#ifdef USE_EMSCRIPTEN
EMSCRIPTEN_BINDINGS(qrcodedec) {
function("decode_grey", &qrcodedec::decode_grey);
}
#endif
27 changes: 6 additions & 21 deletions QtQrDec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,13 @@ find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick OPTIONAL_COMPONENTS Mult

if (Qt6_FOUND AND TARGET QrDec)
qt_standard_project_setup()
if(NOT TARGET Qt6::Multimedia AND NOT EMSCRIPTEN)
FetchContent_Declare(
qtmultimedia
GIT_REPOSITORY git://code.qt.io/qt/qtmultimedia.git
GIT_TAG 6.5.0
)
FetchContent_MakeAvailable(qtmultimedia)
endif()
list(APPEND qml_files "qml/QrTextArea.qml")
if(TARGET Qt6::Multimedia)
list(APPEND qml_files "qml/QrQmlCamera.qml")
else()
if(EMSCRIPTEN)
list(APPEND qml_files "qml/wasm/QrQmlCamera.qml")
endif()
endif()

qt6_add_qml_module(QtQrDec
URI QtQrDec
VERSION 1.0
SOURCES Qrimagedecoder.cpp include/Qrimagedecoder.hpp
QML_FILES ${qml_files}
QML_FILES
qml/QrTextArea.qml
qml/QrQmlCamera.qml
RESOURCE_PREFIX
"/esterVtech.com/imports"
OUTPUT_TARGETS out_targets_var
Expand All @@ -37,8 +22,8 @@ if (Qt6_FOUND AND TARGET QrDec)
target_include_directories(QtQrDec PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/qrCode>")

target_link_libraries(QtQrDec PUBLIC Qt6::Gui Qt6::Quick)
target_link_libraries(QtQrDec PRIVATE QrDec MyDesigns)
target_link_libraries(QtQrDec PUBLIC Qt6::Gui Qt6::Quick QrDec)
target_link_libraries(QtQrDec PRIVATE MyDesigns)

if(TARGET Qt6::Multimedia)
target_link_libraries(QtQrDec PUBLIC Qt6::Multimedia)
Expand All @@ -53,7 +38,7 @@ if (Qt6_FOUND AND TARGET QrDec)
COMPONENT QtQr
)
if(EMSCRIPTEN)
target_compile_definitions(QtQrDec PRIVATE USE_EMSCRIPTEN)
target_compile_definitions(QtQrDec PUBLIC USE_EMSCRIPTEN)
endif(EMSCRIPTEN)
endif(Qt6_FOUND AND TARGET QrDec)
list(APPEND QML_IMPORT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/qml ${CMAKE_CURRENT_BINARY_DIR})
Expand Down
Loading

0 comments on commit 17847ea

Please sign in to comment.