Baidu cloud intelligent recognition api Java platform invoke achieve food

   My school record of 2 hours to write the ceiling of 20 dishes identify java program.

1.2. Baidu Cloud Smart Profile

 

1.2.1 Baidu image recognition service

Baidu image recognition services, based on deep learning and large-scale image training, comprehensive information to accurately identify the object in the picture category, location, and so on confidence.

 

1.2.2 Recognition dishes

Support identify 50,000 kinds of dishes adapted to recognize only dishes containing a single picture, the interface returns the name of the dishes, confidence, calories, Wikipedia information and other comprehensive information. Support self dishes Gallery for identifying images containing multiple dishes, the interface returns the name of the dishes, location, relevance and other comprehensive information.

 

1.2.3 recognition application scenarios dishes

According to take a picture, the picture identification names of dishes, the dishes get a reference caloric content and Wikipedia information can be combined with the recognition results provide further dietary recommendations, health-related functions such as program management, enhance the user experience, widely used in food and beverage and entertainment Health Management APP in. According to take a picture, identify the name and location of the picture dishes, improve settlement efficiency and reduce manual entry cost, widely used in intelligent settlement in the catering industry.

 

1.2.4 Introduction recognition interface dishes

 

Interface capability: the request for identification dishes. I.e., for an image (normally decoded, and an appropriate aspect ratio) of the input, name of the output image of the dishes, calorie information, confidence.

Request format: POST mode call (Content-Type is application / x-www-form-urlencoded, and then through the request body urlencode formatting)

Returned Format: JSON format

Request limit: base64 encoded subject to request image: base64 encoded picture refers to a picture encoded data string into a string, the string is used instead of the image address. First, you can get a binary image, and then use Base64 encoding format can be. (Base64 encoded picture is not included in the picture header, such as (data: image / jpg; base64), a request format support: PNG, JPG, JPEG, BMP, GIF **, the size does not exceed base64 encoded 4M, the smallest side at least 15px, the longest side maximum 4096px, an aspect ratio of 3: 1 or less)

1.2.5 Request Interface Parameter Description

parameter

Are Required

Types of

The values ​​range

Explanation

image

Yes

string

-

Base64 encoded string, mandatory request to the image file format. (Supported image formats: jpg, bmp, png, jpeg ), image size no more than 4M. The shortest side at least 15px, the longest side maximum 4096px. Note: The image needs to base64 encoded, remove the head and then perform encoding urlencode .

top_num

no

unit32

-

Return result top n, default 5.

filter_threshold

Yes

float

-

0.95 default can be adjusted to identify the effect of this parameter, the recognition rate decreased non-food.

baike_num

no

integer

0

The number of results returned encyclopedic information, default does not return

 

 

 

 

1.2.6 Interface Parameter Description Returns

Field

Are Required

Types of

Explanation

log_id

Yes

uint64

The only log id, used to locate the problem

result_num

no

unit32

The number of results to return the number of elements, and in the result array

result

no

array()

Dishes recognition result array

+name

no

string

Dishes, example: fish-flavored pork

+calorie

no

float

Calories, calorie content per 100g

+probability

no

float

Recognition result confidence value for each row, 0-1

+ Baike_info

object

no

Corresponding to the recognition result Wikipedia entry name

++ baike_url

string

no

Corresponding to the recognition result of Baidu encyclopedia pages link

++image_url

string

no

The corresponding recognition results Encyclopedia image link

++description

string

no

Corresponding to the recognition result Encyclopedia Description

 

Needs analysis

2.1 Introduction to Program

2.1.1 program type

This program is written in java call Baidu cloud platform for intelligent image recognition software to identify the interface dishes.

2.1.2 program use

 

1. Run the program to the main page, click on the menu bar of the image recognition

 

                                                                      

 

 
FIG main program interface 1-1

 

 

2. Expand the menu bar

  

 

                                                                   

 

 

 

 

 

 

 

 

 

 

FIG main interface menu bar 1-2

 

 

 

3. dishes picture identification

                                                 

 

4. Click the identification history menu bar to view the data in the database

                                                                       

 

Figure 1-7 record display

 

2.2 Requirements Analysis

2.2.1 Program Stream FIG.

(1) The image recognition function for data stream 2-1 of FIG.

 

 

Figure 2-1 image recognition function for data flow graph

(2) Program Operation flowchart 2-2.

 

 

According to the flowchart of FIG. 2-2 program operating flow of FIG.

 

2.2.2 Program Functional Requirements

(1) Image Recognition

识别出用户提供的图片的菜名、卡路里、置信度、百科信息描述。

(2)历史纪录查询

显示识别过图像相关信息的历史纪录。

(3)数据库菜品信息检索

输入菜名查询出所查菜的相关信息。

 

 

3 程序设计

3.1 总体设计

程序分为3个大模块,分别是图像识别模块,历史纪录查询模块,数据库菜品信息检索,下图3-1是菜品识别程序的程序与模块的关系:

 

 

 

图3-1 菜品识别程序结构图

3.2 图像识别模块设计

设定返回菜品数据为两条,选择第一条的菜名、卡路里、置信度、百科信息和第二条的菜名。

左边4行2列的网格布局用来显示四条文本信息,右边的画布用来显示加载后的图像和百科信息。最底下为1行4列的网格布局,显示、退出按钮和拖拽提示标签和实现接受拖拽图片后显示图片路径的文本框。

点击显示会调用文件选择器。通过点击显示或者直接拖拽图片到文本框都可以通过获得图片的路径来获得图片的信息。

将图片信息通过图像识别接口用POST方式上传到百度智能云平台的图像识别服务得到JSON格式的字符串。将JSON格式的字符串利用阿里的fastjson库转换字符串,获得想要格式的信息存到控件中。

 

3.3 历史纪录模块设计

历史纪录模块界面的主容器采用3行1列的网格布局,第一行显示历史纪录标签,第二行用JtextArea控件来存放从数据库获取的指定列的信息,第三行添加显示和退出按钮。

3.4 数据库菜品信息检索模块

通过输入菜品名称对指定列在数据库中查询符和的行,并用JtextArea存放菜品的百科信息。

 

 

4 菜品识别程序实现

4.1 程序开发环境介绍

本程序使用的是Eclipse201906版本开发,语言使用的是JavaJDK版本为11。在Windows10平台上完成开发与测试。

4.2 图像识别模块实现

 

5 软件测试

5.1 图像识别测试

5.1.1 文件选择测试

点击图像识别页面的显示调用文件选择器:

      

                                                                                  

 

图5-1 文件选择测试

 

5.1.2 图像拖拽测试

拖拽图像进文本框加载图像,并在文本框显示图像路径信息:

                                                                             

图5-2 拖拽加载图片测试

5.1.3 图像识别结果测试

拖拽图片至文本框或者点击显示调用文件选择器加载图片,上传图片信息,将返回结果显示在空间中

 

                                                                                

图5-3 图像识别结果测试

5.2 历史纪录显示测试

点击显示从数据中获取菜品识别的历史纪录

 

图5-4 历史纪录显示测试

5.3数据库菜品信息查询测试

输入菜品名称,点击查询,返回菜品相关信息。 

图5-5 数据库菜品信息查询测试

 

参考文献

[1] 慕课教育研发中心.Java从入门到项目实践[M].北京:清华大学出版社,2018.

[2] 百度工程师.百度智能云文档-菜品识别[EB/OL]

.https://cloud.baidu.com/doc/IMAGERECOGNITION/s/Ajwvy2g51/,2019-06-28.

[3]liuyz60.JAVA图形界面,怎么让背景图片正好充满JFrame?[EB/OL]

. https://zhidao.baidu.com/question/1925865716690279987.html,2017-11-27.

[4]蒋固金.JAVA拖拽选择文件[EB/OL]

. https://blog.csdn.net/jianggujin/article/details/50569827,2016-01-23.

[5]阿朱__.从本地读取json文件 用alibaba--fastjson解析 jar包[EB/OL]

. https://blog.csdn.net/qq_41371858/article/details/84940854,2018-12-10.

[6]紫霜落枫.Java如何做出好看的本地文件选择器[EB/OL]

. https://zhidao.baidu.com/question/425294497293157012.html,2017-12-16.

[7]披Zhe羊皮De狼.Java中改变应用程序界面外观[EB/OL]. https://blog.csdn.net/u010995220/article/details/49847307,2015-11-15.

 

资源链接:https://download.csdn.net/my/uploads/1/1(待审核后更新)

 

Guess you like

Origin www.cnblogs.com/yuanhang110/p/11229358.html