python opencv图像检索_OpenCV和基于内容的图像检索有没有一种方法可以在不下载图像的情况下使用在线数据库...

本文介绍了使用Python和OpenCV构建一个基于内容的图像检索(CBIR)系统,该系统目前处理本地图像数据库。现在目标是将系统连接到Scrapy网络爬虫,以处理在线图像。问题是能否在不下载图像的情况下直接对在线图像进行计算和索引。
摘要由CSDN通过智能技术生成

我试图构建一个CBIR系统,最近用Python编写了一个程序,使用OpenCV函数可以查询本地图像数据库并返回结果(后面是this tutorial)。我现在需要把这个链接到另一个网络抓取模块(使用Scrapy),在这个模块中,我在线输出大约1000个图片链接。这些图像分散在整个网络中,应该输入到第一个OpenCV模块中。是否可以在不下载的情况下对该联机图像集进行计算?在

这些是我在OpenCV模块中遵循的步骤

1)定义基于区域的彩色图像描述符

2)从数据集中提取特征(索引)(作为命令行参数传递的数据集)# import the necessary packages

import sys

sys.path.append('/usr/local/lib/python2.7/site-packages')

from colordescriptor import ColorDescriptor

import argparse

import glob

import cv2

# construct the argument parser and parse the arguments

ap = argparse.ArgumentParser()

ap.add_argument("-d", "--dataset", required = True,

help = "Path to the directory that contains the images to be indexed")

ap.add_argument("-i", "--index", required = True,

help = "Path to where the computed index will be stored")

args = vars(ap.parse_args())

# initialize the color descriptor

cd = ColorDescriptor((8, 12, 3))

# open the output index file for writing

output = open(args["index"], "w")

# use glob to grab the image paths and loop over them

for imagePath in glob.glob(args["dataset"] + "/*.jpg"):

# extract the image ID (i.e. the unique filename) from the image

# path and load the image itself

imageID = imagePath[imagePath.rfind("/") + 1:]

image = cv2.imread(imagePath)

# describe the image

features = cd.describe(image)

# write the features to file

features = [str(f) for f in features]

output.write("%s,%s\n" % (imageID, ",".join(features)))

# close the index file

output.close()

3)相似性度量的提取

^{pr2}$

`

4)进行实际搜索# import the necessary packages

from colordescriptor import ColorDescriptor

from searcher import Searcher

import sys

sys.path.append('/usr/local/lib/python2.7/site-packages')

import argparse

import cv2

# construct the argument parser and parse the arguments

ap = argparse.ArgumentParser()

ap.add_argument("-i", "--index", required = True,

help = "Path to where the computed index will be stored")

ap.add_argument("-q", "--query", required = True,

help = "Path to the query image")

ap.add_argument("-r", "--result-path", required = True,

help = "Path to the result path")

args = vars(ap.parse_args())

# initialize the image descriptor

cd = ColorDescriptor((8, 12, 3))

# load the query image and describe it

query = cv2.imread(args["query"])

features = cd.describe(query)

# perform the search

searcher = Searcher(args["index"])

results = searcher.search(features)

# display the query

cv2.imshow("Query", query)

# loop over the results

for (score, resultID) in results:

# load the result image and display it

result = cv2.imread(args["result_path"] + "/" + resultID)

cv2.imshow("Result", result)

cv2.waitKey(0)

最后的命令行命令是:python search.py --index index.csv --query query.png --result-path dataset

在哪里索引.csv是在图像数据库的步骤2之后生成的文件。查询.png是我的查询图像,dataset是包含~100个图像的文件夹。在

那么,是否可以修改索引以使我不需要本地数据集,并且可以直接从url列表中进行查询和索引?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值