Skip to content

Commit

Permalink
Change file and class variable names to be more C++ style
Browse files Browse the repository at this point in the history
Change-Id: I1006aaa39e84a896eb41e7c09e5947869995a427
Signed-off-by: Joakim Roubert <[email protected]>
  • Loading branch information
joakimr-axis committed Feb 18, 2025
1 parent 484b25d commit fcc951f
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 235 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [2023] [Axis Communications AB]
Copyright [2025] [Axis Communications AB]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*Copyright (C) 2023, Axis Communications AB, Lund, Sweden. All Rights Reserved.*
*Copyright (C) 2025, Axis Communications AB, Lund, Sweden. All Rights Reserved.*

# OPC UA Color Checker ACAP

Expand Down
20 changes: 10 additions & 10 deletions include/colorarea.hpp → include/ColorArea.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2023, Axis Communications AB, Lund, Sweden
* Copyright (C) 2025, Axis Communications AB, Lund, Sweden
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,15 +41,15 @@ class ColorArea
cv::Scalar GetAverageColor(const cv::Mat &img) const;

protected:
cv::Mat colorarea_mask;
cv::Point point_center;
cv::Range croprange_x;
cv::Range croprange_y;
cv::Scalar color;
cv::Size img_size;
uint32_t markerwidth;
uint32_t markerheight;
uint8_t tolerance;
cv::Mat colorarea_mask_;
cv::Point point_center_;
cv::Range croprange_x_;
cv::Range croprange_y_;
cv::Scalar color_;
cv::Size img_size_;
uint32_t markerwidth_;
uint32_t markerheight_;
uint8_t tolerance_;
};

class ColorAreaEllipse : public ColorArea
Expand Down
14 changes: 7 additions & 7 deletions include/evhandler.hpp → include/EventHandler.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2023, Axis Communications AB, Lund, Sweden
* Copyright (C) 2025, Axis Communications AB, Lund, Sweden
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,15 +23,15 @@
#include <axevent.h>
#include <string>

class AxEventHandler
class EventHandler
{
public:
AxEventHandler();
~AxEventHandler();
EventHandler();
~EventHandler();
void Send(const gboolean active) const;

private:
AXEventHandler *evhandler;
bool initialized;
guint eventid;
AXEventHandler *event_handler_;
bool initialized_;
guint event_id_;
};
56 changes: 29 additions & 27 deletions include/imgprovider.hpp → include/ImageProvider.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2023, Axis Communications AB, Lund, Sweden
* Copyright (C) 2025, Axis Communications AB, Lund, Sweden
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,8 +24,10 @@
#include <pthread.h>
#include <stdbool.h>

#include "vdo-stream.h"
#include "vdo-types.h"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <vdo-stream.h>
#include <vdo-types.h>
#pragma GCC diagnostic pop

#define _Atomic(X) std::atomic<X>
#define NUM_VDO_BUFFERS (8)
Expand All @@ -37,46 +39,46 @@
* VDO types to setup and maintain a stream, as well as parameters to make
* the streaming thread safe.
*/
class ImgProvider
class ImageProvider
{
public:
ImgProvider(const unsigned int w, const unsigned int h, const unsigned int numFrames, const VdoFormat format);
~ImgProvider();
bool InitImgProvider();
ImageProvider(const unsigned int w, const unsigned int h, const unsigned int numFrames, const VdoFormat format);
~ImageProvider();
bool InitImageProvider();
static bool ChooseStreamResolution(
const unsigned int reqWidth,
const unsigned int reqHeight,
unsigned int &chosenWidth,
unsigned int &chosenHeight);
static bool CreateStream(ImgProvider &provider);
static bool AllocateVdoBuffers(ImgProvider &provider, VdoStream &vdoStream);
static void ReleaseVdoBuffers(ImgProvider &provider);
static VdoBuffer *GetLastFrameBlocking(ImgProvider &provider);
static void ReturnFrame(ImgProvider &provider, VdoBuffer &buffer);
static bool CreateStream(ImageProvider &provider);
static bool AllocateVdoBuffers(ImageProvider &provider, VdoStream &vdoStream);
static void ReleaseVdoBuffers(ImageProvider &provider);
static VdoBuffer *GetLastFrameBlocking(ImageProvider &provider);
static void ReturnFrame(ImageProvider &provider, VdoBuffer &buffer);
static void *threadEntry(void *data);
static bool StartFrameFetch(ImgProvider &provider);
static bool StopFrameFetch(ImgProvider &provider);
static bool StartFrameFetch(ImageProvider &provider);
static bool StopFrameFetch(ImageProvider &provider);

/// Keeping track of frames' statuses.
GQueue *delivered_frames;
GQueue *processed_frames;
GQueue *delivered_frames_;
GQueue *processed_frames_;

/// To support fetching frames asynchonously with VDO.
pthread_mutex_t frame_mutex;
pthread_cond_t frame_deliver_cond;
pthread_t fetcher_thread;
std::atomic_bool shutdown;
pthread_mutex_t frame_mutex_;
pthread_cond_t frame_deliver_cond_;
pthread_t fetcher_thread_;
std::atomic_bool shutdown_;

private:
void RunLoopIteration();
bool initialized;
unsigned int width;
unsigned int height;
bool initialized_;
unsigned int width_;
unsigned int height_;
/// Number of frames to keep in the delivered_frames queue.
unsigned int num_app_frames;
unsigned int num_app_frames_;
// Stream configuration parameters.
VdoFormat vdo_format;
VdoFormat vdo_format_;
// Vdo stream and buffers handling.
VdoStream *vdo_stream;
VdoBuffer *vdo_buffers[NUM_VDO_BUFFERS];
VdoStream *vdo_stream_;
VdoBuffer *vdo_buffers_[NUM_VDO_BUFFERS];
};
10 changes: 5 additions & 5 deletions include/opcuaserver.hpp → include/OpcUaServer.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2023, Axis Communications AB, Lund, Sweden
* Copyright (C) 2025, Axis Communications AB, Lund, Sweden
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,8 +35,8 @@ class OpcUaServer
private:
void AddBoolean(char *label, UA_Boolean value);
static void RunUaServer(OpcUaServer *parent);
bool colorareavalue;
std::thread *serverthread;
UA_Boolean running;
UA_Server *server;
bool colorareavalue_;
std::thread *serverthread_;
UA_Boolean running_;
UA_Server *server_;
};
2 changes: 1 addition & 1 deletion include/common.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2023, Axis Communications AB, Lund, Sweden
* Copyright (C) 2025, Axis Communications AB, Lund, Sweden
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
53 changes: 27 additions & 26 deletions src/colorarea.cpp → src/ColorArea.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2023, Axis Communications AB, Lund, Sweden
* Copyright (C) 2025, Axis Communications AB, Lund, Sweden
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,7 @@
#include <map>
#include <opencv2/imgproc.hpp>

#include "colorarea.hpp"
#include "ColorArea.hpp"
#include "common.hpp"

using namespace cv;
Expand All @@ -41,7 +41,8 @@ ColorArea::ColorArea(
const uint32_t markerwidth,
const uint32_t markerheight,
const uint8_t tolerance)
: color(color), img_size(img.size()), markerwidth(markerwidth), markerheight(markerheight), tolerance(tolerance)
: color_(color), img_size_(img.size()), markerwidth_(markerwidth), markerheight_(markerheight),
tolerance_(tolerance)
{
// Crop to avoid processing pixels outside color area
int max_x = point_center.x + markerwidth / 2;
Expand All @@ -64,10 +65,10 @@ ColorArea::ColorArea(
{
min_y = 0;
}
croprange_x = Range(min_x, max_x);
croprange_y = Range(min_y, max_y);
const Point offset(croprange_x.start, croprange_y.start);
this->point_center = point_center - offset;
croprange_x_ = Range(min_x, max_x);
croprange_y_ = Range(min_y, max_y);
const Point offset(croprange_x_.start, croprange_y_.start);
this->point_center_ = point_center - offset;
#if defined(DEBUG_WRITE)
Mat cropped_img = img(croprange_y, croprange_x);
DBG_WRITE_IMG("cropped_img.jpg", cropped_img);
Expand All @@ -79,8 +80,8 @@ ColorArea::ColorArea(
"%u",
__FILE__,
__FUNCTION__,
img_size.width,
img_size.height,
img_size_.width,
img_size_.height,
markerwidth,
markerheight,
point_center.x,
Expand All @@ -98,36 +99,36 @@ ColorArea::~ColorArea()
Scalar ColorArea::GetAverageColor(const Mat &img) const
{
// Make sure input image has the same size as the gague was set up for
assert(img_size == img.size());
assert(img.size() == img_size_);

// Crop
auto crop_img = img(croprange_y, croprange_x);
auto crop_img = img(croprange_y_, croprange_x_);
DBG_WRITE_IMG("avg_after_crop.jpg", crop_img);

return mean(crop_img, colorarea_mask);
return mean(crop_img, colorarea_mask_);
}

bool ColorArea::ColorAreaValueWithinTolerance(const Mat &img) const
{
// Make sure input image has the same size as the gague was set up for
assert(img_size == img.size());
assert(img_size_ == img.size());

auto currentavg = GetAverageColor(img);
LOG_D(
"%s/%s: Target/Current average color in region: (%1.f, %.1f, %.1f)/(%.1f, %.1f, %.1f)",
__FILE__,
__FUNCTION__,
color.val[R],
color.val[G],
color.val[B],
color_.val[R],
color_.val[G],
color_.val[B],
currentavg.val[R],
currentavg.val[G],
currentavg.val[B]);
auto colordiff_r = abs(color.val[R] - currentavg.val[R]);
auto colordiff_g = abs(color.val[G] - currentavg.val[G]);
auto colordiff_b = abs(color.val[B] - currentavg.val[B]);
auto colordiff_r = abs(color_.val[R] - currentavg.val[R]);
auto colordiff_g = abs(color_.val[G] - currentavg.val[G]);
auto colordiff_b = abs(color_.val[B] - currentavg.val[B]);

return (tolerance > colordiff_r && tolerance > colordiff_g && tolerance > colordiff_b);
return (tolerance_ > colordiff_r && tolerance_ > colordiff_g && tolerance_ > colordiff_b);
}

ColorAreaEllipse::ColorAreaEllipse(
Expand All @@ -152,10 +153,10 @@ ColorAreaEllipse::ColorAreaEllipse(
#endif

// Create color mask
colorarea_mask = Mat::zeros(Size(croprange_x.size(), croprange_y.size()), CV_8U);
colorarea_mask_ = Mat::zeros(Size(croprange_x_.size(), croprange_y_.size()), CV_8U);
ellipse(
colorarea_mask,
this->point_center,
colorarea_mask_,
this->point_center_,
Size(markerwidth / 2, markerheight / 2),
0.0,
0,
Expand All @@ -164,7 +165,7 @@ ColorAreaEllipse::ColorAreaEllipse(
-1,
LINE_8,
0);
DBG_WRITE_IMG("mask_img.jpg", colorarea_mask);
DBG_WRITE_IMG("mask_img.jpg", colorarea_mask_);
LOG_I("%s/%s: Elliptic colorarea created", __FILE__, __FUNCTION__);
}

Expand All @@ -191,7 +192,7 @@ ColorAreaRectangle::ColorAreaRectangle(
#endif

// Create color mask
colorarea_mask = Mat::ones(Size(croprange_x.size(), croprange_y.size()), CV_8U) * 255;
DBG_WRITE_IMG("mask_img.jpg", colorarea_mask);
colorarea_mask_ = Mat::ones(Size(croprange_x_.size(), croprange_y_.size()), CV_8U) * 255;
DBG_WRITE_IMG("mask_img.jpg", colorarea_mask_);
LOG_I("%s/%s: Rectancular colorarea created", __FILE__, __FUNCTION__);
}
Loading

0 comments on commit fcc951f

Please sign in to comment.