当前位置:网站首页>图像特征计算与表示——基于内容的图像检索
图像特征计算与表示——基于内容的图像检索
2022-06-29 17:46:00 【华为云】
| 1️⃣作业需求 |
|---|
| 2️⃣核心代码 |
|---|
# coding:utf-8def extract_features(image_path, vector_size=32): image = imageio.imread(image_path) try: # Using KAZE, cause SIFT, ORB and other was moved to additional module alg = cv2.KAZE_create() # Finding image keypoints # 寻找图像关键点 kps = alg.detect(image) # Getting first 32 of them. # 计算前32个 # Number of keypoints is varies depend on image size and color pallet # 关键点的数量取决于图像大小以及彩色调色板 # Sorting them based on keypoint response value(bigger is better) # 根据关键点的返回值进行排序(越大越好) kps = sorted(kps, key=lambda x: -x.response)[:vector_size] # computing descriptors vector # 计算描述符向量 kps, dsc = alg.compute(image, kps) # Flatten all of them in one big vector - our feature vector # 将其放在一个大的向量中,作为我们的特征向量 dsc = dsc.flatten() # Making descriptor of same size # 使描述符的大小一致 # Descriptor vector size is 64 # 描述符向量的大小为64 needed_size = (vector_size * 64) if dsc.size < needed_size: # if we have less the 32 descriptors then just adding zeros # at the end of our feature vector # 如果少于32个描述符,则在特征向量后面补零 dsc = np.concatenate([dsc, np.zeros(needed_size - dsc.size)]) except cv2.error as e: print('Error: ', e) return None return dsc| 3️⃣实验结果 |
|---|
我们从数据集中随意选取一张图片:
用鼠标框出图像中的一块区域:
然后回车会获取数据集中与框出的目标区域特征最相近的五张图片:
还会输出每张图片的匹配值,这里的匹配值就是计算目标区域的特征与数据库中的图片的余弦距离,如果想相似度更高,可以扩充数据集,使得特征更加适配:
| 实验源码+报告 |
|---|
边栏推荐
猜你喜欢

阿里云不同账号新旧服务器镜像迁移数据迁移同步

Bottom level internal skill cultivation

最受欢迎的30款开源软件

Opencv+YOLO-V3实现目标跟踪

Maidong Internet won the bid of Dajia Insurance Group

位图的详细介绍及模拟实现

MATLAB 最远点采样(FPS)

How to use the chart control of the b/s development tool devextreme - customize the axis position?

mysql. What is the concept of sock

Mysql database literacy, do you really know what a database is
随机推荐
Createstore for Redux source code analysis
Set double click to run the jar file
Graduation season | Huawei experts teach interview tips: how to get a high salary offer from a large factory?
How to use the chart control of the b/s development tool devextreme - customize the axis position?
Prevent form resubmission based on annotations and interceptors
MaxCompute字符串替换函数-replace
[webdriver] upload files using AutoIT
mongoTemplate - distinct 使用
剑指 Offer 13. 机器人的运动范围 (BFS)
Custom handlerinterceptor interceptor for user authentication
Use SSH to pull codes
SRM supplier collaborative management system function introduction
Web Scraping with Beautiful Soup for Data Scientist
人脸识别4-百度商用方案调研
R language ggplot2 visualization: use the patchwork package (directly use the plus sign +) to horizontally combine a ggplot2 visualization result and a plot function visualization result to form the f
Sword finger offer 13 Robot range of motion (BFS)
What is the MySQL query view command
What is the function of MySQL cursors
3h精通OpenCV(九)-最简单的人脸检测
Error:Connection refused: connect