저장소
이미지 회전 본문
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\core\core.hpp"
#include "opencv2\opencv.hpp"
#include <stdio.h>
#include <io.h>
#include <conio.h>
#include <stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
#include <sys/types.h>
#include <list>
#include <direct.h> //mkdir
#include <errno.h>
using namespace cv;
using namespace std;
typedef struct _finddata_t FILE_SEARCH;
void GetfileList(char* path);
void RotationImage(char* path);
int main() {
char path[100] = "C:/Users/Administrator/Desktop/cat";
//char path2[100] = "D:/New_Image_Down/Not_folder/human";
GetfileList(path);
//GetfileList(path2);
return 0;
}
void GetfileList(char* path){
long h_file;
char search_Path[250];
//list<string> folder_Liset
FILE_SEARCH file_search;
sprintf_s(search_Path, "%s/*.*", path);
if ((h_file = _findfirst(search_Path, &file_search)) == -1L) {
printf("No files in current directory!\n");
}
else {
do {
if (!strcmp(file_search.name, "..") || !strcmp(file_search.name, "."))
{
}
else
{
//printf("%s\n", file_search.name);
char low_path[250] = "";
sprintf_s(low_path, "%s/%s", path, file_search.name);
RotationImage(low_path);
//printf("%s");
}
} while (_findnext(h_file, &file_search) == 0);
_findclose(h_file);
}
}
void RotationImage(char* path)
{
long h_file;
char search_Path[250];
//list<string> folder_Liset
FILE_SEARCH file_search;
char NewFileAddr[256];
char NewFileFullPath[256];
char FileAddr[256];
char ImageFileName[128];
char FileNameFullPath[256];
char *filename_old = NULL;
char *filename_new = NULL;
int count = 0;
sprintf_s(search_Path, "%s/*.jpg", path);
if ((h_file = _findfirst(search_Path, &file_search)) == -1L) {
printf("No files in current directory!\n");
}
else {
do {
if (!strcmp(file_search.name, "..") || !strcmp(file_search.name, "."))
{
}
else
{
for (int i = 0; i < 4; i++)
{
int angle[] = { 5, 15, 355, 345 };
char dir_name[200];
sprintf(dir_name, "%s%s%d", path, "/", angle[i]);
//itoa(angle[i], dir_name, radix);
//printf("%s\n",FileNameFullPath);
if (!_mkdir(dir_name)); // Unicode 버전
{
printf("폴더 생성 성공\n");
}
float m[6];
IplImage* pDstImg = 0;
CvMat M;
sprintf(FileNameFullPath, "%s%s%s", path, "/", file_search.name);
//printf("%s\n", fd.name);
IplImage *imgae = cvLoadImage(FileNameFullPath);
// 복사
pDstImg = cvCloneImage(imgae);
// 회전을위한 행렬 (아핀 행렬) 요소를 설정하고 CvMat 행렬 M을 초기화
m[0] = (float)(cos(angle[i] * CV_PI / 180));
m[1] = (float)(-sin(angle[i] * CV_PI / 180));
m[2] = pDstImg->width * 0.5;
m[3] = -m[1];
m[4] = m[0];
m[5] = imgae->height * 0.5;
cvInitMatHeader(&M, 2, 3, CV_32FC1, m, CV_AUTOSTEP);
// 지정된 회전 행렬은 GetQuadrangleSubPix을 이용해 이미지 전체를 회전
cvGetQuadrangleSubPix(imgae, pDstImg, &M);
sprintf(NewFileFullPath, "%s%s%s%s%d%s%d.jpg", dir_name, "/", file_search.name, "_", angle[i], "_", count);
filename_old = FileNameFullPath;
filename_new = NewFileFullPath;
//printf("%s\n");
cvSaveImage(NewFileFullPath, pDstImg);
//result = _findnext(handle, &fd);
////count++;
filename_old = NULL;
filename_new = NULL;
cvReleaseImage(&imgae);
cvReleaseImage(&pDstImg);
count++;
/*char low_path[250] = "";
sprintf_s(low_path, "%s/%s", path, file_search.name);
GetfileList(low_path);*/
}
}
} while (_findnext(h_file, &file_search) == 0);
_findclose(h_file);
}
}
'OpenCV' 카테고리의 다른 글
영상반전 (0) | 2016.04.10 |
---|---|
이미지 띄우기 (0) | 2016.04.09 |
edge detection(canny) (0) | 2016.04.09 |
edge detection(sobel) (0) | 2016.04.09 |
템플릿 매칭 (0) | 2016.03.04 |