1

Basically, I have a function in my view which when called renders the opencv webcam videocapture window. But the problem is that the window opens but behind my chrome browser window, i have to manually click on the icon in taskbar to open the window ahead of the browser. Simply, the Z-index of the Capture window should be greater than the browser window.

VIEW.PY

def face_recognition(request, eid):
    size = 4
    haar_file = 'C:\\Users\\Aayush\\ev_manage\\face_detector\\haarcascade_frontalface_default.xml'
    datasets = 'C:\\Users\\Aayush\\ev_manage\\face_detector\\static\\face_detector\\datasets'

    # Create a list of images and a list of corresponding names
    (images, lables, names, id) = ([], [], {}, 0)
    for (subdirs, dirs, files) in os.walk(datasets):
        for subdir in dirs:
            names[id] = subdir
            subjectpath = os.path.join(datasets, subdir)
            for filename in os.listdir(subjectpath):
                path = subjectpath + '/' + filename
                lable = id
                images.append(cv2.imread(path, 0))
                lables.append(int(lable))
            id += 1
    # (width, height) = (130, 100)

    # Create a Numpy array from the two lists above
    (images, lables) = [numpy.array(lis) for lis in [images, lables]]

    model = cv2.face.LBPHFaceRecognizer_create()
    model.train(images, lables)
    # Part 2: Use fisherRecognizer on camera stream
    face_cascade = cv2.CascadeClassifier(haar_file)
    webcam = cv2.VideoCapture(0)
    flag = 0
    d_id = 1000
    while True:
        (_, im) = webcam.read()
        gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
        faces = face_cascade.detectMultiScale(gray, 1.3, 5)
        for (x, y, w, h) in faces:
            cv2.rectangle(im, (x, y), (x + w, y + h), (255, 0, 0), 2)
            face = gray[y:y + h, x:x + w]
            # face_resize = cv2.resize(face, (width, height))
            face_resize = cv2.resize(face, None, fx=0.5, fy=0.5)
            # Try to recognize the face
            prediction = model.predict(face_resize)
            cv2.rectangle(im, (x, y), (x + w, y + h), (0, 255, 0), 3)

            if prediction[1] < 110:
                uid = Delegate.objects.get(dataset_id=names[prediction[0]])
                cv2.putText(im, '% s % s' %
                            (uid.first_name, uid.last_name), (x - -35, y - 20),
                            cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0))
            else:
                cv2.putText(im, 'Unable to Recognize',
                            (x - -35, y - 20), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0))

            if prediction[1] < 110:
                d_id = names[prediction[0]]
        #     break

        cv2.imshow('Recognizing Face...', im)

        key = cv2.waitKey(10)
        if key == 13:
            present_delegate(request, eid, d_id)
            break

    webcam.release()
    cv2.destroyAllWindows()
    func = delegate_det(request, d_id)
    return render(request, "face_recognition.html", {"eid": eid})

So is there any predefined method in the OpenCV library to force open the capture webcam window in a maximized form?

Aayush Gupta
  • 504
  • 1
  • 5
  • 28
  • Is something like this : ```cv2.namedWindow("Your Window",WINDOW_FULLSCREEN)```? – Yunus Temurlenk Jan 30 '20 at 07:56
  • it will only open the window in full screen mode but not in maximized form, the window will remain minimized on starting and i will have to manually click to open it – Aayush Gupta Jan 30 '20 at 07:59
  • u are not understanding , i dont have problem with the size of window. i just want when function is called the cv window should come on top of my browser window – Aayush Gupta Jan 30 '20 at 08:06
  • Sorry for misunderstanding before. When first called ```imshow``` , it will pop-up over the all windows. when disappeared and called again it will again pop-up over the others. There is not a specific function or property to do that because opencv is not a ui based tool. – Yunus Temurlenk Jan 30 '20 at 08:19
  • @YunusTemurlenk but in my case, it is not popping up over my browser window anytime – Aayush Gupta Jan 30 '20 at 08:30
  • I mean it ll pop-up at the first time program executed. When you click the browser window, the imshow window ll be again on background. To call it again you should run the program again or reexecute the program. I am using ubuntu I am not sure its different in different operating systems. – Yunus Temurlenk Jan 30 '20 at 08:34
  • but i am using windows, so i think we are thinking differently – Aayush Gupta Jan 30 '20 at 08:38
  • It sounds like your problem is probably more related to your computer settings rather than OpenCV. The default behavior of imshow is to display it as the primary window. I've only used Raspberry Pi and Linux so not sure what might be causing it on Windows. – Warpstar22 Jan 30 '20 at 21:37

0 Answers0