Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
b8a7093
Modif Readme
Sep 15, 2020
06449ad
initial commit
Sep 15, 2020
64a3142
test push
Sep 15, 2020
30f803b
Create function to get average of positive numbers
Sep 15, 2020
bfdc79d
Fix comment error
Sep 15, 2020
2a761bb
Create max value function and fix average function
Sep 15, 2020
67bbb79
Add reverse table function
Sep 15, 2020
e8bed64
Add new test for average function
Sep 16, 2020
7ac5d63
Add new test for max value function
skeul Sep 16, 2020
53d46cf
Add V2 for reverse table function
skeul Sep 16, 2020
56dc1b5
Add comment to reverse table v2
skeul Sep 16, 2020
7b4d16e
Add reverse table function V3
skeul Sep 16, 2020
f2dba1e
Add bounding box function
skeul Sep 16, 2020
0ef1e22
Add bounding box V2 and fix bugs
skeul Sep 16, 2020
52175ff
Start random fill function(work in progress)
skeul Sep 16, 2020
94c6d59
Add TravisCI
skeul Sep 16, 2020
321086d
Add test file and fix travis config
skeul Sep 16, 2020
4f9a0f7
Merge branch 'master' of https://github.com/albenoit/BachelorDIM-Lect…
skeul Sep 16, 2020
1342a7e
add coveralls config file
skeul Sep 16, 2020
9763c99
add coveralls badge
skeul Sep 16, 2020
a48d74a
Add first test for average function
skeul Sep 16, 2020
6e0b944
Add some test for max values function
skeul Sep 16, 2020
954db4c
Add test for reverse table function
skeul Sep 16, 2020
849a2de
Add some exception test to average function
skeul Sep 16, 2020
fb334a9
Add reverse table test
skeul Sep 16, 2020
a08f668
add Bounding box test
skeul Sep 16, 2020
be08af0
Clean for fix error
skeul Sep 16, 2020
c998607
Maj
skeul Sep 29, 2020
4872f46
Merge branch 'master' of https://github.com/albenoit/BachelorDIM-Lect…
skeul Sep 29, 2020
7308ff4
Add image function && test
skeul Sep 29, 2020
94ded10
Add function documentation
skeul Sep 29, 2020
4eb530c
Add threshold function and new tests
skeul Sep 29, 2020
380aa01
Edit threshold function
skeul Sep 29, 2020
4e12cba
Add Queues and CloudAMPQ methods and files
skeul Oct 13, 2020
6d262d2
Add concurrency mode for persistent messages
skeul Oct 20, 2020
e9035d6
Update documentation
skeul Oct 20, 2020
294973a
Add sleep args to set sleep mode in reader
skeul Oct 20, 2020
2f6c68c
Edit reader and sender with fanout exchange mode to publish in many q…
skeul Oct 20, 2020
2949622
Edit fanout mode in new files
skeul Oct 20, 2020
e592c2a
Remove fanout from older files
skeul Oct 20, 2020
3532e05
Add whitespace func && linter edit
skeul Nov 8, 2020
9b93ad3
Add shuffle function
skeul Nov 8, 2020
d5b5990
remove unused files
skeul Nov 8, 2020
f9028fd
Fix error & config files
skeul Nov 8, 2020
02de482
First version (broken) of dice game
skeul Nov 8, 2020
207db17
Fix dice_game algo
skeul Nov 8, 2020
dc0b629
Fix cv2 error
skeul Nov 8, 2020
0bfbf3a
Fix requirements
skeul Nov 8, 2020
c44a3aa
Edit & fix on dice game
skeul Nov 8, 2020
fd7ac4d
Fix errors
skeul Nov 10, 2020
63386d3
add computer logic
skeul Nov 14, 2020
62bb0ba
fix test errors
skeul Nov 14, 2020
0d1e8ed
Dice game comments
skeul Nov 14, 2020
b51005a
Add new test for S3
skeul Nov 14, 2020
5347a2b
Edit threshold and test
skeul Nov 14, 2020
d61de90
fix
skeul Nov 14, 2020
acac59d
add baby caramail methods
skeul Nov 15, 2020
b97e9df
Edit caramail
skeul Nov 15, 2020
b71fb14
Add logical to presentation channel
skeul Nov 15, 2020
e0b8ee4
End baby caramail v1
skeul Nov 15, 2020
091547f
rpc_client V1
skeul Nov 15, 2020
03bf803
rpc client & servers comments after tests
skeul Nov 15, 2020
6c37929
Test with Json message
skeul Nov 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
service_name: travis-pro
repo_token: 6UvqI0vuqQq3P2Fsw8d2jHy5OnJnbVbff
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ python:
install:
- pip install -r requirements.txt
addons:
sonarcloud:
organization: albenoit-github
# sonarcloud:
# organization: albenoit-github
# command to run tests
script:
- pytest -v --cov .
#- sonar-scanner
- coveralls

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Coverage Status](https://coveralls.io/repos/github/albenoit/BachelorDIM-Lectures-Algorithms-2020/badge.svg?branch=master)](https://coveralls.io/github/albenoit/BachelorDIM-Lectures-Algorithms-2020?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/skeul/BachelorDIM-Lectures-Algorithms-2020/badge.svg?branch=master)](https://coveralls.io/github/skeul/BachelorDIM-Lectures-Algorithms-2020?branch=master)

# BachelorDIM-Lectures-Algorithms-2020
Algorithms, code writing and continuous integration @ DIM Bachelor, Université Savoie Mont Blanc, France
Expand Down
Binary file added assignements/DIM_Algo_Session4_Queues.pdf
Binary file not shown.
Binary file added assignements/IMG_0825.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions assignements/S3_imgproc_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import cv2
import numpy as np

img = cv2.imread("BachelorDIM-Lectures-Algorithms-2020/assignements/IMG_0825.JPG")
# img = np.array([[[0, 0, 254]]], dtype=np.uint8)
img_gray = cv2.imread(
"BachelorDIM-Lectures-Algorithms-2020/assignements/IMG_0825.JPG", 0
)
img_bgr = cv2.imread(
"BachelorDIM-Lectures-Algorithms-2020/assignements/IMG_0825.JPG", 1
)


def invert_color_manual(img: np.ndarray):
"""
Function to invert image colors with highest CPU demanding processing
Parameters :
img: image nd array
Returns :
imgRet image inverted
"""
img_out = np.zeros(img.shape, dtype=np.uint8)

if img is None:
raise ValueError("expected an uint8 nd array")
if not (isinstance(img, np.ndarray)):
raise TypeError("expected an nd array")
if img.dtype != np.dtype(np.uint8):
raise TypeError("expected an uint8 nd array")

for row in range(img.shape[0]):
for col in range(img.shape[1]):
for channel in range(img.shape[2]):
img_out[row, col, channel] = 255 - img[row, col, channel]
return img_out


def invert_gray_lvl_image_light(img: np.ndarray):
"""
Function to invert image colors with lower CPU demanding processing
Parameters :
img: image nd array
Returns :
imgRet image inverted
"""
# imgRet=np.zeros(img.shape, dtype=np.uint8)
if img is None:
raise ValueError("expected an uint8 nd array")
if not (isinstance(img, np.ndarray)):
raise TypeError("expected an nd array")
if img.dtype != np.dtype(np.uint8):
raise TypeError("expected uint8 typed nd array")

imgRet = 255 - img
return imgRet


def invert_color_opencv(img: np.ndarray):
"""
Function to invert image colors with opencv method
Parameters :
img: image nd array
Returns :
imgRet image inverted
"""
if img is None:
raise ValueError("expected an uint8 nd array")
if not (isinstance(img, np.ndarray)):
raise TypeError("expected an nd array")
if img.dtype != np.dtype(np.uint8):
raise TypeError("expected uint8 typed nd array")

return ~img


def threshold(img: np.ndarray):
"""
tresholde image
Parameters :
img: image nd array
Returns :
imgRet image tresholded
"""

threshold_value = 128
if img is None:
raise ValueError("expected an uint8 nd array")
if img.dtype != np.dtype(np.uint8):
raise TypeError("expected uint8 typed nd array")
return img > threshold_value


# print(threshold(img))
# thresholded = threshold(img_bgr)
# thresholded_display = thresholded.astype(np.uint8) * 255
# cv2.imshow("testimg", thresholded_display)
# cv2.waitKey()
# stream=cv2.VideoCapture(0)


# while True:
# ok, imgStream=stream.read()
# cv2.imshow("Inverted image", invert_gray_lvl_image_light(imgStream))
# cv2.waitKey(1)

# cv2.imshow("test", invert_color_opencv(img))
# cv2.waitKey()

# display matrix
# print("Gray levels image shape = "+str(img_gray.shape))
# print("BGR levels image shape = "+str(img_bgr.shape))

# display images
# cv2.imshow("Gray lvl image", img_gray)
# cv2.imshow("Bgr lvl image", img_bgr)
# cv2.waitKey()
258 changes: 258 additions & 0 deletions assignements/Session1/S1_algotools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
import numpy as np


def average_above_zero(tab: list):
"""
Function to add average of positive numbers in array
This function add one array of numbers in args
Parameters :
tab: array of numbers in input
Returns :
the average of positive numbers
"""
som = 0 # Sum of positive numbers in array. Init at 0
N = 0 # Count of positive numbers in array. Init at 0

for i in range(len(tab)):
if tab[i] > 0: # If number is > 0
som += tab[i]
N += 1

# Calculate the average if positive numbers find
if N > 0:
average = som / N
else:
raise ValueError("No positive number found")

return average # Return average


# Call the function with array in args and display the average
# print('# Average above zero function # ')
# print('T1 : average = ' , average_above_zero([1,10,2,8,12])) #Only positive numbers
# print('T2 : average = ' , average_above_zero([1,-10,-2,-8,12])) #With positive and negative numbers
# print('T3 : average = ' , average_above_zero([-1,-10,-2,-8,-12])) #Only negative numbers


def max_value(tab: list):
"""
Function to get the number with the max value in array
Parameters :
tab: array of numbers in input
Returns :
the index of max value numbers
the max number
"""
maxNumber = max(tab) # Get the max number in tab
maxNumberIndex = tab.index(maxNumber) # Get index of max number
return maxNumberIndex, maxNumber # Return index of max number & the max number


# Call the function with array in args and display the index of max value
# print('# Max value index function #')
# print('T1 = ', max_value([1,10,2,8,11])) #Only positive numbers
# print('T2 = ', max_value([1,10,2,8,-11])) #With positive and negative numbers
# print('T3 = ', max_value([-1,-10,-2,-8,-11])) #Only negative numbers

# Reverse table V1
def reverse_table(tab: list):
"""
Function to reverse and return a reversed array
Parameters :
tab: array of numbers in input
Returns :
the reversed array
"""
tab = list(reversed(tab))

return tab


# Call the function with array in args and display reversed array
# print('# Reverse table function #')
# print(reverse_table([1,10,2,8,11]))

# Reverse table V2
def reverse_table_V2(tab: list):
"""
Function to reverse and return a reversed array
Parameters :
tab: array of numbers in input
Returns :
the reversed array
"""
for i in range(-1, -len(tab) - 1, -1):
n = tab[i]
tab.pop(i)
tab.append(n)
return tab


# Call the function with array in args and display reversed array
# print('# Reverse table function V2 #')
# print(reverse_table_V2([1,10,2,8,11]))

# Reverse table V3
def reverse_table_V3(tab: list):
"""
Function to reverse and return a reversed array
Parameters :
tab: array of numbers in input
Returns :
the reversed array
"""
listen = len(tab)
for i in range(len(tab) // 2):
n = tab[i]
tab[i] = tab[listen - i - 1]
tab[listen - i - 1] = n
return tab


# Call the function with array in args and display reversed array
# print('# Reverse table function V3 #')
# print(reverse_table_V3([1,10,2,8,11]))


# Bounding box
def run():
H = 12
W = 10
matrix = np.zeros((H, W))
# matrix[2:3, 3:5]= np.ones((2,2)) * 2
for c in range(1, 3):
for l in range(3, 5):
matrix[l, c] = 1
for c in range(5, 8):
for l in range(6, 9):
matrix[l, c] = 1


# print(matrix)

if __name__ == "__main__":
run()


def roi_bbox(img):
"""
Function to get coordinates of img in matrix
Parameters :
img: matrix of img
Returns :
the coordinates of img
"""
x1 = 0
y1 = 0
x2 = 0
y2 = 0

targets = np.argwhere(img > 0)
# print(targets)

x1 = targets[0][0]
y1 = targets[0][1]
x2 = targets[len(targets) - 1][0]
y2 = targets[len(targets) - 1][1]
return np.array([x1, y1, x2, y2])


# Call the function with matrix in args and display img coordinates
# print('# Bounding box function V1 #')
# print('T1 : img coordinate = ',roi_bbox(matrix))


def roi_bbox_V2(img):
"""
Function to get coordinates of img in matrix V2
Parameters :
img: matrix of img
Returns :
the coordinates of img
"""
W = img.shape[0] - 1
H = img.shape[1] - 1
x1 = W
y1 = H
x2 = 0
y2 = 0
for x in range(0, W):
for y in range(0, H):
# print(x,y)
if img[x, y]:
if x < x1:
x1 = x
if y < y1:
y1 = y
if y > y2:
y2 = y
if x > x2:
x2 = x
return np.array([x1, y1, x2, y2])


# Call the function with matrix in args and display img coordinates
# print('# Bounding box function V2 #')
# print('T2 : img coordinate = ',roi_bbox_V2(matrix))


# Random array filling
import random

RandomArray = np.zeros((10, 10))
K = 200
# print(RandomArray)


def random_fill_sparse(matrix, k):
"""
Function to insert X values in random cells of matrix
Parameters :
matrix: matrix of where insert X values
k: numbers of cells
Returns :
a np.array with X values inserted
"""
randomList = []
maxRandomNumber = (matrix.shape[0]) * (matrix.shape[1])
if k > maxRandomNumber:
raise ValueError("Too randoms numbers will be create")

# print(maxRandomNumber)

# Set a length of the list to 10
for i in range(0, k):
# any random numbers from 0 to 1000
randomList.append(random.randint(0, 1000))

print("Printing list of 10 random numbers")
print(randomList)


def remove_whitespace(text: str):
"""
Function to remove whitespace in string
Parameters :
text: string to check
Returns :
text: string got in params without whitespace
"""
return text.replace(" ", "")


# print(remove_whitespace("a bcdefghij;;; kl eudjj"))


def shuffle(tab: list):
"""
Function to shuffle tab
Parameters :
tab: tab
Returns :
tab: tab shuffled
"""
random.shuffle(tab)
return tab


# print(shuffle(["abc", "def", "ghi", "jkl"]))
Loading