Get photo

I didn’t know there would be such a step. My boss told me that all the information needed was on the wechat of my iPhone, and it was completely in the chat record, no difference from other pictures. I spent most of the day looking for tools to export wechat photos without success. Finally, my boss spent money (about 100RMB) to buy a mobile phone assistant membership version before finally exporting.

However, these images are distributed in subfolders under a large folder (/ TMP), and a short shell script is used to place them in the same folder (/RealImage).

#! /bin/bash
for file in 'tmp/*';
do   
    find $file -name "*.jpg" -exec cp {} RealImage \;
done   
/bin/cp: Argument list too long
# Direct CP may have the above problems
ls -l RealImage | grep "^ -" | wc -l
Copy the code

At this point, I have a folder of all the needed and unwanted images.

Eliminate irrelevant images

Call the Cloud Vision API to help me determine if there is a meter in the picture before I have to pay for my Google Cloud. The first step is to create a library of customer segments: Google Docs. After that, the API is called as follows:

// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
const fs = require("fs");

// Creates a client
const client = new vision.ImageAnnotatorClient();

const detect = async (n) => {

    const fileName1 = 'AllPic';
    const fileName2 = '.jpg';

    client
        .labelDetection(fileName1 + n + fileName2)
        .then(results= > {
            const labels = results[0].labelAnnotations;
            var find = false;
            for (var i = 0; i < labels.length; i++) {
            // If the description of the returned labels contains the labels Electronics or Electronic Device, the returned labels should be in the format of Object.
                if (labels[i].description == "Electronics" || labels[i].description == "Electronic device") {
                    find = true;
                    console.log(fileName1 + n + fileName2 + " Saved");
                    break; }}if (find == false) {
                fs.unlinkSync(fileName1 + n + fileName2);
                console.log(fileName1 + n + fileName2 + " Deleted");
            }
        })
        .catch(err= > {
            console.error('ERROR:', err);
        });
}

// The reason for using setTimeout here is that the Google Cloud Vision API is limited by the number of calls per minute, so it cannot be called too frequently.
detect(1);
for (var i = 2; i < 9000; i++) {
    (function (n) {
        setTimeout(detect, (n) * 100, n);
    })(i);
}
Copy the code

At this time, after a wave of culling, there were still 3,000, but when opened, the quality was uneven. Finally handed in a partner himself, blurred pictures and irrelevant pictures manually deleted, right is so unbearable.

We finally have the data set we need to work with, and in the second article we’ll explain how to convert images into text and label them using the Google Vision API.