Getting rid of opencv

This commit is contained in:
2023-06-16 23:31:20 +02:00
parent ab245f0484
commit 31cf1ee2b1
5 changed files with 487 additions and 363 deletions
+43 -28
View File
@@ -3,12 +3,11 @@
#include <vector>
#include <algorithm>
#include <memory>
#include <stdint.h>
#include <math.h>
#include <memory.h>
#include <opencv2/imgproc.hpp>
#include <QImage>
#include <QVector3D>
extern int THUMB_SIZE;
extern int THUMB_SIZE_BORDER;
@@ -38,55 +37,71 @@ public:
class RawImage
{
protected:
cv::Mat m_img;
bool m_stats;
double m_mean;
double m_stdDev;
double m_median;
double m_min;
double m_max;
double m_mad;
float m_thumbAspect;
uint32_t m_saturated;
using PixelType = uint8_t;
public:
enum ImgType
enum DataType
{
UINT8,
UINT16,
UINT32,
FLOAT32,
UINT8C3,
UINT8C4,
UINT16C3,
UINT16C4,
FLOAT32C3,
UNKNOWN,
FLOAT64,
};
protected:
struct Stats
{
bool m_stats = false;
double m_mean[4] = {0.0};
double m_stdDev[4] = {0.0};
double m_median[4] = {0.0};
double m_min[4] = {0.0};
double m_max[4] = {0.0};
double m_mad[4] = {0.0};
};
std::unique_ptr<PixelType> m_pixels;
std::unique_ptr<PixelType> m_original;
uint32_t m_width = 0;
uint32_t m_height = 0;
uint32_t m_channels = 0;
uint32_t m_ch = 0;
DataType m_type = UINT8;
DataType m_origType = UINT8;
float m_thumbAspect = 0.0;
uint32_t m_saturated = 0.0;
Stats m_stats;
void allocate(uint32_t w, uint32_t h, uint32_t ch, DataType type);
public:
RawImage();
RawImage(int w, int h, ImgType type);
RawImage(cv::Mat &img);
RawImage(uint32_t w, uint32_t h, uint32_t ch, DataType type);
RawImage(const RawImage &d);
RawImage(RawImage &&d);
RawImage(const QImage &img);
bool imageStats(double *mean, double *stdDev, double *median, double *min, double *max, double *mad, uint32_t *saturated);
void calcStats();
void rect(int &x, int &y, int w, int h, std::vector<double> &r) const;
int findPeaks(double background, double distance, std::vector<Peak> &peaks) const;
RawImage* medianFilter() const;
void quarter();
uint32_t width() const;
uint32_t height() const;
uint32_t channels() const;
uint32_t size() const;
ImgType type() const;
int dataType() const;
DataType type() const;
uint32_t norm() const;
void* data();
const void* data() const;
void* data(uint32_t row, uint32_t col = 0);
const void* data(uint32_t row, uint32_t col = 0) const;
void *origData(uint32_t row, uint32_t col = 0) const;
void convertToThumbnail();
void convertToGLFormat();
float thumbAspect() const;
const cv::Mat& mat() const;
bool pixel(int x, int y, QVector3D &rgb) const;
bool pixel(int x, int y, double &r, double &g, double &b) const;
void scaleToUnit();
void downscaleTo(uint32_t size);
static RawImage* fromPlanar(const RawImage &img);
static RawImage* fromPlanar(const void *pixels, uint32_t w, uint32_t h, uint32_t ch, DataType type);
static size_t typeSize(DataType type);
std::vector<RawImage> split() const;
};
#endif // RAWIMAGE_H