Programowanie w systemie UNIX/OpenCV: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
m →‎Instalacja: sudo apt install libopencv-dev python3-opencv
m →‎python: program
Linia 513:
 
==python==
 
Program do analizy obrazu<ref>[https://stackoverflow.com/questions/74582777/is-there-any-good-command-to-get-pixels-gray-value-in-this-case-im-working-on stackoverflow question: is-there-any-good-command-to-get-pixels-gray-value-in-this-case-im-working-on]</ref>
* nie korzysta z pętli fo i CPU ( są one powolne i podatne na błędy )
* wykorzystuje wektoryzację z pomocą bibliotek Numpy lub OpenCV.
 
<syntaxhighlight lang="python">
import cv2
import numpy as np
 
# Load image
im = cv2.imread('Mushroom1.jpg', cv2.IMREAD_GRAYSCALE)
 
# Calculate total number of pixels in image
nPixels = im.size
 
# Iterate over the possible threshold values, skipping 10 at a time for speed of development/checking
for T in range(1,255,10):
# Make all pixels under threshold black, leaving those above threshold unchanged
thresholded = (im < T) * im
# Count the non-zero pixels
nonZero = cv2.countNonZero(thresholded)
Zero = nPixels - nonZero
# Sum the non-zero pixels
sum = np.sum(thresholded)
# Print some statistics
print(f'T={T}, zero={Zero}, nonZero={nonZero}, sum={sum}')
# Save the image for animation
cv2.imwrite(f'DEBUG-T{T:03}.png', thresholded)
</syntaxhighlight>
 
 
===gui ===
* python <ref>[https://erget.wordpress.com/2014/03/13/building-an-interactive-gui-with-opencv/ building-an-interactive-gui-with-opencv by erget]</ref><ref>[http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_table_of_contents_gui/py_table_of_contents_gui.html opencv-python-tutroals gui]</ref>