I try start my code, but process finishes on step with method cv2.namedWindow (without any errors). Do you have any suggestions, why it could be so?
import cv2
image_cv2 = cv2.imread('/home/spartak/PycharmProjects/python_base/lesson_016/python_snippets/external_data/girl.jpg')
def viewImage(image, name_of_window):
print('step_1')
cv2.namedWindow(name_of_window, cv2.WINDOW_NORMAL)
print('step_2')
cv2.imshow(name_of_window, image)
print('step_3')
cv2.waitKey(0)
print('step_4')
cv2.destroyAllWindows()
cropped = image_cv2
viewImage(cropped, 'Cropped version')
P.S.: Also I erased UBUNTU , and installed Fedora. Instead Pycharm, check programm on VS code. But nothing changes. I changed location for picture (girl.jpg) to directory with python document. But program stops on step1 and waiting something.
CodePudding user response:
The code completes all 4 steps for me
I think there is a problem with the image path which you took
The function cv2.namedWindow creates a window that can be used as a placeholder for images and trackbars. Created windows are referred to by their names If a window with the same name already exists, the function does nothing.
CodePudding user response:
I do think the function cv2.destroyAllWindows This function is deallocating some needed gui elements, I would guess. So calling this multiple times will produce some trouble.
import cv2
image_cv2 = cv2.imread('foo.jpg')
def viewImage(image, name_of_window):
print('step_1')
cv2.namedWindow(name_of_window)
print('step_2')
cv2.imshow(name_of_window, image)
print('step_3')
cv2.waitKey(0)
#print('step_4')
#cv2.destroyAllWindows()
cropped = image_cv2
viewImage(cropped, 'Cropped version')
#e.g. better usage at the end of the code or section
cv2.destroyAllWindows()