-1

I was working on a hand-tracking module from a course offered by free code camp.where I encountered with a issue. The Output window does not open whenever I run my code. When I run The code this is what I get:

Screen shot when I run the program

The code for the program is :

import cv2
import mediapipe as mp
import time


class FaceDetector():
    def __init__(self, minDetectionCon = 0.5):
        self.minDetectionCon = minDetectionCon

        self.mpFaceDetection = mp.solutions.face_detection
        self.mpDraw = mp.solutions.drawing_utils
        self.faceDetection = self.mpFaceDetection.FaceDetection(0.75)

    def findFaces(self, img, draw = True):

        imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        self. results = self.faceDetection.process(imgRGB)
        print(self.results)
        bboxs = []

        if self.results.detections:
            for id, detection in enumerate(self.results.detections):
                bboxC = detection.location_data.relative_bounding_box
                ih, iw, ic = img.shape
                bbox = int(bboxC.xmin * iw), int(bboxC.ymin * ih), \
                       int(bboxC.width * iw), int(bboxC.height * iw)
                bboxs.append([bbox, detection.score])

                cv2.rectangle(img, bbox, (255, 0, 255), 2)
                cv2.putText(img, f':{int(detection.score[0]*100)}%',
                            (bbox[0],bbox[1]-20), cv2.FONT_HERSHEY_PLAIN,
                            2, (255, 0, 255), 2)
        return img, bboxs

def main():
    cap = cv2.VideoCapture(0)
    pTime = 0
    detector = FaceDetector()
    while True:
        success, img = cap.read()
        img, bboxs = detector.findFaces(img, bboxs)

        cTime = time.time()
        fps = 1 / (cTime - pTime)
        pTime = cTime
        cv2.putText(img, f'fps:{int(fps)}', (20, 70), cv2.FONT_HERSHEY_PLAIN,
                    3, (0, 255, 0), 2)
        cv2.imshow('image', img)
        cv2.waitKey(1)


if __name__ == "__mian__":
    main()
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Manas17_
  • 1
  • 1
  • it's a **typo**. you wrote `__mian__` instead of `__main__`. you did not debug your code. learn how: https://ericlippert.com/2014/03/05/how-to-debug-small-programs/ you should review [ask] and [mre] and [help/on-topic]. – Christoph Rackwitz Aug 17 '22 at 14:55

1 Answers1

0

Typo:

if __name__ == "__mian__":
Fiddling Bits
  • 8,712
  • 3
  • 28
  • 46
  • 1
    you should also vote to close as typo. you have enough rep to (know to) do that. typo-questions may be commented on to point the issue out, but posting an answer is discouraged. https://meta.stackoverflow.com/questions/366135/should-you-answer-questions-where-the-cause-of-the-problem-is-a-typo – Christoph Rackwitz Aug 17 '22 at 14:54
  • I expected OP to delete this question. – Fiddling Bits Aug 17 '22 at 15:00
  • 1
    the problem with _answering_ such questions is that it may _prevent_ OP from deleting the question (and prevents automatic housekeeping bots from removing the question). and you get rep for pointing out mistakes due to simple inattention, which is _not_ what this site is about. – Christoph Rackwitz Aug 17 '22 at 15:03
  • @Manas17_ `if __name__ == "__main__":` is really only necessary if you plan on `import`ing your module. – Fiddling Bits Aug 17 '22 at 15:04
  • sorry for the inconvenience everyone faced and taking your time. I was stuck for a long time and didn't realize it was a typo my sincere apology. – Manas17_ Aug 17 '22 at 15:13
  • @Manas17_ No need to apologize, at least to me. – Fiddling Bits Aug 17 '22 at 15:15