Suck the cat with code! This paper is participating in[Cat Essay Campaign].

preface

Photographer friends have to take a lot of photos every day, open the file also need to classify all the pictures, this workload is quite large. Let’s get him a recognition widget that automatically classifies some pictures. And megvii now supports a lot of scenes: characters, children, night scenes, streets, snow scenes, cats, dogs and so on can support a lot of scenes. Start by developing a simple desktop tool using Eletron. I’ve always been a back-end developer, so I can only make a rough interface.

Main functions:

1. Locate a folder

2. Identify the picture files in the folder. The recognition process mainly uses Kuangshi ARTIFICIAL intelligence interface, and the interface of scene and object recognition API is detailed in Megvii ARTIFICIAL Intelligence Open Platform

The specific implementation

1. Implement a desktop platform

A desktop gadget

const { app, BrowserWindow } = require("electron"); require('./src/pages/menu'); Function createWin() {const win = new BrowserWindow({width: 800, height: 600, webPreferences: {nodeIntegration: true, backgroundThrottling: false, // Set the application to run properly in the background nodeIntegration: True, // Set the API contextIsolation to use nodeJS on the page: false, // turn off the warning message},}); Win.loadfile ("./ SRC /index.html"); / / open the developer tools / / win webContents. OpenDevTools (); } // app.whenReady().then(createWin); On ("window-all-closed", () => {// On macOS, most apps and their menu bar remain active unless the user explicitly exits with Cmd + Q. if (process.platform ! == "darwin") { app.quit(); }}); // app.on("activate", () => { if (BrowserWindow.getAllWindows().length === 0) { createWin(); }});Copy the code

2. Realize scene and object recognition

Steps:

1. First of all, you need to apply for the corresponding key and Secret. Registering a Kuang Shi account and creating an application will obtain an appKey and appSecret

2, call scenario and object recognition API: request address: api-cn.faceplusplus.com/imagepp/bet…

Whether the choice Parameter names type Parameters that
Will choose api_key String The API Key that calls this API
Will choose api_secret String The API Secret that calls this API
Required (1 out of 3) image_url String The URL of the picture
async function scanPic(filePath) { const options ={ uri: url, method: 'POST', formData: { api_key: cfg.appKey, app_secret: cfg.appSecret, image_url:filePath } } const isCatPic = false; const result = await rp(options); const objects = JSON.parse(result).objects; objects.forEach(obj => { if(obj.value === 'Cat' ) { isCatPic = true; }}); return isCatPic; }Copy the code

Results show

It’s very simple to complete the project: show the results

References:

  • Juejin. Cn/post / 697419…
  • Juejin. Cn/post / 701547…
  • Console.faceplusplus.com.cn/documents/5…