OpenCV Function is not Implemented, Rebuild the Library with windows Error - python

I am trying the following code:
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
frame = frame[120:120+250,200:200+250, :]
cv2.imshow('Image Collection', frame)
if cv2.waitKey(1) & 0XFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
And I am getting this error message:
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-2-99572a850d8f> in <module>
6 frame = frame[120:120+250,200:200+250, :]
7
----> 8 cv2.imshow('Image Collection', frame)
9
10 # Breaking gracefully
error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:1272: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'
Can anyone help me with this?

Related

imread throws [WARN] can't open/read file: check file path/integrity

what can i do?
WARN:0#0.726] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_('pythonProject6/arrow.jpg'): can't open/read file: check file path/integrity
Traceback (most recent call last):
File "C:\Users\PC2\PycharmProjects\pythonProject6\whatsapp try.py", line 17, in <module>
cv2.imshow("image", img)
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-
python\opencv\modules\highgui\src\window.cpp:967: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
import cv2
img = cv2.imread("pythonProject6/arrow.jpg")
#print(img.shape)
cv2.imshow("image", img)
cv2.waitkey(0)
first of all, make sure you have defined default folder in python correctly. then check the file and address spelling. if it did not resolve, then try this:(use r and instead of / use //.
import cv2
img = cv2.imread(r"pythonProject6//arrow.jpg")
#print(img.shape)
cv2.imshow("image", img)
cv2.waitkey(0)
If it did not resolve, check your file attribution, and uncheck hidden and read-only. always check you can view the image by windows photo viewer.
I had the same problem using VS Code on macOS. The path was correct, but I was getting the same warning, and the resulting image of cv2.imread was empty.
The issue was solved when I gave Full Disk Access to VS Code. I figured it out because I managed to run the code using my terminal (instead of VS Code terminal).
System Settings -> Privacy & Security -> Full Disk Access
The latest versions of opencv 4.6.x.y and later have the cv2.imshow() issue. I experienced the same. If solution is:
First
pip3 uninstall opencv-python
Second:
pip3 install opencv-python==4.5.5.62

(V4L2: /dev/video0) can't open camera by index

I have an error on my algorithm with Jetson Xavier NX. I try to run code but terminal say that :
[ WARN:0] global /home/arc/opencv_build/opencv/modules/videoio/src/cap_v4l.cpp (890) open VIDEOIO(V4L2:/dev/video0): can't open camera by index
Traceback (most recent call last):
File "realtime_quadrant.py", line 41, in
height = frame.shape
AttributeError: 'NoneType' object has no attribute 'shape'
This means that I have to change 0 in camera = cv2.VideoCapture(0).
So I try
cv2.VideoCapture(1),
cv2.VideoCapture(-1)
cv2.VideoCapture(cv2.CAP_V4L2)
yet I still have the same error. Also I installed V4l2 ( Sudo apt-get install v4l2) How can I do that to run?

How to read image from file directory in Jupyter Notebook using OpenCV?

I am trying to read an image from the laptop in Jupyter notebook using imread() of OpenCV. When I execute the program by specifying the address of the file, it shows the following error:
img2 = cv.imread('D:\Photos\roaches.jpg')
cv.imshow("Cockroaches", img2)
cv.waitKey(0)
cv.destroyAllWindows()
Output:
error Traceback (most recent call last)
<ipython-input-8-645759bb8eb6> in <module>
1 img2 = cv.imread('D:\Photos\roaches.jpg')
----> 2 cv.imshow("Cockroaches", img2)
3 cv.waitKey(0)
4 cv.destroyAllWindows()
error: C:\ci\opencv_1512688052760\work\modules\highgui\src\window.cpp:331: error: (-215) size.width>0 && size.height>0 in function cv::imshow
Screenshot of the notebook snippet
However, when I placed the image in the directory where Jupyter notebook is running, the code worked fine.
How can I read any image from the computer without placing it in the Jupyter notebook directory?

Unable to capture Video from Laptop Webcam using OpenCV

I wrote some code to generate a live feed from my laptop webcam. I'm using the openCV library for Python 3.7 with Pycharm.
This is my code:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while True:
#capture frame by frame
ret, img = cap.read()
# gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow('test', img)
cv2.waitKey(0) & 0xFF
cv2.destroyAllWindows()
cap.release()
This is the error message that I got:
Traceback (most recent call last): File "D:/Python
Programs/OpenCV/VideoCapture.py", line 10, in
cv2.imshow('test', img) cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:627:
error: (-2:Unspecified error) The function is not implemented. Rebuild
the library with Windows, GTK+ 2.x or Cocoa support. If you are on
Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run
cmake or configure script in function 'cvShowImage'
[ WARN:0] terminating async callback

Google Colaboratory: Unable to open landmarks.dat

I am newbie and am currently trying out the Python Notebook https://github.com/TessFerrandez/research-papers/tree/master/facenet on Google Colaboratory.
I added
!pip install face-recognition
!git clone https://github.com/TessFerrandez/research-papers.git
%cd research-papers/facenet
at the start of the notebook so that I can import the right utils.
However, in one of the cells below, I am unable to run the code. I get this error message:
RuntimeError
Traceback (most recent call last)
ipython-input-14-45bae69bfbbe in <module>()
15 # Initialize the OpenFace face alignment utility
---> 16 alignment = AlignDlib('models/landmarks.dat')
/content/research-papers/facenet/research-papers/facenet/align.py in __init__(self, facePredictor)
88 self.detector = dlib.get_frontal_face_detector()
---> 89 self.predictor = dlib.shape_predictor(facePredictor)
RuntimeError: Unable to open models/landmarks.dat
Do you know where to find models/landmarks.dat so that AlignDlib will not throw an error?
Do I have to install openface into the google colabortary or upload the model from somewhere?
You can download and decompress the necessary file with this code.
!wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
!bunzip2 "shape_predictor_68_face_landmarks.dat.bz2"

Categories