Moblabpy Documentation¶
-
class
PROPS
¶ A class that contains all the configurations of the Moblabpy module
-
ROW
: int = 4¶ The number of row of color matrix in each frame.
ROW
must be equal toCOL
and they are defined by the square root ofBPS
.
-
INFO_BIT_SIZE
: int = 50¶ The height and width of each color matrix. It is defined by
ROW
divides 200.
-
VID_SOURCE
: str = "./16bps.mp4"¶ The video name of the generated video. It will be set by
set_BPS()
automatically if py:attr:BPS is modified.
-
set_BPS
(bps)¶ Set the
BPS
of the video. It will also change the value ofROW
,COL
,INFO_BIT_SIZE
andVID_SOURCE
automatically.- Parameters
bps (int) – The BPS of the video
-
-
class
MobLabPy
¶ A class that allows users to connect their ip camera with the program to simulate a telecommunication system. It use the python
multiprocessing
modules to reduce the time delay of decoding images and capturing images. The program usesmultiprocessing.Pipe
object to send images between thesend_frame()
andrecv_frame()
.-
__init__
(self, ip_address, bit_mess, props=PROPS)¶ Initialize the member variable of the
MobLabPy
object.
-
start
(self)¶ Start getting frames from the ip camera and send it to the decoding function.
-
-
img_to_bit_seq
(frame, pt1=(), pt2=(), props=PROPS)¶ Convert black and white color to “0” and “1” respectively.
- Parameters
- Returns bit_seq, pt1, pt2
Decoded bit sequence and vertices of the area bounded by qr codes in opposite direction.
- Return type
- Raises
IndexError – If it fails to calculate the mean of the RGB of the color matrix
-
check_orientation
(frame, pt1, pt2)¶ Check the orientation of the image according to the qr codes in the corner.
- Parameters
- Return result
Number of rotation needed to be performed
- Return type
- Raises
IndexError – If it fails to locate the qr codes
-
point_rotation
(pt1, pt2, width, rotation)¶ Perform the rotation of vertices of the color matrix area.
- Parameters
- Type
- Returns pt1, pt2
Vertices of the color matrix area after rotation
- Type
-
find_corner
(frame, pt1=(), pt2=())¶ Find the vertex of the color matrix surrounded by but exclude qr codes.
- Parameters
frame (
numpy.ndarray
) – Imagept1 (tuple(int, int)) – Vertex of the area include qr codes, defaults to ()
- Prarm pt2
Vertex of the area include qr codes opposite to pt1, defaults to ()
- Returns size, pt1, pt2
size of the color matrix area and its vertices in opposite direction
- Return type
-
find_min_and_max
(points, min_pt, max_pt)¶ Find the minimum and maximum xy-points in a list and the provides points.
-
all_zeros_or_ones
(bit_seq)¶ Check if the bit sequence contains only 0 or 1.
- Parameters
bit_seq (str) – The bit sequence needed to be checked
- Returns
“True” if the bit sequence only contains 0 or 1, “False” otherwise
- Return type
- Raises
ValueError – it input contains non numerical values
-
str_to_ascii_seq
(my_str='Apple')¶ Convert each character in a string to its corresponding ascii code.
-
ascii_seq_to_bit_seq
(ascii_arr)¶ Convert a list of ascii code to its binary representation.
-
bit_seq_to_ascii_seq
(bit_arr)¶ Perform byte conversion of an array.
-
ascii_seq_to_str
(ascii_arr)¶ Convert a list of ascii code to its corresponding character.
-
append_zeros
(bit_seq, props=PROPS, is_str=False)¶ Append zeros until the length of the input equals to the products of desired length.
-
generate_img
(dir_name, my_str='Hello World', if_bin=False, props=PROPS)¶ Generate images that contain color matrix of my_str parameter, with black represents 0 and white represents 1, and paste them with the qr codes (finder patterns) together. The generated images will be saved at the dir_name directory.
- Parameters
dir_name (str) – The directory name used to save the image generated
my_str (str, list(int)) – The integer binary array or string which will be convert to color code formats, defaults to “Hello World”
if_bin (bool) – True if my_str is an integer binary array, False otherwise, defaults to False
props (
PROPS
) – thePROPS
object that contains the properties of the program
-
generate_res
()¶ Generate the res folder which contains all the head and end messages, start and end signals and finder patterns.
-
generate_video
(video_name='16bps.mp4', mystr='Hello World', if_bin=False, props=PROPS)¶ Generate a video which contains start and end messages, start and end signals, finder patterns and color matrix of the mystr parameter, with desired fps.
- Parameters
video_name (str) – The name of the generated video in mp4 format
mystr (str, list(int)) – The message that will be converted to color code, defaults to “Hello World”
if_bin (bool) – True if mystr is an integer binary array, False otherwise, defaults to False
props (
PROPS
) – thePROPS
object that contains the properties of the program
-
recv_frame
(fps, is_pilot_bit_found, recver, bit_seq, flag, bit_mess, props=PROPS)¶ Funtion that received frames from the sender function. It does all the manipulation of the captured iamge here, such as detecting start and end signals, checking rotations and decoding color codes back to 0 and 1.
- Parameters
fps (
multiprocessing.Value
) – Amultiprocessing.Value
object which represents the fps of the camerais_pilot_bit_found (
multiprocessing.Value
) – Amultiprocessing.Value
object which is True if the start signal is detected, False otherwiserecver (
multiprocessing.Pipe
) – Amultiprocessing.Pipe
object that received images sent from the sender functionbit_seq (
multiprocessing.Value
) – Amultiprocessing.Value
object whcih is the decoded bit sequence of received imagesflag (
multiprocessing.Value
) – Amultiprocessing.Value
object which is the state of the play video buttonbit_mess (str) – The transmitted bit sequence
props (
PROPS
) – ThePROPS
object that contains the properties of the program
-
vid_player
(vid_source, flag, props=PROPS)¶ A video player will be appeared if the play video button is clicked
- Parameters
vid_source (str) – The name of the video to pe played
flag (
multiprocessing.Value
) – Amultiprocessing.Value
object which is the state of the play video buttonprops (
PROPS
) – ThePROPS
object that contains the properties of the program
-
send_frame
(fps, is_pilot_bit_found, sender, ip_address, props=PROPS)¶ A sender function which gets images from the connected camera and send it to the receiver function.
- Parameters
fps (
multiprocessing.Value
) – Amultiprocessing.Value
object which represents the fps of the camerais_pilot_bit_found (
multiprocessing.Value
) – Amultiprocessing.Value
object which is True if the start signal is detected, False otherwisesender (
multiprocessing.Pipe
) – Amultiprocessing.Pipe
object that send images captured by the connected cameraip_address (str) – IP address of the camera that is going to be connected
props (
PROPS
) – The :py:class:PROPS object that contains the properties of the program
-
encode
(D, G)¶ Perform matrix multiplication on parameter D and G, which is D x G.
- Parameters
G (
numpy.ndarray
) – A generator matrix
- Return C
A 1 x n matrix
- Return type
- Raises
ValueError – If the number of columns in the first matrix not equals to the number of rows in the second matrix
UFuncTypeError – If both parameters are not integer
numpy.ndarray
-
syndrome
(R, H)¶ Calculate the syndrome of the received bit sequence.
- Parameters
H (
numpy.ndarray
) – A parity check matrix
-
class
monitor
¶ -
__init__
(self, master, bit_mess)¶ Defines the monitor window.
- Parameters
master (Tk) – Root window
bit_mess (str) – The bit sequence to be sent
-
update_recv
(self, bit_seq)¶ Update the received and error bits textbox upon call.
- Parameters
bit_seq – The bits that are collected from the receiver
Switch the status of the button to True, which indicates it has been pressed.
Return the status of the button.
- Returns
The status of the button, whether it has been pressed
- Return type
-
close_windows
(self)¶ Destroy the root window.
-
-
class
VidCap
¶ -
__init__
(self, scale, vidsource=0)¶ Defines the video to be played and its porperty.
-
get_frame
(self)¶ Get one frame from the video.
- Returns ret, frame
whether a frame is successfully grabbed; the image from the video, None otherwise.
- Return type
tuple(
bool
,numpy.ndarray
)
-
reset
(self, vidsource=0)¶ Reset the video source and start from the beginning.
-
__del__
(self)¶ Release the video when the window is closed.
-