give me a function,finds and returns list of corners and new image with corners drawn
时间: 2024-05-02 21:18:01 浏览: 14
As an AI language model, I do not have access to image processing libraries or frameworks. However, here is a Python function that takes an image as input, uses the Harris Corner Detection algorithm to find corners, draws them in the image, and returns the corners coordinates and the new image:
```python
import cv2
import numpy as np
def find_corners(image):
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
# Apply Harris Corner Detection algorithm
dst = cv2.cornerHarris(gray, 2, 3, 0.04)
# Normalize and threshold the result
dst_norm = np.empty_like(dst)
cv2.normalize(dst, dst_norm, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX)
dst_norm_thresh = cv2.threshold(dst_norm, 100, 255, cv2.THRESH_BINARY)[1]
# Find corners coordinates
corners = np.argwhere(dst_norm_thresh==255)
corners = [corner[::-1] for corner in corners]
# Draw corners in the image
image_with_corners = image.copy()
for corner in corners:
x,y = corner
cv2.circle(image_with_corners, (x,y), 5, (0,255,0), 2)
return corners, image_with_corners
```
To use this function, you can pass an image as input, and it will return a tuple with the corners coordinates and a new image with the corners drawn:
```python
image = cv2.imread("image.jpg")
corners, image_with_corners = find_corners(image)
cv2.imshow("Image with Corners", image_with_corners)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)