您的位置:

python特征点匹配(python查找特征数)

本文目录一览:

Python中正则表达式的匹配规则总结

其他关于Python的总结文章请访问:

正则表达式用来匹配字符串,在python中可以使用 re 模块来完成,本篇做一个对正则表达式的匹配规则的总结

在上述的精确匹配后可以跟上一些符号来进行模糊的匹配:

可以使用中括号的形式进行范围匹配,中括号表达式后边可以跟上上述模糊匹配的符号来表示数量

多个条件可以 紧跟着写在同一个中括号中 ,比如:

[a-zA-Z] :匹配一个大、小写字母

python指纹图像细化后如何进行特征点匹配

thin’这个参数就指定了对二值图像BW进行细化操作,inf(无穷大)这个参数说的是对图像一直进行细化,直到图像不再发生变化为止。

Python编程语言有哪些特征?

Python语言的主要特征如下:

①Python语法优雅,程序编码简单易读。

②Python易上手,通过简单的操作就能让你写的程序运行。Python非常适合用来做原型开发或其他专门的编码任务,同时又不用为了维护而烦恼。

③Python拥有大量的标准库来支持一般的编码任务,例如连接网络服务器、用正则表达式搜索文字、读取和修改文件等。

④Python的交互模式可以很方便地检测代码片段。同时Python其实也自带了一个叫做IDLE的集成开发环境,初学者可以利用它方便地创建、运行、测试和调试Python程序。

⑤Python通过添加新的模块可以很容易进行扩展,这些模块可以是通过类似C或C++等编译型语言执行应用的。注意,Python是解释型脚本语言。

⑥Python也可以被嵌入应用中来提供一个可编程的接口。

⑦Python可以在任何环境运行,包括Mac OS X,Windows,Linux和Unix,通过非官方的构建,也可以在android和ios上运行。

⑧Python双重免费。首先下载和使用或是在你的应用中内置Python是完全免费的。其次Python可以被自由修改然后再发布,因为语言是完全开源的。

Python如何实现图片特征点匹配

python-opencv-特征点匹配连线(画线)drawMatches

Python 没有OpenCV 2.4.13版本的cv2.drawMatches(),无法直接使用,故可参看本文第2节的drawMatches函数使用

Python 有OpenCV 3.0.0版本的cv2.drawMatches(),可以直接使用

1、drawMatches数据结构(opencv2.4.13)

Draws the found matches of keypoints from two images.

C++:

void drawMatches(const Mat img1, const vectorKeyPoint keypoints1, const Mat img2, const vectorKeyPoint keypoints2, const vectorvectorDMatch matches1to2, Mat outImg, const Scalar matchColor=Scalar::all(-1), const Scalar singlePointColor=Scalar::all(-1), const vectorvectorchar matchesMask=vectorvectorchar (), int flags=DrawMatchesFlags::DEFAULT )1

Parameters: 

img1 – First source image.

keypoints1 – Keypoints from the first source image.

img2 – Second source image.

keypoints2 – Keypoints from the second source image.

matches1to2 – Matches from the first image to the second one, which means that keypoints1[i] has a corresponding point in keypoints2[matches[i]] . 

outImg – Output image. Its content depends on the flags value defining what is drawn in the output image. See possible flags bit values below.

matchColor – Color of matches (lines and connected keypoints). If matchColor==Scalar::all(-1) , the color is generated randomly. 

singlePointColor – Color of single keypoints (circles), which means that keypoints do not have the matches. If singlePointColor==Scalar::all(-1) , the color is generated randomly.

matchesMask – Mask determining which matches are drawn. If the mask is empty, all matches are drawn.

flags – Flags setting drawing features. Possible flags bit values are defined by DrawMatchesFlags. 

This function draws matches of keypoints from two images in the output image. Match is a line connecting two keypoints (circles). The structure DrawMatchesFlags is defined as follows:

struct DrawMatchesFlags

{

   enum

   {

       DEFAULT = 0, // Output image matrix will be created (Mat::create),

                    // i.e. existing memory of output image may be reused.

                    // Two source images, matches, and single keypoints

                    // will be drawn.

                    // For each keypoint, only the center point will be

                    // drawn (without a circle around the keypoint with the

                    // keypoint size and orientation).

       DRAW_OVER_OUTIMG = 1, // Output image matrix will not be

                      // created (using Mat::create). Matches will be drawn

                      // on existing content of output image.

       NOT_DRAW_SINGLE_POINTS = 2, // Single keypoints will not be drawn.

       DRAW_RICH_KEYPOINTS = 4 // For each keypoint, the circle around

                      // keypoint with keypoint size and orientation will

                      // be drawn.

   };};1234567891011121314151617181920

2、drawMatches(python实现)

# -*- coding: utf-8 -*-"""

Created on Tue Dec 27 09:32:02 2016

@author:

"""def drawMatches(img1, kp1, img2, kp2, matches):

   """

   My own implementation of cv2.drawMatches as OpenCV 2.4.9

   does not have this function available but it's supported in

   OpenCV 3.0.0

   This function takes in two images with their associated

   keypoints, as well as a list of DMatch data structure (matches)

   that contains which keypoints matched in which images.

   An image will be produced where a montage is shown with

   the first image followed by the second image beside it.

   Keypoints are delineated with circles, while lines are connected

   between matching keypoints.

   img1,img2 - Grayscale images

   kp1,kp2 - Detected list of keypoints through any of the OpenCV keypoint

             detection algorithms

   matches - A list of matches of corresponding keypoints through any

             OpenCV keypoint matching algorithm

   """

   # Create a new output image that concatenates the two images together

   # (a.k.a) a montage

   rows1 = img1.shape[0]

   cols1 = img1.shape[1]

   rows2 = img2.shape[0]

   cols2 = img2.shape[1]

   out = np.zeros((max([rows1,rows2]),cols1+cols2,3), dtype='uint8')    # Place the first image to the left

   out[:rows1,:cols1] = np.dstack([img1, img1, img1])    # Place the next image to the right of it

   out[:rows2,cols1:] = np.dstack([img2, img2, img2])    # For each pair of points we have between both images

   # draw circles, then connect a line between them

   for mat in matches:        # Get the matching keypoints for each of the images

       img1_idx = mat.queryIdx

       img2_idx = mat.trainIdx        # x - columns

       # y - rows

       (x1,y1) = kp1[img1_idx].pt

       (x2,y2) = kp2[img2_idx].pt        # Draw a small circle at both co-ordinates

       # radius 4

       # colour blue

       # thickness = 1

       a = np.random.randint(0,256)

       b = np.random.randint(0,256)

       c = np.random.randint(0,256)

       cv2.circle(out, (int(np.round(x1)),int(np.round(y1))), 2, (a, b, c), 1)      #画圆,cv2.circle()参考官方文档

       cv2.circle(out, (int(np.round(x2)+cols1),int(np.round(y2))), 2, (a, b, c), 1)        # Draw a line in between the two points

       # thickness = 1

       # colour blue

       cv2.line(out, (int(np.round(x1)),int(np.round(y1))), (int(np.round(x2)+cols1),int(np.round(y2))), (a, b, c), 1, lineType=cv2.CV_AA, shift=0)  #画线,cv2.line()参考官方文档

   # Also return the image if you'd like a copy

   return out

Python正则表达式的几种匹配方法

1.测试正则表达式是否匹配字符串的全部或部分

regex=ur"" #正则表达式

if re.search(regex, subject):

do_something()

else:

do_anotherthing()

2.测试正则表达式是否匹配整个字符串

regex=ur"/Z" #正则表达式末尾以/Z结束

if re.match(regex, subject):

do_something()

else:

do_anotherthing()

3.创建一个匹配对象,然后通过该对象获得匹配细节(Create an object with details about how the regex matches (part of) a string)

regex=ur"" #正则表达式

match = re.search(regex, subject)

if match:

# match start: match.start()

# match end (exclusive): atch.end()

# matched text: match.group()

do_something()

else:

do_anotherthing()

4.获取正则表达式所匹配的子串(Get the part of a string matched by the regex)

regex=ur"" #正则表达式

match = re.search(regex, subject)

if match:

result = match.group()

else:

result = ""

OpenCV-Python之——图像SIFT特征提取

在一定的范围内,无论物体是大还是小,人眼都可以分辨出来。然而计算机要有相同的能力却不是那么的容易,在未知的场景中,计算机视觉并不能提供物体的尺度大小,其中的一种方法是把物体不同尺度下的图像都提供给机器,让机器能够对物体在不同的尺度下有一个统一的认知。在建立统一认知的过程中,要考虑的就是在图像在不同的尺度下都存在的特征点。

在早期图像的多尺度通常使用图像金字塔表示形式。图像金字塔是同一图像在不同的分辨率下得到的一组结果其生成过程一般包括两个步骤:

多分辨率的图像金字塔虽然生成简单,但其本质是降采样,图像的局部特征则难以保持,也就是无法保持特征的尺度不变性。

我们还可以通过图像的模糊程度来模拟人在距离物体由远到近时物体在视网膜上成像过程,距离物体越近其尺寸越大图像也越模糊,这就是高斯尺度空间,使用不同的参数模糊图像(分辨率不变),是尺度空间的另一种表现形式。

构建尺度空间的目的是为了检测出在不同的尺度下都存在的特征点,而检测特征点较好的算子是Δ^2G(高斯拉普拉斯,LoG)

使用LoG虽然能较好的检测到图像中的特征点,但是其运算量过大,通常可使用DoG(差分高斯,Difference of Gaussina)来近似计算LoG。

从上式可以知道,将相邻的两个高斯空间的图像相减就得到了DoG的响应图像。为了得到DoG图像,先要构建高斯尺度空间,而高斯的尺度空间可以在图像金字塔降采样的基础上加上高斯滤波得到,也就是对图像金字塔的每层图像使用不同的参数σ进行高斯模糊,使每层金字塔有多张高斯模糊过的图像。

如下图,octave间是降采样关系,且octave(i+1)的第一张(从下往上数)图像是由octave(i)中德倒数第三张图像降采样得到。octave内的图像大小一样,只是高斯模糊使用的尺度参数不同。

对于一幅图像,建立其在不同尺度scale下的图像,也称为octave,这是为了scale-invariant,也就是在任何尺度都能有对应的特征点。下图中右侧的DoG就是我们构建的尺度空间。

为了寻找尺度空间的极值点,每一个采样点要和它所有的相邻点比较,看其是否比它的图像域和尺度域的相邻点大或者小。如图所示,中间的检测点和它同尺度的8个相邻点和上下相邻尺度对应的9×2个点共26个点比较,以确保在尺度空间和二维图像空间都检测到极值点。 一个点如果在DOG尺度空间本层以及上下两层的26个领域中是最大或最小值时,就认为该点是图像在该尺度下的一个特征点。下图中将叉号点要比较的26个点都标为了绿色。

找到所有特征点后, 要去除低对比度和不稳定的边缘效应的点 ,留下具有代表性的关键点(比如,正方形旋转后变为菱形,如果用边缘做识别,4条边就完全不一样,就会错误;如果用角点识别,则稳定一些)。去除这些点的好处是增强匹配的抗噪能力和稳定性。最后,对离散的点做曲线拟合,得到精确的关键点的位置和尺度信息。

近来不断有人改进,其中最著名的有 SURF(计算量小,运算速度快,提取的特征点几乎与SIFT相同)和 CSIFT(彩色尺度特征不变变换,顾名思义,可以解决基于彩色图像的SIFT问题)。

其中sift.detectAndCompute()函数返回kp,des。

上图dog的shape为(481, 500, 3),提取的特征向量des的shape为(501, 128),501个128维的特征点。

该方法可以在特征点处绘制一个小圆圈。