[PYTHON] The image display function of iTerm is convenient for image processing.

The new version of iTerm has the ability to display images in the terminal (https://www.iterm2.com/documentation-images.html).

image (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

image

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

Combine with other commands

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

image

When you want to glitch

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 image

When you want to glitch a lot

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 image

Recommended Posts

The image display function of iTerm is convenient for image processing.
Image processing? The story of starting Python for
Understand the function of convolution using image processing as an example
Let's talk about the tone curve of image processing ~ LUT is amazing ~
Why is cross entropy used for the objective function of the classification problem?
What is the activation function?
100 language processing knock-42: Display of the phrase of the person concerned and the person concerned
100 language processing knock-29: Get the URL of the national flag image
Which method is best for asynchronous processing of TCP server?
What is the interface for ...
What is the Callback function?
2015-11-26 python> Display the function list of the module> import math> dir (math)
The image is a slug
Gold needle for when it becomes a stone by looking at the formula of image processing
Real-time display of server-side processing progress in the browser (implementation of progress bar)
Consider the speed of processing to shift the image buffer with numpy.ndarray
A function that measures the processing time of a method in python
Why is distributed representation of words important for natural language processing?
[For beginners] Recursive function (Tower of Hanoi is easy to understand!)
for, continue, break Explain the flow of iterative processing in Python3-Part 1
Is the probability of precipitation correct?
Personal notes for python image processing
What is the python underscore (_) for?
Science "Is Saito the representative of Saito?"
I tried to get the batting results of Hachinai using image processing
[Ota Ward] Check the status of application processing for special flat-rate benefits
[Example of Python improvement] What is the recommended learning site for Python beginners?
Trial to judge the timing of the progress display of the for loop using 0b1111 ~
About the main tasks of image processing (computer vision) and the architecture used
Python: I want to measure the processing time of a function neatly
Basics of binarized image processing with Python
Image display taken with the built-in ISIGHT
What is the ETL processing framework clivoa?
Grayscale by matrix-Reinventor of Python image processing-
Display the graph of tensorBoard on jupyter
About the arguments of the setup function of PyCaret
[python] [meta] Is the type of python a type?
Introducing the addModuleCleanup / doModuleCleanups function for unittest
The third night of the loop with for
Pandas of the beginner, by the beginner, for the beginner [Python]
Drawing with Matrix-Reinventor of Python Image Processing-
Hashing algorithm for determining the same image
The second night of the loop with for
The story of blackjack A processing (python)
Solution: The jedi-vim pop-up display is broken
The update of conda is not finished.
The backslash of the Japanese keyboard is "ro"
Matrix Convolution Filtering-Reinventor of Python Image Processing-
[IOS] Change the display time for each frame of GIF animation in Pythonista3.
Django shift creation function Added basic work shift registration function for days of the week
[Python] Number of integer sequences of length n for which the sum is m
Let's display a simple template that is ideal for Django for the first time
I tried to automate the face hiding work of the coordination image for wear