I try to calibrate a camera with python and opnecv.
I use a video-file instead of a webcam live stream.
Everything seems to work except of the last step. This is:
print "now get ready, camera is switching on"
while(1):
image=cv.QueryFrame(capture)
t = cv.CloneImage(image);
cv.ShowImage( "Calibration", image )
cv.Remap( t, image, mapx, mapy )
cv.ShowImage("Undistort", image)
c = cv.WaitKey(33)
if(c == 1048688): # enter 'p' key to pause for some time
cv.WaitKey(2000)
elif c==1048603: # enter esc key to exit
break
print "everything is fine"
There I receive following error:
Traceback (most recent call last):
File "V:\Studenten\Christian_Fuerstenhoefer\02_Kamerakalibrierung\openCV\camCalib.py", line 137, in <module>
t = cv.CloneImage(image);
TypeError: Argument 'image' must be IplImage
I already checked print type (image). Then it says None.
Does anyone know how to fix this problem?
Thanks for your help.
you don't check for the end of the stream ( each video has an end..)
while(1):
image=cv.QueryFrame(capture)
if image==None:
break
Related
during tests it's showing the error message:
Traceback (most recent call last):
File "tictactoe/tictactoe.py", line 10, in <module>
coordinates = input("Enter the coordinates: ")
EOFError: EOF when reading a line
I can't image what is causing this problem. The code is:
c = True
while c:
coordinates = input("Enter the coordinates: ") # <-- line 10 is this one
if coordinates == '':
print("Coordinates should be from 1 to 3!")
continue
elif len(coordinates) < 3 or len(coordinates) > 3:
print("Coordinates should be from 1 to 3!")
continue
Thanks for support
Your test probably runs the code non-interactively. If you are creating the test in Python, try using subprocess.PIPE so that you can communicate with the subprocess. Without a valid stdin, the program will throw this error, which (should) cause your test to fail.
#!/usr/bin/env python
'''
Usage:
./ssearch.py input_image (f|q)
f=fast, q=quality
Use "l" to display less rects, 'm' to display more rects, "q" to quit.
'''
import sys
import cv2
if __name__ == '__main__':
# If image path and f/q is not passed as command
# line arguments, quit and display help message
if len(sys.argv) < 3:
print(__doc__)
sys.exit(1)
# speed-up using multithreads
cv2.setUseOptimized(True);
cv2.setNumThreads(4);
# read image
im = cv2.imread(sys.argv[1])
# resize image
newHeight = 200
newWidth = int(im.shape[1]*200/im.shape[0])
im = cv2.resize(im, (newWidth, newHeight))
Here i am getting error
AttributeError Traceback (most recent call last)
<ipython-input-7-b88f466ecb3b> in <module>
25 # resize image
26 newHeight = 200
---> 27 newWidth = int(im.shape[1]*200/im.shape[0])
28 im = cv2.resize(im, (newWidth, newHeight))
29
AttributeError: 'NoneType' object has no attribute 'shape'
and explain cv2.imread(sys,argv[1]) line
(2)second question is how do i get nonetype error because i havent
passed my image path from my command line yet
(3) cmd line didnt prompt because program didnt executed with th error
i am sorry i couldnt place entire code
The correct way is:
# read image
im = cv2.imread(sys.argv[1])
if im == None :
sys.exit('Invalid or missing image: ' + sys.argv[1])
BEFORE you try to do anything with your image im.
I'm using Python with OpenCV, and I'm trying to open the camera. However, I'm getting the following error:
VIDEOIO ERROR: V4L: can't open camera by index 1
VIDEOIO ERROR: V4L: can't open camera by index 0
Traceback (most recent call last):
File "set_hand_hist.py", line 71, in <module>
get_hand_hist()
File "set_hand_hist.py", line 38, in get_hand_hist
img = cv2.resize(img, (640, 480))
cv2.error: OpenCV(4.1.0) /io/opencv/modules/imgproc/src/resize.cpp:3718: error: (-215:Assertion failed) !ssize.empty() in function 'resize'
I believe that this is the corresponding part of the Python code:
def store_images(g_id):
total_pics = 1200
hist = get_hand_hist()
cam = cv2.VideoCapture(1)
if cam.read()[0]==False:
cam = cv2.VideoCapture(0)
x, y, w, h = 300, 100, 300, 300
create_folder("gestures/"+str(g_id))
pic_no = 0
flag_start_capturing = False
frames = 0
.... ... remaining code ... ...
I've tried looking on Google for a solution; however, nothing that I found yet works. I would really appreciate it if someone who is more experienced could take a look and try to help me out.
Thanks so much
Wanted to comment but I lack reputation. Seems like you can't open both cameras 1 and 0.
VIDEOIO ERROR: V4L: can't open camera by index 1
VIDEOIO ERROR: V4L: can't open camera by index 0
Please be sure a camera is connected to the system. If so, check that you have the appropriate Linux drivers installed for your camera.
And on line 38 of set_hand_hist.py, img variable is possibly an empty image. That's why you get an error on resize. You should investigate why img image is empty. Can't tell more without seeing the whole code.
Edit:You can try the code below to read images from the camera and show it. I believe the error is reading images from the camera. If the code below works, we should look elsewhere for the error.
import cv2
camera_index=1
cam = cv2.VideoCapture(1)
if not cam.read()[0]:
cam = cv2.VideoCapture(0)
camera_index=0
while True:
ret, frame = cam.read()
cv2.imshow(f"image from camera {camera_index}", frame)
if not ret:
break
k = cv2.waitKey(1)
if k%256 == 27:
# ESC pressed
print("Escape hit, closing...")
break
cam.release()
cv2.destroyAllWindows()
I have two gif images and I need to do logical_xor on them from PIL library
This is my code:
from PIL import Image
image = Image.open("image.gif")
key = Image.open("key.gif")
test = image.mode == key.mode
print(test)
def logical_xor(image1, image2):
"""Logical XOR between two images.
.. code-block:: python
out = ((bool(image1) != bool(image2)) % MAX)
:rtype: :py:class:~PIL.Image.Image
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_xor(image2.im))
secret = logical_xor(image, key)
I am getting this error:
True
Traceback (most recent call last):
File "C:/Users/negut_000/OneDrive/Scoala/Crypto/Image Encrypt Decrypt OTP/Encrypt.py", line 24, in <module>
secret = logical_xor(image, key)
File "C:/Users/negut_000/OneDrive/Scoala/Crypto/Image Encrypt Decrypt OTP/Encrypt.py", line 21, in logical_xor
return image1._new(image1.im.chop_xor(image2.im))
ValueError: image has wrong mode
Process finished with exit code 1
It seems that the images have the same mode so I don't understand the problem.
Please help!
Using instead of
image = Image.open("image.gif")
key = Image.open("key.gif")
This code
image = Image.open("image.gif", mode='r').convert("1")
key = Image.open("key.gif", mode='r').convert("1")
I'm trying to write a script to convert an Intel HEX file to a Verilog mem format.
I can print the strings I want to save OK (eg the read & parse bit's working) but when I try to write to a file nothing ever appears :(
ihexf = open("test.hex","r")
vmemf = open("test.mem","w")
for line in ihexf:
rlen_s = line[1:3]
addr_s = line[3:7]
rtyp_s = line[7:9]
rlen = int(rlen_s, 16)
addr = int(addr_s, 16)
rtyp = int(rtyp_s, 16)
# print(rlen_s,addr_s,rtyp_s)
if rtyp == 0:
# print('#'+addr_s)
vmemf.write('#'+addr_s+'\n')
for i in range (0, rlen):
laddr = addr + i
val_s = line[9+i*2:9+i*2+2]
val = int(val_s, 16)
# print(val_s)
vmemf.write(val_s+'\n')
# print("")
else:
print("------- End Of File ------")
ihexf.close()
vmemf.close()
My test.hex looks like
:20000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000FF000000FF000000FF555540FF0A
:20000800155540FF055540FF015540FF005540FF001540FF000540FF000140FF000040FF56
:20001000000040FF000140FF000540FF001540FF005540FF015540FF055540FF155540FF4E
:00000001FF
Any clues what I'm doing wrong?
Make sure you have closed the file and very importantly that you reposition the file pointer to the start of the file and start reading chunks.
ihexf.seek(0,0)
OK - I worked out what was happening (I think!)
Existing code works on linux but not Windows.
On Windows I was seeing the following once the script finished:
#0000
#0008
#0010
#0018
------- End Of File ------
Traceback (most recent call last):
File "C:\Users\Nigel\SkyDrive\Files\python\intexhex2v.py", line 8, in <module>
rlen = int(rlen_s, 16)
ValueError: invalid literal for int() with base 16: ''`
Looks like things were messing up at the end of the file read.
Adding break after the End-Of-File print fixed everything
Thanks