def main(): cap = cv2.VideoCapture("./../720.mp4") client = imagiz.Client("cc1", server_ip="10.42.0.1", server_port=5555) encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90] fps = FPS().start() while True: try: succes, frame1 = cap.read() frame1 = cv2.rotate(frame1, cv2.ROTATE_90_COUNTERCLOCKWISE) r, image = cv2.imencode('.jpg', frame1, encode_param) client.send(image) #cv2.imshow("mean.jpg", frame1) if cv2.waitKey(1) & 0xFF == ord('q'): break fps.update() except Exception as e: print(e) cv2.destroyAllWindows() cap.release() break fps.stop() print("[INFO] elasped time: {:.2f}".format(fps.elapsed())) print("[INFO] approx. FPS: {:.2f}".format(fps.fps())) cv2.destroyAllWindows() cap.release()
def send_webcam(port): vid=cv2.VideoCapture(0) client=imagiz.Client(server_port=port,client_name="cc1",server_ip='192.168.1.17') # establishing connection with the server computer. Note: change serveer_ip to ip of administrative computer encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90] # t_end = time.time() + int(time_) frame_rate = 10 prev = 0 while True: time_elapsed = time.time() - prev r,frame=vid.read() #print('Original Dimension', frame.shape) if time_elapsed > 1./frame_rate: prev = time.time() scale_percent = 60 # percent of original size width = int(frame.shape[1] * scale_percent / 100) # compressing frame for easy transmission height = int(frame.shape[0] * scale_percent / 100) dim = (width, height) # resize image resized = cv2.resize(frame, dim, interpolation = cv2.INTER_AREA) # resizing frame with provided scale factor if r: try: r,image=cv2.imencode('.jpg',resized, encode_param) # enconding to bytes np_bytes = BytesIO() np.save(np_bytes, image, allow_pickle=True) # allow_pickle = true allows dimension of numpy array to be encrypted alongside np_bytes = np_bytes.getvalue() en_bytes = base64.b64encode(np_bytes) # base64 encoding of numpy array response=client.send(en_bytes) # sending encoded bytes over to server computer #print(response) except: break vid.release() cv2.destroyAllWindows() current_id = multiprocessing.current_process().pid os.kill(current_id,signal.SIGTERM)
def start_stream(): global ds global ds_mean global ds_iter global altitude, latitude, longitude global et global encode_param, QAL vid = cv2.VideoCapture(0) vid.set(cv2.CAP_PROP_FPS, 1000) client = imagiz.Client("cc1", server_ip=CONTROLLER_IP, server_port=CONTROLLER_VIDEO_PORT, request_retries=100000, request_timeout=5000) encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 55] while True: r, frame = vid.read() pd = '' rd = '' if r: dss = np.mean(ds_mean) / 1024 / 8 / 10 # Data rate global c_hdg # Construct overlay data met = 'MET: ' + str(round(et, 2)) dat = 'DATA: ' + str(round(ds, 2)) + 'M' bat1 = 'SYSV: ' + '7.28' bat2 = 'ENGV:' + '13.93' bit = 'RATE: ' + str(round(dss, 2)) + 'MBit/s' alt = 'ALT : ' + str(round(altitude, 2)) + " m" lon = 'LON: ' + str(round(longitude, 4)) lat = 'LAT: ' + str(round(latitude, 4)) vq = 'VQ: ' + str(QAL) if c_pit < 0: pd = 'PIT D: ' if c_pit >= 0: pd = 'PIT U: ' if c_rol < 0: rd = 'ROL L: ' if c_rol >= 0: rd = 'ROL R: ' pitc = pd + str(round(c_pit, 2)) roll = rd + str(round(c_rol, 2)) cv2.putText(frame, met, BLC1, font, fontScale, fontColor, lineType) cv2.putText(frame, dat, BLC5, font, fontScale, fontColor, lineType) cv2.putText(frame, bat1, BLC2, font, fontScale, fontColor, lineType) cv2.putText(frame, bat2, BLC3, font, fontScale, fontColor, lineType) cv2.putText(frame, bit, BLC4, font, fontScale, fontColor, lineType) cv2.putText(frame, pitc, LC1, font, fontScale, fontColor, lineType) cv2.putText(frame, roll, LC2, font, fontScale, fontColor, lineType) cv2.putText(frame, alt, LC3, font, fontScale, fontColor, lineType) cv2.putText(frame, lon, RC1, font, fontScale, fontColor, lineType) cv2.putText(frame, lat, RC2, font, fontScale, fontColor, lineType) cv2.putText(frame, vq, RC3, font, fontScale, fontColor, lineType) r, image = cv2.imencode('.jpg', frame, encode_param) ds += round(sys.getsizeof(image), 4) / 1024 / 1024 ds_mean[ds_iter] = round(sys.getsizeof(image), 4) if ds_iter < 5: ds_iter += 1 if ds_iter >= 5: ds_iter = 0 client.send(image) else: pass
import imagiz import cv2 client = imagiz.Client("cc1", server_ip="localhost") vid = cv2.VideoCapture(0) encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90] while True: r, frame = vid.read() if r: r, image = cv2.imencode('.jpg', frame, encode_param) client.send(image) else: break
import imagiz import cv2 #https://pypi.org/project/imagiz/ client = imagiz.Client("cc1", server_ip="putserverip") vid = cv2.VideoCapture(0) encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90] while True: r, frame = vid.read() if r: r, image = cv2.imencode('.jpg', frame, encode_param) client.send(image) else: break
import imagiz import cv2 client = imagiz.Client("cc1", server_ip="localhost", server_port=7070) # Connect to server ip on 7070 port vid = cv2.VideoCapture(0) # capturing webcam frames encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90] while True: r, frame = vid.read() # reading captured frame continously for tranmission if r: r, image = cv2.imencode( '.jpg', frame, encode_param) # Encoding captured framed in bytes client.send(image) # Sending captured frame over to server side else: break