opencv-python icon indicating copy to clipboard operation
opencv-python copied to clipboard

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

Open danishkhangithub opened this issue 2 years ago • 8 comments

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.

danishkhangithub avatar Aug 28 '21 04:08 danishkhangithub

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

asmorkalov avatar Aug 30 '21 07:08 asmorkalov

@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 avatar Aug 30 '21 07:08 asmorkalov

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

asmorkalov avatar Sep 13 '21 06:09 asmorkalov

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.

danishkhangithub avatar Sep 13 '21 06:09 danishkhangithub

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

  • Your platform and how you install/build OpenCV
  • cv.getBuildInformation() call output in the repro code.
  • Any details how you run the code: natively, over SSH, etc.

asmorkalov avatar Sep 13 '21 06:09 asmorkalov

@danishkhangithub friendly reminder.

asmorkalov avatar Sep 21 '21 05:09 asmorkalov

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

asmorkalov avatar Oct 11 '21 09:10 asmorkalov

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

vishisht-dubey avatar Aug 17 '22 12:08 vishisht-dubey