Archive pour la catégorie ‘Python’

Deep learning AI detection for a surveillance camera.

Lundi 13 novembre 2023

You can find my last article on camera detection using deeplearning at
https://medium.com/@themadmax_60294/deep-learning-ai-detection-for-a-surveillance-camera-cde4c44c09fd.

OpenCV Python Write AVI under windows

Mardi 9 juin 2015

Create AVI file with opencv under windows:

[sourcecode language="py"]
import cv2
import numpy as np

cap = cv2.VideoCapture(0)
fourcc = cv2.cv.CV_FOURCC(‘D’,'I’,'B’,’ ‘)
size = (320,240)
out = cv2.VideoWriter(‘output.avi’,fourcc, 1.0, size)

for i in range(100):
im = np.zeros( (size[1],size[0]), dtype=np.uint8 )
cv2.rectangle( im, (size[0]/2-50,size[1]/2-10), (size[0]/2+50,size[1]/2+10), 255, -1 )
out.write( im )
print i, im.shape

cap.release()
out.release()
[/sourcecode]

Simulate PPTP connexion in Python

Jeudi 26 juin 2014

I want to check PPTP connexion into a script, so I write this small code to simulate first packet PPTP connection:

[sourcecode]
import socket
import array
import struct

HOST = "pptp.example.com"
PORT = 1723

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST,PORT))

hex_string = "009c00011a2b3c4d0001000001000000000000010000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004d6963726f736f667400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
hex_data = hex_string.decode("hex")
msg = bytearray(hex_data)

s.send(msg)

data = s.recv(8)
( len, type, magic ) = struct.unpack(‘>HHI’, data )
data = s.recv( len – 8 )
s.close()

print ( "len=%d,type=%d,magic=0x%0x" ) % ( len, type, magic )
print data.encode(‘hex_codec’)
[/sourcecode]

Source : http://tools.ietf.org/html/rfc2637
http://www.wireshark.org/