#include <QImage>
#include <QLoggingCategory>
+#include <QMetaObject>
+#include <QtConcurrent>
-Q_LOGGING_CATEGORY(annotationsCategory, "Annotations")
-Q_LOGGING_CATEGORY(annotationsStatsCategory, "Annotations.stats")
-Q_LOGGING_CATEGORY(annotationsVerboseCategory, "Annotations.verbose")
+#include <stdexcept>
#include <dlib/dnn.h>
#include <dlib/image_saver/image_saver.h>
-#include <QMetaObject>
-#include <QtConcurrent>
-
// random windows.h defines
#undef interface
+Q_LOGGING_CATEGORY(annotationsCategory, "Annotations")
+Q_LOGGING_CATEGORY(annotationsStatsCategory, "Annotations.stats")
+Q_LOGGING_CATEGORY(annotationsVerboseCategory, "Annotations.verbose")
+
using namespace std;
using namespace dlib;
rcon5_r<rcon5_r<rcon5_r<downsampler_r<
input_rgb_image_pyramid<pyramid_down<6>>>>>>>>;
-namespace {
-detection_net_type net;
-bool valid = false;
-} // namespace
+struct FeatureAnnoationsInstance::Private
+{
+ detection_net_type net;
+};
FeatureAnnoations::FeatureAnnoations(QObject *parent) : QObject{parent} {
- try {
- deserialize("C:/_C/anime_face_recognition/mmod_network.dat") >> net;
- valid = true;
- } catch (const std::exception &ex) {
- qCWarning(annotationsCategory)
- << "Failed to read neural network. Error:" << ex.what();
- }
}
FeaturePluginInstance *
FeatureAnnoations::createInstance(QObject *instance,
PlayerFeaturePluginInterface *interface) {
- if (!valid)
- throw std::exception{"Network failed to initialize"};
return new FeatureAnnoationsInstance(instance, interface);
}
FeatureAnnoationsInstance::FeatureAnnoationsInstance(
QObject *instance, PlayerFeaturePluginInterface *player, QObject *)
- : FeaturePluginInstance{instance, player} {
+ : FeaturePluginInstance{instance, player},
+ m_private{std::make_unique<Private>()} {
+ try {
+ deserialize("/mnt/windows/_C/anime_face_recognition/"
+ "mmod_network-1000-labeled-adjusted.dat") >>
+ m_private->net;
+ } catch (const std::exception &ex) {
+ qCWarning(annotationsCategory)
+ << "Failed to read neural network. Error:" << ex.what();
+ throw;
+ }
qCDebug(annotationsCategory) << "Registering with instance" << instance;
connect(&m_watcher, SIGNAL(finished()), this, SLOT(onResultReady()));
toggleAnnotations();
}
+FeatureAnnoationsInstance::~FeatureAnnoationsInstance() = default;
-QList<FeaturePluginInstance::Action> FeatureAnnoationsInstance::featurePluginActions() const
-{
- return {Action{"Enable annotations", "P", SLOT()}};
+QList<FeaturePluginInstance::Action>
+FeatureAnnoationsInstance::featurePluginActions() const {
+ return {Action{"Enable annotations", "P", SLOT()}};
}
void FeatureAnnoationsInstance::onFrameChanged(const QImage &image) {
qCDebug(annotationsVerboseCategory) << "Starting annotation detection...";
+ auto &prv = *m_private;
auto future = QtConcurrent::run(
- [](QImage image) -> PlayerFeaturePluginInterface::AnnotationList {
+ [&prv](QImage image) -> PlayerFeaturePluginInterface::AnnotationList {
try {
const int maxHeight{600};
if (image.size().height() > maxHeight)
// dlib::save_bmp(img, "testimage.bmp");
- auto dets = net(img);
+ auto dets = prv.net(img);
PlayerFeaturePluginInterface::AnnotationList al;
for (auto &&d : dets)
al << PlayerFeaturePluginInterface::Annotation{
class FeatureAnnoationsInstance : public QObject, public FeaturePluginInstance {
Q_OBJECT
public:
- FeatureAnnoationsInstance(QObject *instance, PlayerFeaturePluginInterface *, QObject *parent = nullptr);
+ FeatureAnnoationsInstance(QObject *instance, PlayerFeaturePluginInterface *,
+ QObject *parent = nullptr);
+ ~FeatureAnnoationsInstance() override;
// FeaturePluginInstance interface
QList<Action> featurePluginActions() const override;
void toggleAnnotations();
bool m_enabled = false;
+ struct Private;
+ std::unique_ptr<Private> m_private;
QTimer m_fpsTimer;
int m_fpsCounter = 0;
QFutureWatcher<PlayerFeaturePluginInterface::AnnotationList> m_watcher;