The new version of iTerm has the ability to display images in the terminal (https://www.iterm2.com/documentation-images.html).
(Reprinted image of Official Page)
When writing a program such as image processing, it is often the case that a small change is made and executed repeatedly, and trial and error is repeated many times. In such a case, if you use the image display command of iTerm, you can try and make an error at high speed.
For example, suppose you write a program that recognizes faces from images. At this time, ** output the image binary to the standard output. ** **
import cv2
import sys
path = sys.argv[1]
cascade_file = "/usr/local/Cellar/opencv/2.4.12_2/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml"
image = cv2.imread(path)
cascade = cv2.CascadeClassifier(cascade_file)
faces = cascade.detectMultiScale(image)
(x, y, w, h) = faces[0]
flag, buf = cv2.imencode('.png', image[y:y+h, x:x+w])
print(buf.tobytes())
You can display the image in iTerm by pipe and send it to the image display command. You don't have to write a program to save the image as a name or display it on the GUI.
python face_detect.py ~/Downloads/trump.jpg | term-img
I'm using the npm command term-img. I think the same is true for the official imgcat command.
If you want to save the image, you can save the standard output.
python face_detect.py ~/Downloads/trump.jpg > president.jpg
I think there are times when you want to make your face smaller because it's too big. In that case, you can resize it by running it from pipe to imagemagick, for example.
python face_detect.py ~/Downloads/trump.jpg | convert -resize 200x200 - jpg:- | term-img
If you suddenly feel like art, you can then stream it to sed and destroy the image.
python face_detect.py ~/Downloads/trump.jpg | convert -resize 64x64 - jpg:- | sed 's/0/1/g' | term-img
Furthermore, when the urge to destroy cannot be suppressed, the image is displayed as it is by turning it with the for statement, and the destroyed image can be confirmed at high speed.
for i in $(seq 1 9); do python face_detect.py ~/Downloads/trump.jpg | convert -resize 64x64 - jpg:- | sed "s/0/$i/g" | term-img; done