Create 4
This commit is contained in:
1 parent
6abe2b069c
commit
8bcef951e3
3 files changed
+89
No files matched your search
@@ -0,0 +1,23 @@
|
|||||||
|
import cv2 as cv
|
||||||
|
import numpy as np
|
||||||
|
from matplotlib import pyplot as plt
|
||||||
|
|
||||||
|
image = cv.imread("images/lena.png")
|
||||||
|
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
|
||||||
|
gray = np.float32(gray)
|
||||||
|
|
||||||
|
block_size = 2
|
||||||
|
sobel_size = 3
|
||||||
|
k = 0.04
|
||||||
|
|
||||||
|
corners_img = cv.cornerHarris(gray, block_size, sobel_size, k) # type: ignore
|
||||||
|
|
||||||
|
indices = np.argsort(corners_img.flatten())[::-1][:50]
|
||||||
|
coords = np.column_stack(np.unravel_index(indices, corners_img.shape))
|
||||||
|
for coord in coords:
|
||||||
|
cv.circle(image, (coord[1], coord[0]), 3, (255, 0, 0), 1)
|
||||||
|
|
||||||
|
plt.imshow(image)
|
||||||
|
plt.axis("off")
|
||||||
|
plt.tight_layout()
|
||||||
|
plt.show()
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import cv2 as cv
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
img = cv.imread("images/lena.png")
|
||||||
|
cv.imshow("raw_img", img)
|
||||||
|
|
||||||
|
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
|
||||||
|
gray = np.float32(gray)
|
||||||
|
|
||||||
|
J = (0.05, 0.01, 0.005)
|
||||||
|
|
||||||
|
for j in J:
|
||||||
|
dst = cv.cornerHarris(gray, 2, 3, 0.04) # type: ignore
|
||||||
|
a = dst > j * dst.max()
|
||||||
|
for r in range(a.shape[0]):
|
||||||
|
for c in range(a.shape[1]):
|
||||||
|
if a[r, c] != 0:
|
||||||
|
cv.circle(img, (c, r), 1, (0, 0, 255), 1)
|
||||||
|
cv.imshow("corners_" + str(j), img)
|
||||||
|
cv.waitKey(0)
|
||||||
|
|
||||||
|
cv.waitKey(0)
|
||||||
|
cv.destroyAllWindows()
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import cv2 as cv
|
||||||
|
|
||||||
|
|
||||||
|
def build_gaussian_pyramid(image, octaves, scales):
|
||||||
|
gaussian_pyramid = []
|
||||||
|
for o in range(octaves):
|
||||||
|
octave_images = []
|
||||||
|
for s in range(scales):
|
||||||
|
if s == 0:
|
||||||
|
if o == 0:
|
||||||
|
octave_images.append(image)
|
||||||
|
else:
|
||||||
|
octave_images.append(cv.pyrDown(gaussian_pyramid[o - 1][-3]))
|
||||||
|
else:
|
||||||
|
sigma = 1.6 * (2 ** (s / scales))
|
||||||
|
blurred = cv.GaussianBlur(octave_images[0], (5, 5), sigma)
|
||||||
|
octave_images.append(blurred)
|
||||||
|
|
||||||
|
gaussian_pyramid.append(octave_images)
|
||||||
|
return gaussian_pyramid
|
||||||
|
|
||||||
|
|
||||||
|
def build_dog_pyramid(gaussian_pyramid):
|
||||||
|
dog_pyramid = []
|
||||||
|
for octave in gaussian_pyramid:
|
||||||
|
dog_images = []
|
||||||
|
for s in range(len(octave) - 1):
|
||||||
|
dog_images.append(octave[s + 1] - octave[s])
|
||||||
|
dog_pyramid.append(dog_images)
|
||||||
|
return dog_pyramid
|
||||||
|
|
||||||
|
|
||||||
|
image = cv.imread("images/lena.jpg", cv.IMREAD_GRAYSCALE)
|
||||||
|
guassian_pyramid = build_gaussian_pyramid(image, octaves=4, scales=5)
|
||||||
|
dog_pyramid = build_dog_pyramid(guassian_pyramid)
|
||||||
|
|
||||||
|
for i in range(len(dog_pyramid)):
|
||||||
|
for j in range(len(dog_pyramid[i])):
|
||||||
|
cv.namedWindow("DoG pyramid image %d %d" % (i, j))
|
||||||
|
cv.imshow("DoG pyramid image %d %d" % (i, j), dog_pyramid[i][j])
|
||||||
|
|
||||||
|
cv.waitKey(0)
|
||||||
|
cv.destroyAllWindows()
|
||||||
Reference in new issue
Block a user