I'm trying to link my IP camera to my a AWS service and there's 2 ways I can do this, either with my built in computer camera (runs fine) and a IP camera. The code I'm using is from https://github.com/aws-samples/amazon-rekognition-video-analyzer which is writing in Python 2.7(but I'm doing it in python 3), I already converted the code to python 3 (using python 2to3).but when I run the code I keep getting this error of only concatenate strings not bytes:
I'm new to python so for what I have research is that 2to3 will do must of the work, but I'm pretty sure this part of converting bytes to strings is not in there and I'm not sure how to handle this conversion/parsing.
Traceback (most recent call last):
File "video_cap_ipcam.py", line 140, in <module>
main()
File "video_cap_ipcam.py", line 104, in main
bytes += stream.read(16384*2)
TypeError: can only concatenate str (not "bytes") to str
video_cap_ipcam.py file:
def main():
ip_cam_url = ''
capture_rate = default_capture_rate
argv_len = len(sys.argv)
if argv_len > 1:
ip_cam_url = sys.argv[1]
if argv_len > 2 and sys.argv[2].isdigit():
capture_rate = int(sys.argv[2])
else:
print("usage: video_cap_ipcam.py <ip-cam-url> [capture-rate]")
return
print(("Capturing from '{}' at a rate of 1 every {} frames...".format(ip_cam_url, capture_rate)))
stream = urllib.request.urlopen(ip_cam_url)
bytes = ''
pool = Pool(processes=3)
frame_count = 0
while True:
# Capture frame-by-frame
frame_jpg = ''
bytes += stream.read(16384*2)
b = bytes.rfind('\xff\xd9')
a = bytes.rfind('\xff\xd8', 0, b-1)
if a != -1 and b != -1:
#print 'Found JPEG markers. Start {}, End {}'.format(a,b)
frame_jpg_bytes = bytes[a:b+2]
bytes = bytes[b+2:]
if frame_count % capture_rate == 0:
img_cv2_mat = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
rotated_img = cv2.transpose(cv2.flip(img_cv2_mat, 0))
retval, new_frame_jpg_bytes = cv2.imencode(".jpg", rotated_img)
#Send to Kinesis
result = pool.apply_async(send_jpg, (bytearray(new_frame_jpg_bytes), frame_count, True, False, False,))
frame_count += 1
if __name__ == '__main__':
main()