139 lines
2.2 KiB
C++
139 lines
2.2 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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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("ÁÁ¶Èµ÷Õû", WINDOW_AUTOSIZE);
|
|
int max = 100;
|
|
int lisss = 50;
|
|
|
|
}
|
|
|
|
static void ontrack(int lit,void* temp )//»Øµ÷
|
|
{
|
|
|
|
Mat image = *((Mat*)temp);
|
|
Mat out;
|
|
lit= lit - 50;
|
|
cv::add(image, Scalar(lit, lit, lit), out);
|
|
imshow("ÁÁ¶Èµ÷Õû22", out);
|
|
}
|
|
|
|
void opencv_t::bar_demo(Mat& temp)
|
|
{
|
|
namedWindow("ÁÁ¶Èµ÷Õû22", WINDOW_AUTOSIZE);
|
|
int lit = 50;
|
|
int max = 100;
|
|
createTrackbar("valuebar", "ÁÁ¶Èµ÷Õû22", &lit, max, ontrack,(void*)(&temp));
|
|
ontrack(50, &temp);
|
|
}
|
|
|
|
void opencv_t::color_sectect(Mat& temp)
|
|
{
|
|
namedWindow("·ç¸ñ±ä»»", WINDOW_AUTOSIZE);
|
|
int c = -1;//signal
|
|
Mat dst;
|
|
while (true)
|
|
{
|
|
cin >> c;
|
|
if (c == -1)
|
|
{
|
|
imshow("·ç¸ñ±ä»»", temp);
|
|
waitKey(1);
|
|
}
|
|
else
|
|
{
|
|
c = c % 22;
|
|
applyColorMap(temp, dst, colormaps[c]);
|
|
imshow("·ç¸ñ±ä»»",dst);
|
|
waitKey(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Mat opencv_t::operter_chen(Mat& temp)
|
|
{
|
|
Mat out;
|
|
multiply(temp, Scalar(2,2,2),out);
|
|
return out;
|
|
}
|
|
|
|
|