i dont know why i am getting this error i have installed every thing but still please help please
here’s the error
Traceback (most recent call last):
File "main.py", line 1, in <module>
import cv2
File "/home/runner/Python-Beta-LSP-1/venv/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/home/runner/Python-Beta-LSP-1/venv/lib/python3.10/site-packages/cv2/__init__.py", line 111, in bootstrap
load_first_config(['config.py'], True)
File "/home/runner/Python-Beta-LSP-1/venv/lib/python3.10/site-packages/cv2/__init__.py", line 109, in load_first_config
raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.
my code
import cv2
def remove_background(image_path):
# Load the image
image = cv2.imread(image_path)
# Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Apply a threshold to create a binary image
_, binary = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
# Find contours in the binary image
contours, _ = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# Create a mask with the same shape as the image
mask = np.zeros_like(image)
# Draw the contours on the mask
cv2.drawContours(mask, contours, -1, (255, 255, 255), thickness=cv2.FILLED)
# Apply the mask to the image
result = cv2.bitwise_and(image, mask)
# Return the result
return result
# Example usage
image_path = "Removebg.jpg"
result = remove_background(image_path)
cv2.imshow("Result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()