1.命名脚本
#!/bin/bash
let i=1
path=/home/bairui/char_color/
cd ${path}
mkdir bak
for file in *.jpg
do
cp ${file} bak
mv ${file} ${i}.jpg
echo "${file} renamed as ${i}.jpg"
let i=i+1
done
2.灰度转换
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img1,img2;
char filename[50];
for(unsigned int k=0;k<50;k++)
{
sprintf(filename,"/home/***/char_color/9/%d.jpg",k);
img1=imread(filename);
if (!img1.data)
{
std::cout << "No data!" << std::endl;
return -1;
}
if(img1.channels()==3)
{
cvtColor(img1,img2,CV_BGR2GRAY);
cv::imwrite(filename, img2);
}
//resize(img1,img2,Size(28,28),0,0,INTER_LINEAR);
}
return 0;
}