1
+ import cv2 , base64 , requests , json , os , re , argparse
2
+ import numpy as np
3
+ from time import sleep
4
+
5
+ def main (camIp , camName ):
6
+ print (camIp )
7
+ print (camName )
8
+ cap = cv2 .VideoCapture ("rtsp://" + camIp )
9
+ #url = 'http://localhost:8888/image/base64/'
10
+ url = 'http://one.innocule.tech/image/base64/'
11
+
12
+ while (cap .isOpened ()):
13
+ retval , image = cap .read ()
14
+ _ , im_arr = cv2 .imencode ('.jpg' , image )
15
+ jpg_as_text = base64 .b64encode (np .array (im_arr ).tostring ()).decode ('utf-8' )
16
+ #print(jpg_as_text[0:50])
17
+ data = { 'image' : str (jpg_as_text ), 'source' : camName }
18
+ headers = {'Content-type' : 'application/json' , 'Authorization' :'Basic YWRtaW46SW5ub2NAMTIz' }
19
+ response = requests .post (url , json = data , headers = headers )
20
+ print (response .text )
21
+ break
22
+
23
+ cap .release ()
24
+ cv2 .destroyAllWindows ()
25
+
26
+ if __name__ == "__main__" :
27
+ # construct the argument parser and parse the arguments
28
+ ap = argparse .ArgumentParser ()
29
+ ap .add_argument ("-i" , "--cameraip" , required = True , type = str , help = "IP Camera host" )
30
+ ap .add_argument ("-n" , "--cameraname" , type = str , required = True , help = "Camera identifier name" )
31
+ args = vars (ap .parse_args ())
32
+
33
+ camIP = args ["cameraip" ]
34
+ camName = args ["cameraname" ]
35
+
36
+ main (camIP , camName )
37
+
38
+ # while(cap.isOpened()):
39
+ # ret, frame = cap.read()
40
+ # cv2.imshow('frame', frame)
41
+ # if cv2.waitKey(20) & 0xFF == ord('q'):
42
+ # break
43
+ # cap.release()
44
+ # cv2.destroyAllWindows()
45
+ #im_bytes = im_arr.tobytes()
46
+ # mydata = np.fromstring(image, dtype=np.uint8)
47
+ # cv2.imwrite("abc.jpg", cap.read()[1])
48
+ #from onvif import ONVIFCamera
49
+ #mycam = ONVIFCamera('192.168.1.64', 80, 'anshul', 'innocule7', '/etc/onvif/python-onvif/wsdl')
50
+
51
+ # Get Hostname
52
+ #resp = mycam.devicemgmt.GetHostname()
53
+ #print 'My camera`s hostname: ' + str(resp.Name)
0 commit comments