cv2.INTERSECT_NONE
时间: 2024-04-07 09:26:54 浏览: 18
cv2.INTERSECT_NONE是OpenCV库中的一个常量,用于表示两个矩形或轮廓之间的相交关系。具体来说,它表示两个矩形或轮廓没有相交部分。
在OpenCV中,可以使用cv2.intersectConvexConvex()函数来计算两个凸多边形之间的相交关系。该函数返回一个整数值,表示相交的类型。其中,cv2.INTERSECT_NONE就是其中之一,表示两个凸多边形没有相交部分。
相关问题
cv2.rotatedrectangleintersecti
on function is used to calculate the intersection area between two rotated rectangles. The function is called `cv2.rotatedRectangleIntersection(rect1, rect2)`. It takes two parameters, `rect1` and `rect2`, which represent the rotated rectangles.
Here is an example usage of the function:
```python
import cv2
import numpy as np
# Define the rotated rectangles
rect1 = ((100, 100), (200, 100), 30)
rect2 = ((150, 150), (100, 200), 45)
# Calculate the intersection area
intersection = cv2.rotatedRectangleIntersection(rect1, rect2)
# Check if there is an intersection
if intersection[0] == cv2.INTERSECT_NONE:
print("No intersection between the rectangles.")
elif intersection[0] == cv2.INTERSECT_PARTIAL:
print("Partial intersection between the rectangles.")
elif intersection[0] == cv2.INTERSECT_FULL:
print("Full intersection between the rectangles.")
# If there is an intersection, retrieve the intersection rectangle
if intersection[0] != cv2.INTERSECT_NONE:
intersection_rect = cv2.boxPoints(intersection[1])
intersection_rect = np.int0(intersection_rect)
```
In this example, `rect1` and `rect2` are defined as tuples representing the center coordinates, size (width and height), and rotation angle of each rectangle. The function returns a tuple with two elements. The first element represents the type of intersection (`INTERSECT_NONE`, `INTERSECT_PARTIAL`, or `INTERSECT_FULL`), and the second element is the intersection rectangle if there is an intersection.
Note that this function requires OpenCV library to be installed on your machine.
python opencv 图像对比_Python Opencv中用compareHist函数进行直方图比较对比图片
要使用compareHist函数进行图像直方图比较,需要先将要比较的两幅图像的直方图计算出来。具体步骤如下:
1. 导入必要的库:
```python
import cv2
import numpy as np
from matplotlib import pyplot as plt
```
2. 加载要比较的两幅图像:
```python
img1 = cv2.imread('image1.png')
img2 = cv2.imread('image2.png')
```
3. 将图像转为HSV空间,并计算直方图:
```python
hsv1 = cv2.cvtColor(img1, cv2.COLOR_BGR2HSV)
hsv2 = cv2.cvtColor(img2, cv2.COLOR_BGR2HSV)
hist1 = cv2.calcHist([hsv1], [0, 1], None, [180, 256], [0, 180, 0, 256])
hist2 = cv2.calcHist([hsv2], [0, 1], None, [180, 256], [0, 180, 0, 256])
```
其中,第一个参数是要计算直方图的图像,第二个参数是通道,[0, 1] 表示计算H和S通道的直方图,第三个参数是掩膜,这里不使用,第四个参数是直方图的大小,第五个参数是每个通道的取值范围。
4. 使用compareHist函数进行直方图比较:
```python
# 使用相关性比较方法
corr = cv2.compareHist(hist1, hist2, cv2.HISTCMP_CORREL)
print('Correlation:', corr)
# 使用卡方比较方法
chi = cv2.compareHist(hist1, hist2, cv2.HISTCMP_CHISQR)
print('Chi-Square:', chi)
# 使用交叉熵比较方法
cross = cv2.compareHist(hist1, hist2, cv2.HISTCMP_INTERSECT)
print('Intersection:', cross)
# 使用巴氏距离比较方法
bhat = cv2.compareHist(hist1, hist2, cv2.HISTCMP_BHATTACHARYYA)
print('Bhattacharyya:', bhat)
```
其中,第一个参数是要比较的直方图1,第二个参数是要比较的直方图2,第三个参数是比较方法,可以选择相关性、卡方、交叉熵或巴氏距离。
5. 可以将比较结果可视化:
```python
plt.subplot(121), plt.imshow(cv2.cvtColor(img1, cv2.COLOR_BGR2RGB))
plt.title('Image 1'), plt.xticks([]), plt.yticks([])
plt.subplot(122), plt.imshow(cv2.cvtColor(img2, cv2.COLOR_BGR2RGB))
plt.title('Image 2'), plt.xticks([]), plt.yticks([])
plt.show()
```
这样就可以使用Python Opencv中的compareHist函数进行图像直方图比较了。