opencv / opencv-python

Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.
https://pypi.org/project/opencv-python/
MIT License
4.35k stars 822 forks source link

opencv not terminating in shell or in jupyter notebook after inshow display image #532

Open danishkhangithub opened 2 years ago

danishkhangithub commented 2 years ago

this is the code

# import libraries
import cv2

def face_detection():
    # load some pre-trained data on face frontals from opencv (haar cascade algorithm)
    trained_face_data = cv2.CascadeClassifier('./haarcascade_files/haarcascade_frontalface_default.xml')

    # show an image to detect
    cv2.namedWindow('output', cv2.WINDOW_AUTOSIZE)
    img = cv2.imread('./images/rdj.jpg')
    #ims = cv2.resize(img, (110, 540))
    cv2.imshow('Face detector', img)

    cv2.waitKey(0)

    cv2.destroyAllWindows()

    print('completed')

if __name__ == '__main__':
   face_detection()`

and the output is :

(scrpers) (base) danish-khan@danishkhan-Latitude-E6430:~/scrapers/machine_learning1/face_detection1$ python face_detection2.py

and this terminal is not ending even i forcefully want to ends it.

asmorkalov commented 2 years ago

Possibly related: https://github.com/opencv/opencv/pull/20597

asmorkalov commented 2 years ago

@danishkhangithub Thanks for the report.

  1. OpenCV handles window closing by (x) button in title incorrectly sometimes. Your code expects keyboard event in waitKey call.
  2. If 1. is not the case, please remove destroyAllWindows and try again.
  3. Please take a look on related fix I posted. Most probably it fixes the issue. You have to rebuild OpenCV from sources and remove pip-managed packages for OpenCV to exclude conflicts. Please ensure that self-built OpenCV is used with cv.getBuildInformation() call.
asmorkalov commented 2 years ago

@danishkhangithub Have you had a chance to try the solution?

danishkhangithub commented 2 years ago

yes it tried but still not work may this is the issue.

On Mon, Sep 13, 2021 at 11:29 AM Alexander Smorkalov < @.***> wrote:

@danishkhangithub https://github.com/danishkhangithub Have you had a chance to try the solution?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/opencv/opencv-python/issues/532#issuecomment-917881914, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ45NZPDT5P7Z2QL3VBJSP3UBWK6LANCNFSM5C6WM72Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

asmorkalov commented 2 years ago

could you give me more information to narrow down the search field:

asmorkalov commented 2 years ago

@danishkhangithub friendly reminder.

asmorkalov commented 2 years ago

Possibly related: https://github.com/opencv/opencv/issues/20822

vishisht-dubey commented 1 year ago

Hey, I want to work on this issue can u provide some more info??