Updaterd backup script; added python script
This commit is contained in:
parent
6828727acc
commit
e1305db4e7
|
@ -0,0 +1,143 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import cv2
|
||||
import pyautogui
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
image_width = 640
|
||||
image_height = 480
|
||||
view_rect_width = 120
|
||||
view_rect_height = view_rect_width
|
||||
outine_color = 0, 0, 255 # bgr NOT rgb
|
||||
lr_full_padding = image_width - view_rect_width
|
||||
tb_full_padding = image_height - view_rect_height
|
||||
lr_padding = int(lr_full_padding / 2)
|
||||
tb_padding = int(tb_full_padding / 2)
|
||||
start_index = (image_width * tb_padding) + lr_padding
|
||||
start_pos = start_index
|
||||
start_y = int(tb_padding)
|
||||
start_x = int(lr_padding)
|
||||
slices = []
|
||||
|
||||
|
||||
|
||||
def generate_slice_info():
|
||||
global view_rect_width
|
||||
global view_rect_height
|
||||
global lr_padding
|
||||
global start_pos
|
||||
global slices
|
||||
|
||||
slices.append([start_pos, start_pos + view_rect_width])
|
||||
for i in range(view_rect_height - 1):
|
||||
start_pos += (view_rect_width + lr_full_padding)
|
||||
end_pos = start_pos + view_rect_width
|
||||
|
||||
slices.append([start_pos, end_pos])
|
||||
|
||||
def draw_square_on_linear_arry(pixels):
|
||||
global slices
|
||||
|
||||
# draw top
|
||||
slice = slices[0]
|
||||
i = slice[0]
|
||||
while i < slice[1]:
|
||||
pixel = pixels[i];
|
||||
pixel[0] = 255
|
||||
pixel[0] = 0
|
||||
pixel[0] = 0
|
||||
|
||||
i += 1
|
||||
|
||||
# draw middle
|
||||
i = 1
|
||||
size = len(slices) - 1
|
||||
while i < size:
|
||||
slice = slices[i]
|
||||
|
||||
pixel = pixels[ slices[0] ];
|
||||
pixel[0] = 255
|
||||
pixel[0] = 0
|
||||
pixel[0] = 0
|
||||
|
||||
pixel2 = pixels[ slices[1] - 1 ];
|
||||
pixel2[0] = 255
|
||||
pixel2[0] = 0
|
||||
pixel2[0] = 0
|
||||
|
||||
i += 1
|
||||
|
||||
# draw bottom
|
||||
slice = slices[ len(slices) - 1]
|
||||
i = slice[0]
|
||||
while i < slice[1]:
|
||||
pixel = pixels[i];
|
||||
pixel[0] = 255
|
||||
pixel[0] = 0
|
||||
pixel[0] = 0
|
||||
|
||||
i += 1
|
||||
|
||||
def draw_square_on_2d_arry(pixels):
|
||||
# draw top
|
||||
i = start_x
|
||||
j = start_x + view_rect_width
|
||||
while i < j:
|
||||
pixels[start_y][i] = outine_color
|
||||
i += 1
|
||||
|
||||
# draw middle
|
||||
y_pos = start_y + 1
|
||||
y_end_pos = (start_y + view_rect_height) - 1
|
||||
while y_pos < y_end_pos:
|
||||
pixels[y_pos][lr_padding] = outine_color
|
||||
pixels[y_pos][lr_padding + view_rect_width] = outine_color
|
||||
y_pos += 1
|
||||
|
||||
# draw bottom
|
||||
bottom_row = start_y + view_rect_height
|
||||
i = start_x
|
||||
j = start_x + view_rect_width
|
||||
while i < j:
|
||||
pixels[bottom_row][i] = outine_color
|
||||
i += 1
|
||||
|
||||
|
||||
|
||||
def process_frame(pixels):
|
||||
draw_square_on_2d_arry(pixels)
|
||||
cv2.imshow('frame', pixels)
|
||||
|
||||
def capture_video(camera):
|
||||
while(True):
|
||||
rendered, data = camera.read()
|
||||
frame = cv2.cvtColor(data, cv2.COLOR_BGR2RGB)
|
||||
# gray_frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
|
||||
|
||||
# Use 'q' key to quit
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
|
||||
if not rendered: continue
|
||||
process_frame(frame)
|
||||
|
||||
def process_video():
|
||||
camera = cv2.VideoCapture(1)
|
||||
camera.set(cv2.CAP_PROP_FRAME_WIDTH, image_width)
|
||||
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, image_width)
|
||||
|
||||
# generate_slice_info()
|
||||
capture_video(camera)
|
||||
|
||||
camera.release()
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
process_video()
|
|
@ -35,3 +35,15 @@ echo -e "
|
|||
##############################################" >> ./"Movies and Tv List".txt
|
||||
|
||||
ls -R ./Music/ >> ./"Movies and Tv List".txt
|
||||
|
||||
echo -e "
|
||||
####################################################
|
||||
# ____ ___________ _______ _______ #
|
||||
# | | | | | | | | #
|
||||
# | | | |______| |_______ |_____ | #
|
||||
# | | | | | | | \ #
|
||||
# |____| | | | |_______ | \ #
|
||||
# #
|
||||
####################################################" >> ./"Movies and Tv List".txt
|
||||
|
||||
ls -R ./Unbackup/ >> ./"Movies and Tv List".txt
|
|
@ -0,0 +1,149 @@
|
|||
(width - view_rect_width)/2 = lr_padding
|
||||
(640-120)/2 = 260
|
||||
|
||||
(height - view_rect_height)/2 = tb_padding
|
||||
(480-120)/2 = 180
|
||||
|
||||
|
||||
[ ------------------------------------ 1D Array ------------------------------------ ]
|
||||
|
||||
---- Python ----
|
||||
|
||||
def draw_square(slices):
|
||||
color_style = "background-color: rgba(0, 66, 125, 1.0)";
|
||||
|
||||
# draw top
|
||||
slice = slices[0]
|
||||
i = slice[0]
|
||||
while i < slice[1]:
|
||||
pixels[i].style = color_style;
|
||||
i += 1
|
||||
|
||||
# draw middle
|
||||
i = 1
|
||||
size = len(slices) - 1
|
||||
while i < size:
|
||||
slice = slices[i]
|
||||
pixels[ slices[0] ].style = color_style;
|
||||
pixels[ slices[1] - 1 ].style = color_style;
|
||||
i += 1
|
||||
|
||||
# draw bottom
|
||||
slice = slices[ len(slices) - 1]
|
||||
i = slice[0]
|
||||
while i < slice[1]:
|
||||
pixels[i].style = color_style;
|
||||
i += 1
|
||||
|
||||
|
||||
image_width = 640
|
||||
image_height = 480
|
||||
view_rect_width = 120
|
||||
view_rect_height = view_rect_width
|
||||
lr_full_padding = image_width - view_rect_width
|
||||
tb_full_padding = image_height - view_rect_height
|
||||
lr_padding = lr_full_padding / 2
|
||||
tb_padding = tb_full_padding / 2
|
||||
start_index = (image_width * tb_padding) + lr_padding
|
||||
start_pos = start_index
|
||||
slices = []
|
||||
|
||||
slices.append([start_pos, start_pos + view_rect_width])
|
||||
for i in range(view_rect_height - 1):
|
||||
start_pos += (view_rect_width + lr_full_padding)
|
||||
end_pos = start_pos + view_rect_width
|
||||
|
||||
slices.append([start_pos, end_pos])
|
||||
|
||||
for i in range( len(slices) ):
|
||||
j = slices[i][0]
|
||||
while j < slices[i][1]:
|
||||
color_style = "background-color: rgba(0, 0, 0, 1.0)";
|
||||
pixels[j].style = color_style;
|
||||
j += 1
|
||||
|
||||
draw_square(slices)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
---- JavaScript ----
|
||||
|
||||
const draw_square = (slices) => {
|
||||
color_style = "background-color: rgba(0, 66, 125, 1.0)";
|
||||
|
||||
// draw top
|
||||
for (let i = slices[0][0]; i < slices[0][1]; i++) {
|
||||
pixels[i].style = color_style;
|
||||
}
|
||||
|
||||
// draw middle
|
||||
for (let i = 1; i < slices.length - 1; i++) {
|
||||
pixels[slices[i][0]].style = color_style;
|
||||
pixels[slices[i][1] - 1].style = color_style;
|
||||
}
|
||||
|
||||
// draw bottom
|
||||
for (let i = slices[slices.length - 1][0]; i < slices[slices.length - 1][1]; i++) {
|
||||
pixels[i].style = color_style;
|
||||
}
|
||||
}
|
||||
|
||||
pixels = document.getElementById("draw-area-body").getElementsByTagName("TD");
|
||||
image_width = 32;
|
||||
image_height = 32;
|
||||
view_rect_width = 16;
|
||||
view_rect_height = view_rect_width;
|
||||
lr_full_padding = image_width - view_rect_width;
|
||||
tb_full_padding = image_height - view_rect_height;
|
||||
lr_padding = lr_full_padding / 2;
|
||||
tb_padding = tb_full_padding / 2;
|
||||
start_index = (image_width * tb_padding) + lr_padding;
|
||||
start_pos = start_index;
|
||||
slices = [];
|
||||
|
||||
slices.push([start_pos, start_pos + view_rect_width]);
|
||||
for (const i of Array(view_rect_height - 1).keys()) {
|
||||
start_pos += (view_rect_width + lr_full_padding);
|
||||
end_pos = start_pos + view_rect_width;
|
||||
|
||||
slices.push([start_pos, end_pos]);
|
||||
}
|
||||
|
||||
for (let i = 0; i < slices.length; i++) {
|
||||
for (let j = slices[i][0]; j < slices[i][1]; j++) {
|
||||
color_style = "background-color: rgba(0, 0, 0, 1.0)";
|
||||
pixels[j].style = color_style;
|
||||
}
|
||||
}
|
||||
|
||||
draw_square(slices);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[ ------------------------------------ 2D Array ------------------------------------ ]
|
||||
|
||||
pixels = document.getElementById("draw-area-body").getElementsByTagName("TD");
|
||||
color_style = "background-color: rgba(0, 66, 125, 1.0)";
|
||||
image_width = 32;
|
||||
image_height = 32;
|
||||
view_rect_width = 16;
|
||||
view_rect_height = view_rect_width;
|
||||
lr_full_padding = image_width - view_rect_width;
|
||||
tb_full_padding = image_height - view_rect_height;
|
||||
lr_padding = lr_full_padding / 2;
|
||||
tb_padding = tb_full_padding / 2;
|
||||
start_index = (image_width * tb_padding) + lr_padding;
|
||||
start_pos = start_index;
|
||||
start_y = start_pos % image_height
|
||||
start_x = start_pos - (start_y * image_width)
|
||||
slices = [];
|
||||
|
||||
for (let i = tb_padding; i < tb_padding + view_rect_height; i++) {
|
||||
pixels[i][lr_padding].style = color_style;
|
||||
pixels[i][lr_padding + view_rect_width].style = color_style;
|
||||
}
|
||||
|
Loading…
Reference in New Issue