C + + realizes the mean reduction of high-volume images by 1 operation

Source: Internet
Author: User

Come in often deal with a large number of pictures, pictures of the operation of the name is really troublesome. Let's talk about the most commonly used file read and write operations.

After clicking the open link, the author writes very clearly. After understanding the article in this blog post, it is much easier.

Header files to include: <fstream>

Namespaces: STD

You can also try <fstream.h>

FStream provides three classes for implementing C + + operations on files. (file creation, read-write).
Ifstream-read from an existing file

Ofstream-Write content to a file

FStream-Open file for read and write

Supported file types

in fact, file types can be divided into two categories: text files and binaries .

A text file holds a readable character, while a binary file saves only binary data.

Using binary mode, you can manipulate images and other files.

In text mode, you can only read and write text files. Otherwise you will get an error.

Since I have stored the name of the picture in a TXT file,


Every time I read a line, I read a picture and then I do the work.

For example, I'm going to preprocess a batch of images, and the preprocessing method is mean reduction and mean variance of 1, then the picture is one to 0-255 and stored in another folder.

The code is as follows:

#include <iostream> #include <fstream> #include <string> #include <opencv2/opencv.hpp>using Namespace Std;using namespace Cv;int main () {Mat src,src0,img,lala,final,over;double average;ifstream fs;fs.open (" Twoclasstrnegativeimglist.txt ", ios::in); char img_name[128]; Const string Imgpath= "d:/twonegative/"; const string imgsavepath= "d:/processed2negative/"; while (Fs.getline (img_name ) {Src=imread (imgpath+img_name,-1); Src.convertto (SRC0,CV_64FC1); Meanstddev (Src0,img,lala); Final= ( Src-img.at<double> (0,0))/lala.at<double> (0,0); normalize (final, over, 0, 255, Norm_minmax, CV_8UC1); Imwrite (Imgsavepath+img_name,over);}    Waitkey (); return 0;}



C + + realizes the mean reduction of high-volume images by 1 operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.