728x90
728x90
μμ€ μ½λ
κΈ°μ‘΄μ λ€μ΄ λ°μλ sample128.png, lenna.png μ¬μ§μ νμ©ν©λλ€.
β
μμμ μ€μΌμΌλ§μ μ‘°μ νλ μμ€μ½λμ λλ€.
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <Windows.h>
#include <string.h>
#include <iostream>
using namespace std;
using namespace cv;
string OpenFileDialog() {
char name[MAX_PATH] = { 0, };
OPENFILENAMEA ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAMEA);
ofn.hwndOwner = NULL;
ofn.lpstrFilter = "λͺ¨λ νμΌ(*.*)\0*.*\0";
ofn.lpstrFile = name;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "";
string strName;
if (GetOpenFileNameA(&ofn)) {
strName = name;
}
return strName;
}
Mat MyScailing1(Mat image, Size size) {
// μμμ νμλ₯Ό μνλ§
Mat ret(size, CV_8UC1, Scalar(0));
double scaleX = (double)size.width / image.cols;
double scaleY = (double)size.height / image.rows;
for (int i = 0; i < image.rows; i++) {
for (int j = 0; j < image.cols; j++) {
int x = (int)(j * scaleX);
int y = (int)(i * scaleY);
ret.at<uchar>(y, x) = image.at<uchar>(i, j);
}
}
return ret;
}
Mat MyScailing2(Mat image, Size size) {
// λ³κ²½λ μ¬μ΄μ¦μ μλ μμμΌλ‘λΆν° νμλ₯Ό μΆμΆ
Mat ret(size, CV_8UC1, Scalar(0));
double scaleX = (double)size.width / image.cols;
double scaleY = (double)size.height / image.rows;
for (int i = 0; i < ret.rows; i++) {
for (int j = 0; j < ret.cols; j++) {
int x = (int)(j * scaleX);
int y = (int)(i * scaleY);
ret.at<uchar>(y, x) = image.at<uchar>(i, j);
}
}
return ret;
}
void Scailing() {
// μ€μΌμΌλ§
auto name = OpenFileDialog();
if (name != "") {
auto image = imread(name, IMREAD_GRAYSCALE);
Mat m1, m2, m3, m4, m5;
resize(image, m1, Size(256, 256), 0, 0);
imshow("Down", m1);
waitKey();
resize(image, m2, Size(1024, 1024), 0, 0);
imshow("Up", m2);
waitKey();
m3 = MyScailing1(image, Size(256, 256));
imshow("MyDownSampling", m3);
waitKey();
m4 = MyScailing1(image, Size(1024, 1024));
imshow("MyDownSampling", m4);
waitKey();
m5 = MyScailing1(image, Size(1024, 1024));
imshow("MyDownSampling", m5);
waitKey();
}
}
int main() {
Scailing();
}
μ€ν κ²°κ³Ό
β
728x90
λ°μν
'π Programming > OpenCV' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[OpenCV] νμ€ν κ·Έλ¨ λͺ μΈν μμ€ μ½λ (C++) (0) | 2020.12.31 |
---|---|
[μμ μ²λ¦¬] λ―ΈλΆμ μ΄μ©ν μ£μ§(Edge) κ²μΆ (0) | 2020.12.29 |
[μμ μ²λ¦¬] κ°λ¨ν μ£μ§(Edge) κ²μΆ κΈ°λ² (0) | 2020.12.29 |
[μμ μ²λ¦¬] νμ μ²λ¦¬ κΈ°λ² νμ©κ³Ό κ°μ°μμ νν°(Gaussian Filter) (0) | 2020.12.29 |
[μμ μ²λ¦¬] νμ μ²λ¦¬μ μ리μ κ²½κ³ λΆλΆ μ²λ¦¬ (1) | 2020.12.29 |