0

the source code is:

import numpy
import cv2

cap=cv2.videoCapture(0)
while true :
    ret,frame=cap.read()
    gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    cv2.imshow('fram',gray)
    if cv2.waitKey(1)&0xFF==ord('q'):
        break
    cap.release()
    cv2.destroyAllWindows()

the error is: source code string cannot contain null bytes . referece to import cv2. what is the solution?

2 Answers 2

2

Somehow an invisible null byte has found its way into your source code.

One easy way to get rid of it is to paste your code back into the editor from e.g. this question – the null byte will probably not have survived the copy-paste.

Also make sure your editor saves files in the UTF-8 encoding, not e.g. UTF-16 (which will contain null bytes).

Sign up to request clarification or add additional context in comments.

3 Comments

Another solution is to search \x00 in print(repr(open('source_code.py').read())).
how can i make sure that my editor saves files in the UTF-8 encoding?
@halamourad That will depend on which editor you are using, and is a tech support question that should be answered by research first.
0

You should try this :

import numpy
import cv2
cap=cv2.VideoCapture(0)
while True :
    ret,frame=cap.read()
    gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    cv2.imshow('fram',gray)
    if cv2.waitKey(1)&0xFF==ord('q'):
        break
    cap.release()
    cv2.destroyAllWindows()

1 Comment

the same problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.