Image 有兴趣在不使用openCV的情况下区分图像中的正方形和矩形吗
我有一个由矩形和正方形组成的图像,现在我感兴趣的是区分图像中哪个是矩形,哪个是正方形。我使用了Harris角点检测算法来提取角点。使用这些角点,我能够提取这些角点像素的索引。我感兴趣的下一个任务是区分哪个是矩形,哪个是正方形?我知道正方形Image 有兴趣在不使用openCV的情况下区分图像中的正方形和矩形吗,image,image-processing,computer-vision,feature-extraction,feature-detection,Image,Image Processing,Computer Vision,Feature Extraction,Feature Detection,我有一个由矩形和正方形组成的图像,现在我感兴趣的是区分图像中哪个是矩形,哪个是正方形。我使用了Harris角点检测算法来提取角点。使用这些角点,我能够提取这些角点像素的索引。我感兴趣的下一个任务是区分哪个是矩形,哪个是正方形?我知道正方形高度=宽度的条件。使用这些信息,我想执行差异化 请问对OpenCV有什么异议?另外,不是使用有损的JPEG,是否考虑使用PNG,以便在处理过程中正确保存您的值?@ MARSETSECHELL,如果我开始使用OpenCV,那么我就无法理解CV2中的函数是如何工作
高度=宽度的条件。使用这些信息,我想执行差异化
请问对OpenCV有什么异议?另外,不是使用有损的JPEG,是否考虑使用PNG,以便在处理过程中正确保存您的值?@ MARSETSECHELL,如果我开始使用OpenCV,那么我就无法理解CV2中的函数是如何工作的。此外,我对从头开始学习很感兴趣。与JPEG相比,PNG有什么优势?请详细说明一下。PNG有很多优势。1) 它可以处理16位/样本,而JPEG只能处理8位2)它的损耗较小,因此您可以准确地返回您写入的值,而如果您在纯蓝色背景上创建一个纯红色矩形并另存为JPEG,则如果您另存为JPEG并从磁盘读取,则可能会得到一个具有数百种颜色的图像。3) 它可以处理透明度问题。4) 它可以本地轻松处理灰度图像。
mport numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as im
from scipy import ndimage
# 1. Before doing any operations convert the image into gray scale image
img = im.imread('OD6.jpg')
plt.imshow(img)
plt.show()
# split
R=img[:,:,0]
G=img[:,:,1]
B=img[:,:,2]
M,N=R.shape
gray_img=np.zeros((M,N), dtype=int);
for i in range(M):
for j in range(N):
gray_img[i, j]=(R[i, j]*0.2989)+(G[i, j]*0.5870)+(B[i, j]*0.114);
plt.imshow(gray_img, cmap='gray')
plt.show()
# 2. Applying sobel filter to find the gradients in x and y direction respectively and remove noise
# using gaussian filter with sigma=1
imarr = np.asarray(gray_img, dtype=np.float64)
ix = ndimage.sobel(imarr, 0)
iy = ndimage.sobel(imarr, 1)
ix2 = ix * ix
iy2 = iy * iy
ixy = ix * iy
ix2 = ndimage.gaussian_filter(ix2, sigma=1)
iy2 = ndimage.gaussian_filter(iy2, sigma=1)
ixy = ndimage.gaussian_filter(ixy, sigma=1)
c, l = imarr.shape
result = np.zeros((c, l))
r = np.zeros((c, l))
rmax = 0 # initialize the maximum value of harris response
for i in range(c):
for j in range(l):
m = np.array([[ix2[i, j], ixy[i, j]], [ixy[i, j], iy2[i, j]]], dtype=np.float64)
r[i, j] = np.linalg.det(m) - 0.04 * (np.power(np.trace(m), 2))
if r[i, j] > rmax:
rmax = r[i, j]
# 3. Applying non maximum supression
for i in range(c - 1):
for j in range(l - 1):
if r[i, j] > 0.01 * rmax and r[i, j] > r[i-1, j-1] and r[i, j] > r[i-1, j+1]\
and r[i, j] > r[i+1, j-1] and r[i, j] > r[i+1, j+1]:
result[i, j] = 1
xy_coords = np.flip(np.column_stack(np.where(result==1)), axis=1)
print (xy_coords)
pc, pr = np.where(result == 1)
plt.plot(pr, pc, "b.")
plt.imshow(img, 'gray')
plt.show()