opencv/opencv_test.cpp
lls 5467684710 记录1
Signed-off-by: lls <staying_liu_1@163.com>
2025-03-07 12:00:23 +08:00

68 lines
1.1 KiB
C++

#include"opencv_test.h"
opencv_t::opencv_t()
{
}
opencv_t::~opencv_t()
{
}
opencv_t* opencv_t::create_new()
{
opencv_t* temp = nullptr;
temp = new opencv_t();
return temp;
}
void opencv_t::visit_xiangsu(Mat& temp)
{
int w = temp.cols;
int h = temp.rows;
int dims = temp.channels();
for (int row = 0; row < h; row++)
{
for (int col = 0; col < w; col++)
{
if (dims == 1)
{
int pv = temp.at<uchar>(row, col);
temp.at<uchar>(row, col) = 255 - pv;
}
else if (dims == 3)
{
Vec3b pv = temp.at<Vec3b>(row, col);
temp.at<Vec3b>(row, col)[0] = 255 - pv[0];
temp.at<Vec3b>(row, col)[1] = 255 - pv[1];
temp.at<Vec3b>(row, col)[2] = 255 - pv[2];
}
}
}
}
void opencv_t::visit_xiangsu(Mat& temp, int a)
{
int w = temp.cols;
int h = temp.rows;
int dims = temp.channels();
for (int row = 0; row < h; row++)
{
uchar* curr = temp.ptr<uchar>(row);
for (int col = 0; col < w; col++)
{
if (dims == 1)
{
int pv = *curr;
*curr++ = 255 - pv;
}
else if (dims == 3)
{
*curr++ = 255 - *curr;
*curr++ = 255 - *curr;
*curr++ = 255 - *curr;
}
}
}
}