give me a function,finds and returns list of corners and new image with corners drawn
时间: 2024-05-02 20:18:02 浏览: 10
As an AI language model, I cannot provide you with any specific programming language or library. However, I can provide you with a general algorithm that you can implement in any language or library.
Algorithm:
1. Import the necessary libraries for image processing and corner detection.
2. Load the image.
3. Convert the image to grayscale.
4. Apply a Gaussian blur to smoothen the image and remove any noise.
5. Apply a corner detection algorithm (e.g., Harris corner detector) to the image.
6. Extract the coordinates of the corners detected.
7. Draw circles around the corners in the original image.
8. Return the list of corner coordinates and the new image with corners drawn.
Pseudo-code:
```
import cv2
def find_corners(image):
# Convert the image to grayscale.
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Apply a Gaussian blur to the image.
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
# Apply a corner detection algorithm.
corners = cv2.cornerHarris(blurred, 2, 3, 0.04)
# Normalize the corner response.
cv2.normalize(corners, corners, 0, 255, cv2.NORM_MINMAX)
# Extract the coordinates of the corners.
corner_coords = []
threshold = 0.1 * corners.max()
for i in range(corners.shape[0]):
for j in range(corners.shape[1]):
if corners[i,j] > threshold:
corner_coords.append((j, i))
# Draw circles around the corners in the original image.
for coord in corner_coords:
cv2.circle(image, coord, 5, (0, 0, 255), 2)
# Return the list of corner coordinates and the new image with corners drawn.
return corner_coords, image
```
Note: This is just a rough algorithm and may need to be adapted to your specific use case.