-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (60 loc) · 1.3 KB
/
main.cpp
File metadata and controls
63 lines (60 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <opencv2/opencv.hpp>
#include <opencv2/core/utils/logger.hpp>
using namespace cv;
using namespace std;
int i, j, k;
int dx;int dy;
Mat img, dst,tmp;//1920*1080
float alpha, beta;
int rnd(float a){
int b;
if(a > 0){
b = (a*2+1)/2;
}else{
b = (a*2-1)/2;
}
return b;
}
int main()
{
cout << "dx:"; cin >> dx;
cout << "dy:"; cin >> dy;
img = imread("2.png");
if (img.empty())
{
cout << "error.";
system("pause");
return -1;
}
img.convertTo(img,CV_32F,1.0/255,0);
dst = Mat::zeros(dy, dx, img.type());
alpha = (float)img.rows / dy;
beta = (float)img.cols / dx;
if (img.channels() == 1)
{
for (i = 0; i < dy; ++i)
{
for (j = 0; j < dx; ++j)
{
dst.at<uchar>(i, j) = img.at<uchar>(i * alpha, j * beta);
}
}
}
else if (img.channels() == 3)
{
for (i = 0; i < dy; ++i)
{
for (j = 0; j < dx; ++j)
{
/*dst.at<Vec3f>(i, j)[0] = img.at<Vec3f>(i,j)[0];
dst.at<Vec3f>(i, j)[1] = img.at<Vec3f>(i,j)[1];
dst.at<Vec3f>(i, j)[2] = img.at<Vec3f>(i,j)[2];*/
dst.at<Vec3f>(i, j)[0] = img.at<Vec3f>(rnd(i * alpha),rnd( j * beta))[0];
dst.at<Vec3f>(i, j)[1] = img.at<Vec3f>(rnd(i * alpha),rnd( j * beta))[1];
dst.at<Vec3f>(i, j)[2] = img.at<Vec3f>(rnd(i * alpha),rnd( j * beta))[2];
}
}
}
imshow("dst",dst);
waitKey(0);
}