I'm new to Python.
I wanted to rotate the image from the center and tried it while watching the internet, but I don't know what the error message was giving an error.
In the code below, the error spit out was the eleventh line, undefined name 'identity'.
import matplotlib.pyplot as plt
def rotate_center (image, angle):
h, w = image.shape [: 2]
affine = cv2.getRotationMatrix2D ((w/2.0, h/2.0), angle, 1.0)
return cv2.warpAffine (image, affine, (w, h))
image = cv2.imread ("mizu.jpg") [:,:, ::-1]
converted = identity (image)
When I looked into it, it came out that there was a variable error, not being defined, etc., but if I don't check how to define a variable in Python, is it defined without permission? I do not understand because it is written.
I tried to rewrite the characters for strange spaces, but the error did not change.
And even if you look at the site described at the end, it is not described because it is not described where the rotation angle of the image is decided, so I am very sorry, but I would appreciate it if someone could tell me.
Answer # 1
Even if you say
identity (image)is a function that performs "1. Identity transformation" in the reference site.
The error is that "
identityis not defined", but when you look at the code in the question, the function is not defined (copy and paste).
, you don't need to actually define (copy and paste), and what you want to do is "12. Rotate from the center of the image" in the reference site code>must be called from
__ main __.
import cv2 import matplotlib.pyplot as plt import numpy as np def rotate_center (image, angle): h, w = image.shape [: 2] affine = cv2.getRotationMatrix2D ((w/2.0, h/2.0), angle, 1.0) return cv2.warpAffine (image, affine, (w, h)) if __name__ == "__main__": image = cv2.imread ("mizu.jpg") [:,:, ::-1] # 30 is the rotation angle converted = rotate_center (image, 30) plt.imshow (converted) plt.title ("Rotate Center") plt.show ()
I haven't checked the actual operation, but I think it will work.
- python - about image display and position of main ()
- python - i want to find the average hsv value for each divided image
- python - image field image output
- python - overwriting the image when the background is selected
- python - garbled characters of ˚c in the image
- [python37] i want to output the center coordinates of two minimum circumscribed circles
- python - resize image to square
- vba - i want to place an image in the center of a merged cell
- html - i want to put the text and background color in the center of the image and display the image in that frame when hovering
- python - how to display an image, make a selection, and process by selection
- python - i want to compare images and find the same image
- image recognition using python beginner pyautogui is not possible
- python - pygame image drawing doesn't work
- python - i want to divide the image into grids and find the hsv value
- [python] i want to paste an image on canvas
- c ++ - i would like to know how to rotate with the center of the block as the origin by rotation by primary rotation with tetris
- i want to read an image file with python using pillow
- html - the image does not come to the center of the left and right in the div
- i want to display an image using opencv from python
- python image size compression
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- python - you may need to restart the kernel to use updated packages error
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- i want to call a child component method from a parent in vuejs