Question:
I am unable to get opencv-python to work on REPL.it even though the packages are showing as installed. Receiving the following error:
File “/home/runner/OptimisticProudGenerics/venv/lib/python3.8/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.
any suggestions?
My test code looks like the following:
import cv2
import pathlib
# Step 0: Read Image from a file
file = pathlib.Path(__file__).parent.resolve() / input("Enter image name in same directory: ")
image1 = cv2.imread(str(file))
# Shows image on the screen until any button is pressed then closes windows
cv2.imshow('Hit any key to continue',image1)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Step 1: Convert to Grey Image. Using cvtColor function of OpenCV.
grey_img = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
# Step 2: Invert Image.
invert = cv2.bitwise_not(grey_img)
# Step 3: Blur image.
blur = cv2.GaussianBlur(invert, (21, 21), 0)
# Step 4: Invert Blurred Image.
invertedblur = cv2.bitwise_not(blur)
# Step 5: Convert to Sketch.
sketch = cv2.divide(grey_img, invertedblur, scale=256.0)
# Step 6: Save Sketch. Read back in to verify saved file
filesave = file.with_name(str(pathlib.Path(file).stem) + '-sketch.jpg')
cv2.imwrite(str(filesave), sketch)
image = cv2.imread(str(filesave))
# Step 7: Display sketch.
cv2.imshow('Hit any key to exit', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Welcome to the community! I’m not familiar with this particular Python module but it appears that your installation of it may be corrupted. Try the following:
In shell, run poetry remove cv2; poetry add cv2.
If that doesn’t work, try pip install cv2.
CoderElijah, Thank you for your suggestion. I have already done those things, both in the terminal and using the GUI package manager, as well as letting the template auto-install upon seeing the “import opencv-python” line in the code.
I did find an old thread that has a working solution, but it still needs addressing by the REPL team. If I fork a very old project with opencv, the fork will work. Any project created with recent templates fails.
It will take me a while to find the discussion thread as I don’t have that handy. The discussion said to fork the following REPL that was an opencv example.
If I fork that REPL, delete all the code, and then paste all of my code inside, it works correctly.
If I start a new REPL it fails with an opencv configuration error.
I have let the “import opencv” auto install, but errors…
I have used GUI package manager to remove and reinstall opencv-python but it errors.
The only working solution has been to fork that old project, and hope that the old project never disappears.
Regards,
Mark
I have used terminal and “pip install opencv-python” but still errors
I’m bumping this topic, because I tried this last year and I find that it still has the same error as before. Something about a configuration file problem. This would be a good thing to fix, because opencv is an important library.
Running OpenCV requires some extra configuration. Because of this, the staff have released a template that has everything configured and OpenCV installed here: https://replit.com/@scottatreplit/Python-OpenCV?v=1
Thanks; this is good to know. Now I can play with opencv.
This doesn’t appear in the template list when I create a new repli, although I see that there is a Java opencv template in there. Is there some listing of useful templates like this that don’t appear in the menu, or some other way that people would know about this type of thing?
Some templates may only appear on the template page, however it doesn’t seem to be listed there, templates are supposed to be reviewed before they are added so the staff likely just haven’t got around to, essentially, ‘whitelisting’ it yet.
If I’m importing a repo from Github that has the OpenCV package, would forking this old repl work for me?
I want to be able to push into the imported repo, so I have to be connected to it somehow, and I can’t select the OpenCV template as it’s not official.