Python Common Library
Some common Python library.
Some common Python library.
Opencv has a lot of useful functions.
1 | while True: |
1 | gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) |
1 | hist = cv2.calcHist([img], [0, 1], None, [180, 256], [0, 180, 0, 256]) |
1 | _, mask = cv2.threshold(img[:, :, 1], 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU) |
1 | _, contours, _ = cv2.findContours(mask, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE) |
1 | hull = cv2.convexHull(contour, returnPoints=False) |
Check the IP of Raspberry Pi is very painful because the IP of the Raspberry Pi will change automatically after a period of time if you didn’t assign a static IP to it. Checking the IP of the Raspberry Pi requires the keyboard, monitor, and it requires time to check it.
One way to solve this problem is let the Raspberry Pi to automatically send its IP to somewhere, like Google Sheet. This can make life better. Following are the steps to achieve it.
You need to use keyboard and monitor to set up the Raspberry Pi’s WiFi firstly, also check the IP, because we need to use the scp
command to send file to Raspberry Pi.
pi_logger.py
from this link, edit itscp
command to send this file together the json file to the Raspberry Pipi_logger.py
file. sudo pip3
to install the libraries, otherwise it cannot be ran by bash laterpython3 pi_logger.py
to test it. Go to your Google Sheet you should find a file created and shared by Raspberry Pilauncher.sh
sudo python3 /home/pi/%your path%/pi_logger.py
, save itsh /home/pi/%your path%/launcher.sh
to test the code, it should have the same result.sudo pip3
to install it backsudo crontab -e
*/2 * * * * /home/pi/justdiedbot/launcher.sh >/home/pi/logs/cronlog.log 2>&1
, which means the Raspberry Pi will send do the sending action every 2 minutes[1] https://www.instructables.com/id/Raspberry-Pi-Launch-Python-script-on-startup/
[2] https://raspberrypi.stackexchange.com/questions/78141/python-script-fails-with-importerror-when-run-from-rc-local
Below are some basic machine learning skills
Object detection is kind of classificitaion which you need to figure out where the object is located in the image. The output is usually described as:
$$
y = [P_c, P_x, P_y, W, H, c_1, c_2, c_3, …]
$$
$P_c$ means whether this image contain the content you’re detecting, $c_i$ the probability of the label_i object exists.
Object detection includes both localization and detection.
$$
Intersection\ Over\ Union = \frac{size\ of\ overlaping\ area}{size\ of\ true\ and\ detection\ area}
$$
This post talks about the grammar of Java.
Importing the .ipynb file we wrote as a module to a new .ipynb file is different from importing them in a .py file. The easiest way is to convert those .ipynb file to a .py file and you can import those in a new .ipynb file. However, this method doesn’t allow you to modify the code and reload it easily.
For example, the lib’s name is test.ipynb
. There is a function called hello()
within it. In a new .ipynb file, you need to type the following.
1 | # !pip install import-ipynb |
The import_ipynb
lib is allowing you to import a .ipynb file. The importlib
file is allowing you to reload the module thus the new change to the lib file can be reloaded into your file.
For example, the lib file in the folder of lib
. The lib’s name is test.ipynb
. There is a function called hello()
within it. In a new .ipynb file, you need to type the following.
Powershell is a more powerfull shell than CMD in Windows. However, the layout of powershell in Windows is very ugle, especially the default font. In order to change the font of powershell, we need to do several works.
Actually the font can be change in the powershell if we click the top left corner of the powreshell interface. While if the CodePage
is 936(Chinese), you can only change the font of powershell among several Chineses fonts, which are not well performed in the powershell.
So we need to find some way to change the CodePage of powershell to 437(English), then we can change the font to some English font like Consolas.
In order to change the default page to another, there are two steps need to finish that. One is for the powershell launched by Win+R
, and another is the powershell launched by the start menu. It is because the software launched by shortcut follows other disciplines which I don’t know much.
\HKEY_CURRENT_USER\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe
CodePage
of type DWORD
to decimal 437
-NoExit -Command "chcp 437; cls"
The command above means the powershell will run the two commands automatically. The chcp 437
means to swtich the Codepage to 437; and the cls
means to clear the powershell.
There is a lot of development frameworks for Java. This post talks about Guice (for Dependency Injection design pattern implementation), Spring (Java integration environment), JUnit and Mockito (for unit test).
Tree is a basic data structure. The most popular tree is the binary tree, which has a left child and a right child. The exercise usually gives you the root node of the tree. The basic method to solve a tree problem is recursive.
1 | openlist = [root] |
1 | def check_tree(node): |
The above two ara both DFS(Deep First Search), in order to achieve the BFS(Breadth First Search), in other means, traverse the tree layer by layer, we need to use a dictionary to store the node
1 | dic_tree = {} |
1 | leafs = [] |
Establish a list to collect the tuple like (node: depth)
1 | def get_depth(node): |
1 | paths = [] |