Skip to content

Commit 64c9739

Browse files
committed
Merge branch 'main' into v0.59
2 parents 1b39b5a + 87116e2 commit 64c9739

File tree

71 files changed

+2475
-999
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2475
-999
lines changed

.clang-format

Lines changed: 0 additions & 124 deletions
This file was deleted.

Common/Cpp/LifetimeSanitizer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace PokemonAutomation{
2626
const std::set<std::string> SANITIZER_FILTER = {
2727
// "MultiSwitchProgramSession",
2828
// "MultiSwitchProgramWidget2",
29+
// "VideoSource",
2930
};
3031

3132
SpinLock sanitizer_lock;

Common/Cpp/Options/EnumDropdownOption.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ class IntegerEnumDropdownOption : private IntegerEnumDropdownDatabase, public In
119119
, IntegerEnumDropdownCell(database, lock_while_running, default_value)
120120
, m_label(std::move(label))
121121
{}
122+
// you can construct IntegerEnumDropdownDatabase using initializer list:
123+
// {
124+
// {0, "<slug_0>", "Display Name 0"},
125+
// {1, "<slug 1>", "Display Name 1"},
126+
// {2, "<slug 2>", "Display Name 2"},
127+
// }
122128
IntegerEnumDropdownOption(
123129
std::string label,
124130
IntegerEnumDropdownDatabase&& database,

Common/Qt/Redispatch.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@ void queue_on_main_thread(std::function<void()> lambda){
2222

2323

2424
void run_on_main_thread_and_wait(std::function<void()> lambda){
25-
if (QCoreApplication::instance()->thread() == QThread::currentThread()){
25+
run_on_object_thread_and_wait(QCoreApplication::instance(), std::move(lambda));
26+
}
27+
28+
void run_on_object_thread_and_wait(QObject* object, std::function<void()> lambda){
29+
if (object->thread() == QThread::currentThread()){
2630
lambda();
2731
return;
2832
}
2933

3034
std::mutex lock;
3135
std::condition_variable cv;
3236
bool done = false;
33-
QMetaObject::invokeMethod(QCoreApplication::instance(), [&]{
37+
QMetaObject::invokeMethod(object, [&]{
3438
lambda();
3539
std::lock_guard<std::mutex> lg(lock);
3640
done = true;
@@ -42,4 +46,5 @@ void run_on_main_thread_and_wait(std::function<void()> lambda){
4246

4347

4448

49+
4550
}

Common/Qt/Redispatch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include <functional>
1111

12+
class QObject;
13+
1214
namespace PokemonAutomation{
1315

1416

@@ -18,6 +20,7 @@ void queue_on_main_thread(std::function<void()> lambda);
1820

1921

2022
void run_on_main_thread_and_wait(std::function<void()> lambda);
23+
void run_on_object_thread_and_wait(QObject* object, std::function<void()> lambda);
2124

2225

2326

SerialPrograms/CMakeLists.txt

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,6 @@ else() # macOS and Linux
352352
target_link_directories(SerialProgramsLib PUBLIC ${ONNXRUNTIME_LIBRARY_DIRS})
353353
target_link_libraries(SerialProgramsLib PUBLIC ${ONNXRUNTIME_LINK_LIBRARIES})
354354
endif()
355-
# Find OpenCV
356-
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(ARM64)")
357-
find_package(OpenCV REQUIRED HINTS "/opt/homebrew/opt/opencv/lib/cmake/opencv4/")
358-
else()
359-
find_package(OpenCV REQUIRED HINTS "/usr/local/opt/opencv/lib/cmake/opencv4/")
360-
endif()
361355
else() # Linux
362356
# ONNX RUNTIME LINUX CONFIG
363357
# NOTE: users can specify their own ONNX_ROOT_PATH (this is the base folder for ONNX) on the command line when evoking cmake.
@@ -435,26 +429,26 @@ else() # macOS and Linux
435429
else()
436430
message(FATAL_ERROR "Could not find ONNX Runtime headers or library.")
437431
endif()
438-
# Find OpenCV
439-
find_package(OpenCV REQUIRED HINTS "/usr/local/opt/opencv/lib/cmake/opencv4/")
440432
endif() # end Linux
441433

442-
include_directories(${OpenCV_INCLUDE_DIRS})
443-
link_directories(${OpenCV_LIBRARY_DIRS})
444-
target_link_libraries(SerialProgramsLib PRIVATE ${OpenCV_LIBS})
434+
# Find OpenCV
435+
pkg_search_module(OpenCV REQUIRED opencv4 opencv)
436+
target_include_directories(SerialProgramsLib SYSTEM PRIVATE ${OpenCV_INCLUDE_DIRS}) # "SYSTEM" to suppress warnings
437+
target_link_directories(SerialProgramsLib PUBLIC ${OpenCV_LIBRARY_DIRS})
438+
target_link_libraries(SerialProgramsLib PUBLIC ${OpenCV_LINK_LIBRARIES})
445439

446440
#we hope to use our own Tesseract build in future so we can rid that dependency
447441
#but right now to run on Linux and Mac we need to use external Tesseract library
448-
if (UNIX_LINK_TESSERACT)
442+
pkg_search_module(TESSERACT tesseract)
443+
pkg_search_module(LEPTONICA lept)
444+
if (TESSERACT_FOUND AND LEPTONICA_FOUND)
449445
target_compile_definitions(SerialProgramsLib PRIVATE PA_TESSERACT UNIX_LINK_TESSERACT)
450-
pkg_search_module(TESSERACT REQUIRED tesseract)
451-
pkg_search_module(LEPTONICA REQUIRED lept)
452-
include_directories(${TESSERACT_INCLUDE_DIRS})
453-
include_directories(${LEPTONICA_INCLUDE_DIRS})
454-
link_directories(${TESSERACT_LIBRARY_DIRS})
455-
link_directories(${LEPTONICA_LIBRARY_DIRS})
456-
target_link_libraries(SerialProgramsLib PRIVATE ${TESSERACT_LINK_LIBRARIES})
457-
target_link_libraries(SerialProgramsLib PRIVATE ${LEPTONICA_LINK_LIBRARIES})
446+
target_include_directories(SerialProgramsLib SYSTEM PRIVATE ${TESSERACT_INCLUDE_DIRS})
447+
target_include_directories(SerialProgramsLib SYSTEM PRIVATE ${LEPTONICA_INCLUDE_DIRS})
448+
target_link_directories(SerialProgramsLib PUBLIC ${TESSERACT_LIBRARY_DIRS})
449+
target_link_directories(SerialProgramsLib PUBLIC ${LEPTONICA_LIBRARY_DIRS})
450+
target_link_libraries(SerialProgramsLib PUBLIC ${TESSERACT_LINK_LIBRARIES})
451+
target_link_libraries(SerialProgramsLib PUBLIC ${LEPTONICA_LINK_LIBRARIES})
458452
endif()
459453

460454
pkg_search_module(DPP dpp=10.0.22)
@@ -468,10 +462,6 @@ else() # macOS and Linux
468462
endif()
469463

470464
if (APPLE)
471-
# Add -Wno-c11-extensions to avoid clang gives
472-
# /usr/local/Cellar/opencv/4.5.5_3/include/opencv4/opencv2/core/mat.inl.hpp:2116:9: error: '_Atomic' is a C11 extension
473-
# when compiling OpenCV
474-
# target_compile_options(SerialProgramsLib PRIVATE -Wall -Wextra -Wpedantic -Werror -Wno-c11-extensions)
475465
target_compile_options(SerialProgramsLib PRIVATE -Wall -Wextra -Wpedantic -Werror -Wshorten-64-to-32)
476466
# on macOS, need this framework to query OS API to control display sleep and system sleep behavior
477467
target_link_libraries(SerialProgramsLib PRIVATE "-framework IOKit -framework CoreFoundation")

SerialPrograms/Scripts/check_detector_regions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@
3232

3333
raw_image = image.copy()
3434

35+
36+
# ==================================================================
37+
# LZA main menu detector
38+
add_infer_box_to_image(raw_image, 0.87, 0.940, 0.077, 0.044, image) # detect button B
39+
40+
3541
# ==================================================================
3642
# LZA fossil selection green arrow when reviving fossils
37-
add_infer_box_to_image(raw_image, 0.630, 0.444, 0.226, 0.319, image)
43+
# add_infer_box_to_image(raw_image, 0.630, 0.444, 0.226, 0.319, image)
3844

3945

4046
# ==================================================================

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace PokemonAutomation{
2626
const bool IS_BETA_VERSION = false;
2727
const int PROGRAM_VERSION_MAJOR = 0;
2828
const int PROGRAM_VERSION_MINOR = 59;
29-
const int PROGRAM_VERSION_PATCH = 5;
29+
const int PROGRAM_VERSION_PATCH = 6;
3030

3131
const std::string PROGRAM_VERSION_BASE =
3232
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +

SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.5.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//#include "Common/Cpp/Exceptions.h"
2020
//#include "Common/Cpp/Time.h"
2121
//#include "Common/Cpp/PrettyPrint.h"
22+
#include "Common/Qt/Redispatch.h"
2223
#include "VideoFrameQt.h"
2324
#include "MediaServicesQt6.h"
2425
#include "CameraWidgetQt6.5.h"
@@ -82,9 +83,11 @@ CameraVideoSource::~CameraVideoSource(){
8283
m_logger.log("Stopping Camera...");
8384
}catch (...){}
8485

85-
// m_camera->stop();
86-
m_capture_session.reset();
87-
m_camera.reset();
86+
run_on_main_thread_and_wait([&]{
87+
// m_camera->stop();
88+
m_capture_session.reset();
89+
m_camera.reset();
90+
});
8891
}
8992
CameraVideoSource::CameraVideoSource(
9093
Logger& logger,
@@ -103,6 +106,13 @@ CameraVideoSource::CameraVideoSource(
103106
}
104107
m_logger.log("Starting Camera: Backend = CameraQt65QMediaCaptureSession");
105108

109+
run_on_main_thread_and_wait([&]{
110+
init(info, desired_resolution);
111+
});
112+
}
113+
void CameraVideoSource::init(const CameraInfo& info, Resolution desired_resolution){
114+
m_metaobject.reset(new QObject());
115+
106116
auto cameras = QMediaDevices::videoInputs();
107117
const QCameraDevice* device = nullptr;
108118
for (const auto& camera : cameras){
@@ -164,7 +174,6 @@ CameraVideoSource::CameraVideoSource(
164174

165175
m_camera->start();
166176
#endif
167-
168177
}
169178

170179

@@ -177,7 +186,7 @@ void CameraVideoSource::set_video_output(QGraphicsVideoItem& item){
177186
}
178187
m_capture_session->setVideoOutput(&item);
179188

180-
connect(
189+
m_metaobject->connect(
181190
item.videoSink(), &QVideoSink::videoFrameChanged,
182191
&m_camera->camera(), [&](const QVideoFrame& frame){
183192
// This runs on the QCamera's thread. So it is off the critical path.

SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.5.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class StaticQGraphicsView : public QGraphicsView{
9292

9393

9494

95-
class CameraVideoSource : public QObject, public VideoSource{
95+
class CameraVideoSource : public VideoSource{
9696
public:
9797
virtual ~CameraVideoSource();
9898
CameraVideoSource(
@@ -118,12 +118,15 @@ class CameraVideoSource : public QObject, public VideoSource{
118118
virtual QWidget* make_display_QtWidget(QWidget* parent) override;
119119

120120
private:
121+
void init(const CameraInfo& info, Resolution desired_resolution);
121122
void set_video_output(QGraphicsVideoItem& item);
122123

123124

124125
private:
125126
friend class CameraVideoDisplay;
126127

128+
std::unique_ptr<QObject> m_metaobject;
129+
127130
Logger& m_logger;
128131
Resolution m_resolution;
129132

0 commit comments

Comments
 (0)