Python OpenCV error encountered

Upon running the Python code provided below, an error message popped up:

Traceback (most recent call last):

File "C:\Users\smart-26\Desktop\예제\face.py", line 28, in

faces = face_cascade.detectMultiScale(grayframe, 1.1, 3, 0, (30, 30))

cv2.error: D:\Build\OpenCV\opencv->

3.2.0\modules\objdetect\src\cascadedetect.cpp:1681: error: (-215) !empty() in

function cv::CascadeClassifier::detectMultiScale

The error message that reads as follows remains unclear to me:

error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale

Below is the current state of my code:

import cv2

CAM_ID = (0)

cap = cv2.VideoCapture(CAM_ID)

if cap.isOpened() == False: 
    print ('Can\'t open the CAM(%d)' % (CAM_ID))
    exit()

face_cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")

while(True):
   
    ret, frame = cap.read()

    grayframe = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    grayframe = cv2.equalizeHist(grayframe)

    faces = face_cascade.detectMultiScale(grayframe, 1.1, 3, 0, (30, 30))
        for (x,y,w,h) in faces:
        cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),3, 4, 0)
   

    cv2.imshow('Face',frame)

   
    if cv2.waitKey(10) >= 0:
        break;


cv2.namedWindow('Face')
cap.release()
cv2.destroyWindow('Face')

Answer №1

Feel free to take a look at this useful link:

Don't forget to verify the output of cv2.CascadeClassifier. Double check that the file

haarcascade_frontalface_default.xml
is present.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Python-powered C/C++ Distributed Engine

Currently, I am utilizing a C based OCR engine called tesseract in conjunction with Python interface library pytesseract to leverage its primary functionalities. The library essentially accesses the local contents of the installed engine for utilization ...

Using Python's Selenium library with Chromedriver on Amazon Linux in an AWS Lambda environment

After successfully converting my locally running scraper to be compatible with aws lambda, I diligently followed various guides, tools, and examples for assistance: https://medium.com/@marco.luethy/running-headless-chrome-on-aws-lambda-fa82ad33a9eb https ...

Running FFmpeg command using Python on Raspberry PI device

I successfully used FFmpeg to record a video on my Raspberry PI. Below is the code snippet I utilized: ffmpeg -f video4linux2 -y -r 4 -i /dev/video0 -vf "drawtext=fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf:expansion=strftime:text=&a ...

Error: Unable to connect to Chrome while attempting to launch the ChromeDriver using Python's selenium

My current project involves using Selenium Chrome Webdriver to open a webpage in Python 3. I am interested in creating a function that can successfully open the desired webpage. Initially, I had the following code: driver = webdriver.Chrome(executable_pat ...

What is the best way to access a specific line in a text file using Python?

I possess a text file containing specific data Style="light mode" Tone="Red" My intention is to extract the value of Style from the text file using Python, which in this case is "light mode" with open("nxc.txt","r&qu ...

Python selenium.common.exceptions.WebDriverException: Error: Unable to connect to Chrome browser in Ubuntu 20.04 command line interface

Running Chrome using Selenium in Python is proving to be a challenge for me. Every time I attempt it, I encounter a stack trace dump and receive the message from Selenium: "chrome not reachable." Traceback (most recent call last): File "test_sel.py& ...

Explore additional pages using Selenium with Python by clicking below

Issue I am trying to access the profiles of all the top users on this page using Selenium. The profiles of the top users can be found on the right side of the page. Steps Taken self.driver.get(response.url) user_list = self.driver.find_elements_b ...

Challenges with Data Extraction on LinkedIn Sales Navigator

Attempting to extract information on various companies and their leads from the LinkedIn Sales Navigator has been a challenge for me. In order to log in, I have set up a textfile named config.txt which stores my username and password. However, each time I ...

Creating a hover effect for a mouse in PyQt5 simulation

Is there a way to simulate mouse hover for PyQt5 to a specific coordinate, possibly using QPoint? import sys from PyQt5.QtWidgets import QApplication from PyQt5.QtCore import Qt, QUrl, QTimer from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngine ...

`` `eliminate quotation marks in a json document with the help of python

On PowerBI, the 'dataset' dataframe is automatically generated. Below are the results of my dataset.head(10).to_clipboard(sep=',', index=False) coordinates,status "[143.4865219,-34.7560602]",not started "[143.4865241,-34.7561332]",not ...

Encountered an issue while trying to construct wheels for camel-kenlm

Encountering issues while attempting to install camel-tools for python3.8 on a MacOS device using: pip install camel-tools ERROR: There was a failure in building the wheel for camel-kenlm Failed to build camel-kenlm ERROR: Unable to create wheels for came ...

Django REST framework error: 'WSGIRequest' does not contain the attribute 'query_params'

Currently, I am in the process of learning about DRF. One thing I attempted was to print out print request.query_params, but unfortunately encountered an error: print request.query_params AttributeError: 'WSGIRequest' object has no attribute ...

I am unsure whether Django or Drupal would be the best fit for my requirements

My interest lies in mastering either Drupal or Django to create dynamic websites with medium databases, multi-level users, PayPal integration, content management, fast development speed, and security features. I have a preference for MVC, ORM, and object-o ...

Exploring Python's doctest to differentiate between matching single or double quotes in output instead of just single quotes

My go-to tool for formatting code is the Black auto-formatter, and it has ingrained in me the habit of using double quotes. Using double quotes has become second nature to me. By default, many classes' repr output in Python uses single quotes when pr ...

Adding Retrieved Information to DataFrame in Python Using Selenium

I'm currently learning about web scraping and practicing on the Eat24 website (Yelp's platform). While I have been successful in extracting basic data from Yelp, I am encountering a challenge when trying to append this data to a dataframe. Below ...

Exploring directories with os.walk while utilizing a variable

Currently, I am exploring the concept of passing variables by developing a small script that copies all files from an input directory path and moves them to another folder. I have created a function to validate the user-provided input path, which I intend ...

Unable to interact with element on the following page using Selenium in Python

Attempting to extract data from multiple pages of a URL using Selenium in Python, but encountering an error after the first page. The code successfully navigates to the subsequent pages but fails to scrape, throwing an error message: "Element ... is not ...

Utilize a function on the elements within a data table's column

Currently, I have a functioning function that utilizes a mapping API to return longitude and latitude coordinates based on unstructured address data. When I input an address like "12 & 14 CHIN BEE AVENUE,, SINGAPORE 619937", I receive the output 1.3332439 ...

What seems to be the issue with this json.load function call?

I wrote the following Python 3 code snippet: import json with open('calldb.json', 'r') as G: data = json.load(G) print(data) Accompanied by this JSON file: [ { "n": { "identity": 0, "labels": [ ...

The error returned by Pandas value_counts depends on the data type of the series

What is the reason behind the key error at 0 in the first DataFrame? import pandas as pd t1 = pd.DataFrame({'c1':[1,2,2,1]}) t1.c1.value_counts()[0] # key error: 0 t2 = pd.DataFrame({'c1':['a','b','b' ...