cd ..
cd # back to home dir
cd ~/p2 # ~ means home dir as well
ls # dir
# install vim: sudo is to notify running as administrater,
# apt-get install to install package,
# vim is a common editor (extension of vi)
sudo apt-get install vim
sudo apt-cache search vim # search packages relating to vi
gedit tmp.py # open to edit a file
ctrl-z # break the current job
bg # send job to background
fg # send job back to foreground
ctrl-c # kill foreground job
ps aux | grep gedit # list all jobs and then search for "gedit" jobs
kill -9 12345 # kill job with job number 12345
# extract the audio channel of dummy.mp4
# audio format suppose to be aac though
# change extension (.ac3/.flac) accordingly
ffmpeg -i dummy.mp4 -acodec copy -vn audio.aac
ls -1 \*.mp4|sed 's/\(.*\)\.mp4/ffmpeg -i "&" -acodec copy -vn "\1.aac"/'|sh
sudo apt-get install python-virtualenv
virtualenv ~/p2 # create a virtualenv with python2
virtualenv --python=/usr/bin/python3 ~/p3 # create a virtualenv with python3
source ~/p2/bin/activate
source ~/p2/bin/activate # make sure you have create virtualenv already, see above.
pip install numpy # install numpy (matlab like library for scientific computing).
# Note that we don't include sudo here as we are installing to the virtualenv
pip install opencv-python
pip install opencv-contrib-python
pip install opencv-python==3.4.5.20 # install a particular version
pip install -U opencv-python # upgrade to latest
pip search opencv # search packages relating to opencv
import cv2
import matplotlib.pyplot as plt
import numpy as np
from skimage import io
import os.path
filename='Lena.png'
if os.path.isfile(filename):
im=cv2.imread('Lena.png')
else:
im=io.imread('http://optipng.sourceforge.net/pngtech/img/lena.png')
# note that io.imread and cv2.imread handle images differently, io.imread compatible with plt.imshow directly
%matplotlib inline
plt.imshow(im)
<matplotlib.image.AxesImage at 0x7f472ff99750>
ims=cv2.resize(im,(128,128))
im2=np.zeros_like(ims)
im2[:,:,0]=ims[:,:,2]
im2[:,:,1]=ims[:,:,1]
im2[:,:,2]=ims[:,:,0]
plt.imshow(im2)
<matplotlib.image.AxesImage at 0x7f472ff86f10>
r=im2[:,:,0]
r[:,50:100]=0
plt.imshow(im2) # note that the original image was modified as well. You may find this surprising
# if you are used to the MATLAB world
# this article may help
# https://jeffknupp.com/blog/2012/11/13/is-python-callbyvalue-or-callbyreference-neither/
<matplotlib.image.AxesImage at 0x7f472fefadd0>
f=np.zeros([5,5])
f[4,4]=1
r=ims[:,:,0]
r2=cv2.filter2D(r,-1,f,borderType=cv2.BORDER_CONSTANT)
plt.imshow(r2)
<matplotlib.image.AxesImage at 0x7f472fe74950>
edge=cv2.Canny(r,100,200)
plt.imshow(edge,cmap='gray')
<matplotlib.image.AxesImage at 0x7f472fdea890>
import cv2
import platform
cap=cv2.VideoCapture(0)
while (True):
ret,frame=cap.read()
cv2.namedWindow("camera",cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("camera",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.imshow('camera',frame)
if cv2.waitKey(1) &0xFF == ord('q'): # press q or ESC to quit. You probably need to hit the screen first
break
cap.release()
cv2.destroyAllWindows()
import cv2
import platform
cap=cv2.VideoCapture(0)
while (True):
ret,frame=cap.read()
cv2.namedWindow("camera",cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("camera",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
frame=cv2.cvtColor(frame,cv2.COLOR_RGB2GRAY)
frame=cv2.Canny(frame,50,60)
cv2.imshow('camera',frame)
if cv2.waitKey(1) &0xFF == ord('q'): # press q or ESC to quit. You probably need to hit the screen first
break
cap.release()
cv2.destroyAllWindows()