• 遍历文件夹,修改图片尺寸


    #include <stdio.h>
    #include<io.h> //下面查找文件的功能需要用到
    #include <opencv2/opencv.hpp>
    #include <iostream>
    
    using namespace std;
    using namespace cv;
    
    void resizePic(char *destFile, char *srcFile);
    
    int main(int argc, char *argv[])
    {
    	struct _finddata_t fa;
    	long fHandle;
    	char destDir[] = "E:/newPicLib/";
    	char srcDir[] = "E:/oldPicLib/";
    	int i = 0;
    
    	if ((fHandle = _findfirst("E:/oldPicLib/*.bmp", &fa)) == -1L)//这里可以改成需要的目录 
    	{
    		printf("当前目录下没有bmp文件
    ");
    		return 0;
    	}
    	else
    		do
    		{
    			char tempDest[256] = {0};
    			char tempSrc[256] = {0};
    			strcat_s(tempDest, destDir);
    			strcat_s(tempDest, fa.name);
    			strcat_s(tempSrc, srcDir);
    			strcat_s(tempSrc, fa.name); //cout << "dest file is:" << tempDest << " src file is :" << tempSrc << endl;
    			printf("处理文件:%s... ...", fa.name);
    			resizePic(tempDest, tempSrc);
    			cout << "ok.." << ++i << endl;
    			
    	} while (_findnext(fHandle, &fa) == 0);
    	 
    	_findclose(fHandle);
    	return 0;
    }
    
    
    void resizePic(char *destFile, char *srcFile)
    {
    	IplImage* img = cvLoadImage(srcFile, 0);
    	IplImage* destImg = cvCreateImage(cvSize(360, 288), 8, 1);
    	memset(destImg->imageData, 0 ,destImg->imageSize);
    
    	int width = img->width;
    	int height = img->height;
    
    	int shiftH = (288 - height) / 2;
    	int shiftW = (width - 360) / 2;
    	cvSetImageROI(img, cvRect(shiftW, 0, 360, height));
    	cvSetImageROI(destImg, cvRect(0, shiftH, 360, height));
    	cvCopy(img, destImg);
    	cvResetImageROI(img);
    	cvResetImageROI(destImg);
    
    	cvSaveImage(destFile, destImg);
    	//cvShowImage("oral", img); cvShowImage("dest", destImg); cvWaitKey();
    	cvReleaseImage(&img);
    	cvReleaseImage(&destImg);
    }
    
    Trouble is a Friend
  • 相关阅读:
    WebSocket简单使用
    viewport 的基本原理以及使用
    Markdown基本语法总结
    emmet 工具的基本使用,总结
    在idea中把项目上传到GitHub库中
    Git Bash命令汇总
    用github创建自己的存储库并把文件推送到远程库中
    之前编写的Symfony教程已经可以观看了
    Symfony路由配置教程已开课
    Symfony原创视频教程
  • 原文地址:https://www.cnblogs.com/sunniflyer/p/4059583.html
Copyright © 2020-2023  润新知