相似图片搜索V2
<p>[TOC]</p>
<h3>1 简介</h3>
<p>1、在图库中找到与检索图片语义相似的图片集,并给出相似度打分(综合图片类型、颜色、内容、布局等特征)。
2、典型应用场景:找相似的图片集合(返回的结果包含相同的图片),各种设计素材、美术作品、UGC内容等。
3、适用的图片类型:各种网络图片、实拍图均可。注意检索图和入库的原图要尽量保持场景一致性,比如入库的原图为标准的广告图(无背景干扰),则检索图要尽量避免背景、其他干扰特征,否则模型计算图片的相似度时会有噪声,造成检索结果不准确。</p>
<h3>2 接入流程</h3>
<p>1、先通过入库接口将图片入库。
2、再调用检索接口,返回相似的图片集合。
3、可调用删除接口删除图片。</p>
<h3>3 接口调用说明</h3>
<h4>3.1 请求方式</h4>
<p>所有接口均为:<strong>POST</strong></p>
<h4>3.2 请求格式</h4>
<p>所有接口均为:<strong>application/form-data</strong></p>
<h4>3.3 请求参数</h4>
<p>请求参数均包括公共参数和业务参数(业务参数见具体接口说明)
接口调用时,均需要把<strong>公共参数</strong>和<strong>业务参数</strong>一并放在<strong>请求参数</strong>中提交</p>
<p><a name="公共请求参数"></a></p>
<h5>公共请求参数</h5>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:420px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>appId</td>
<td>String</td>
<td>是</td>
<td>服务商分配的唯一标识</td>
</tr>
<tr>
<td>timestamp</td>
<td>Long</td>
<td>是</td>
<td>当前时间戳(毫秒)</td>
</tr>
<tr>
<td>sign</td>
<td>String</td>
<td>是</td>
<td>签名,详见签名算法说明</td>
</tr>
</tbody>
</table>
<h5>签名算法说明</h5>
<pre><code>sign = sha256(appId + appSecret + timestamp)</code></pre>
<p>用服务商分配的 <strong>appId</strong>、服务商分配的 <strong>appSecret</strong>,当前时间戳(毫秒) <strong>timestamp</strong>,按上述顺序拼接成字符串,再进行 <strong>sha256</strong> 哈希得到。如下:</p>
<pre><code class="language-java">String appId = &quot;xyzxy2121zxyz&quot;;
String timestamp = &quot;1555378976238&quot;;
String appSecret = &quot;efcefcef1121cefcefc1212121&quot;;
String str = appId + appSecret + timestamp;
String sign = sha256(str);</code></pre>
<h4>3.4 返回说明</h4>
<h5>返回字段说明</h5>
<table>
<thead>
<tr>
<th>字段名</th>
<th><div style="width:420px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>code</td>
<td>返回码,详见:code返回码说明</td>
</tr>
<tr>
<td>msg</td>
<td>code对应的描述</td>
</tr>
<tr>
<td>charge</td>
<td>计费标志 true为计费,false为不计费</td>
</tr>
<tr>
<td>taskNo</td>
<td>本次请求号</td>
</tr>
<tr>
<td>data</td>
<td>返回具体结果,详见具体接口返回体说明</td>
</tr>
</tbody>
</table>
<h5>code返回码说明</h5>
<table>
<thead>
<tr>
<th>code</th>
<th><div style="width:420px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>200</td>
<td>成功</td>
</tr>
<tr>
<td>202</td>
<td>图片已存在</td>
</tr>
<tr>
<td>203</td>
<td>图片不存在</td>
</tr>
<tr>
<td>400</td>
<td>参数错误</td>
</tr>
<tr>
<td>404</td>
<td>接口地址不正确</td>
</tr>
<tr>
<td>500</td>
<td>系统维护,请稍候再试</td>
</tr>
<tr>
<td>601</td>
<td>接口未开通</td>
</tr>
<tr>
<td>602</td>
<td>账号停用</td>
</tr>
<tr>
<td>604</td>
<td>接口停用</td>
</tr>
<tr>
<td>606</td>
<td>调用超限,请稍候再试</td>
</tr>
<tr>
<td>607</td>
<td>ip不在白名单</td>
</tr>
<tr>
<td>609</td>
<td>请求过于频繁,请稍候再试</td>
</tr>
<tr>
<td>610</td>
<td>请求超时</td>
</tr>
<tr>
<td>999</td>
<td>其他,以实际返回为准</td>
</tr>
</tbody>
</table>
<hr />
<h3>4 图片入库</h3>
<h4>4.1 请求地址</h4>
<p><code>https://api.jumdata.com/image/similarity/v2/input</code></p>
<h4>4.2 请求参数</h4>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:420px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>url</td>
<td>String</td>
<td>否</td>
<td>入库图片的URL</td>
</tr>
<tr>
<td>base64</td>
<td>String</td>
<td>否</td>
<td>入库图片的base64</td>
</tr>
<tr>
<td>description</td>
<td>String</td>
<td>否</td>
<td>入库图片的描述,不能超过64字节</td>
</tr>
</tbody>
</table>
<ul>
<li>base64、url 必须提供一个,优先级:url > base64,图片格式支持jpg、png、bmp格式</li>
</ul>
<p>公共请求参数请参阅:<a href="#公共请求参数">公共请求参数</a></p>
<h4>4.3 入库成功返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 200, // 返回码,详见返回码说明
&quot;msg&quot;: &quot;成功&quot;,// 返回码对应描述
&quot;taskNo&quot;: &quot;043439882226367117195632&quot;,// 本次请求号
&quot;charge&quot;: true, // 计费标志
&quot;data&quot;: {
&quot;contSign&quot;: &quot;MzA0OTUzNjk1MCwyMjUzNTU3Mjc&quot; // 入库后的图片签名
}
}</code></pre>
<h4>4.4 入库失败返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 202,
&quot;msg&quot;: &quot;图片已存在!&quot;,
&quot;taskNo&quot;: &quot;043439882226367117195632&quot;,
&quot;charge&quot;: false
}</code></pre>
<h4>4.5 接口调用失败返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 400,
&quot;msg&quot;: &quot;url和base64不能同时为空!&quot;
}</code></pre>
<h3>5 图片检索</h3>
<h4>5.1 请求地址</h4>
<p><code>https://api.jumdata.com/image/similarity/v2/search</code></p>
<h4>5.2 请求参数</h4>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:420px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>url</td>
<td>String</td>
<td>否</td>
<td>检索图片的URL</td>
</tr>
<tr>
<td>base64</td>
<td>String</td>
<td>否</td>
<td>检索图片的base64</td>
</tr>
<tr>
<td>start</td>
<td>String</td>
<td>否</td>
<td>分页功能,起始位置。接口返回数量最大限制1000条,例如:起始位置为800,截取条数500条,接口也只返回第800-1000条的结果,共计200条。默认返回0-100</td>
</tr>
<tr>
<td>end</td>
<td>String</td>
<td>否</td>
<td>分页功能,截取条数,例:250</td>
</tr>
</tbody>
</table>
<ul>
<li>base64、url 必须提供一个,优先级:url > base64,图片格式支持jpg、png、bmp格式</li>
</ul>
<p>公共请求参数请参阅:<a href="#公共请求参数">公共请求参数</a></p>
<h4>5.3 检索有结果返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 200,// 返回码,详见返回码说明
&quot;msg&quot;: &quot;成功&quot;,// 返回码对应描述
&quot;taskNo&quot;: &quot;043439882226367117195632&quot;,// 本次请求号
&quot;charge&quot;: true, // 计费标志
&quot;data&quot;: {
&quot;result&quot;: [
{
&quot;brief&quot;: &quot;{\&quot;describe\&quot;:\&quot;测试1\&quot;, \&quot;taskNo\&quot;:\&quot;123\&quot;}&quot;,//入库是添加的描述信息
&quot;score&quot;: 1,//图片相关性,取值范围0-1,越接近1代表越相似
&quot;contSign&quot;: &quot;MzA0MzM0ODQ1NSwxNjIwMzA3MTk&quot; //图片签名信息,可以用来删除图片或定位问题
}
],
&quot;resultNum&quot;: &quot;8&quot;,//检索结果数
&quot;hasMore&quot;: &quot;false&quot; //是否还有下一页,返回值:true、false;如果不分页,不用关注该字段
}
}
</code></pre>
<h4>5.5 检索无结果返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 200,
&quot;msg&quot;: &quot;成功&quot;,
&quot;taskNo&quot;: &quot;043439882226367117195632&quot;,
&quot;charge&quot;: true,
&quot;data&quot;: {
&quot;resultNum&quot;: 0,
&quot;hasMore&quot;: &quot;false&quot;
}
}</code></pre>
<h4>5.6 接口调用失败返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 400,
&quot;msg&quot;: &quot;url和base64不能同时为空!&quot;
}</code></pre>
<h3>6 删除图片</h3>
<h4>6.1 请求地址</h4>
<p><code>https://api.jumdata.com/image/similarity/v2/delete</code></p>
<h4>6.2 请求参数</h4>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:420px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>contSign</td>
<td>String</td>
<td>是</td>
<td>图片签名信息,多个以逗号隔开,例:MzA0MzM0ODQ1NSwxNjIwMzA3JLk3,NDAzMDk3MFP0NCwxOTU0MDY0OTA1</td>
</tr>
</tbody>
</table>
<p>公共请求参数请参阅:<a href="#公共请求参数">公共请求参数</a></p>
<h4>6.3 检索有结果返回样例</h4>
<pre><code class="language-json">{
&quot;msg&quot;: &quot;成功&quot;,//返回码对应描述
&quot;code&quot;: 200,//返回码,详见返回码说明
&quot;taskNo&quot;: &quot;991824559141136645118228&quot;,//本次请求号
&quot;charge&quot;: true,//计费标志
&quot;data&quot;: {}
}</code></pre>
<h4>6.4 接口调用失败返回样例</h4>
<pre><code class="language-json">{
&quot;charge&quot;: false,
&quot;code&quot;: 203,
&quot;msg&quot;: &quot;图片不存在!&quot;,
&quot;taskNo&quot;: &quot;594546003180864495178423&quot;
}</code></pre>