opencv/opencv_test.cpp

139 lines
2.2 KiB
C++
Raw Normal View History

#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;
}
}
}
}
Mat opencv_t::operter_zuo(Mat& temp)
{
Mat out;
cv::add(temp, Scalar(50, 50, 50), out);//divide
//out = temp + Scalar(50, 50, 50);
return out;
}
void opencv_t::tar_bar(Mat& temp)
{
namedWindow("<EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD>", WINDOW_AUTOSIZE);
int max = 100;
int lisss = 50;
}
static void ontrack(int lit,void* temp )//<2F>ص<EFBFBD>
{
Mat image = *((Mat*)temp);
Mat out;
lit= lit - 50;
cv::add(image, Scalar(lit, lit, lit), out);
imshow("<EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD>22", out);
}
void opencv_t::bar_demo(Mat& temp)
{
namedWindow("<EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD>22", WINDOW_AUTOSIZE);
int lit = 50;
int max = 100;
createTrackbar("valuebar", "<EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD>22", &lit, max, ontrack,(void*)(&temp));
ontrack(50, &temp);
}
void opencv_t::color_sectect(Mat& temp)
{
namedWindow("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", WINDOW_AUTOSIZE);
int c = -1;//signal
Mat dst;
while (true)
{
cin >> c;
if (c == -1)
{
imshow("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", temp);
waitKey(1);
}
else
{
c = c % 22;
applyColorMap(temp, dst, colormaps[c]);
imshow("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",dst);
waitKey(1);
}
}
}
Mat opencv_t::operter_chen(Mat& temp)
{
Mat out;
multiply(temp, Scalar(2,2,2),out);
return out;
}