<jupyter_start><jupyter_text>OpenCV - Code snippets By <NAME> / Ph.D https://github.com/JSJeong-me/KOSA-Vision email: <EMAIL>  Copyrights 2021<jupyter_code>!pwd
!ls -l<jupyter_output>total 176
-rw-r--r-- 1 root root 172127 Sep 13 05:40 data3.png
drwxr-xr-x 1 root root   4096 Sep  1 19:26 sample_data<jupyter_text>![Computer-vision-tasks-Adapted-from.png](attachment:d59cb896-f21f-4a6b-a8a3-74c696d1584d.png)  !pip install opencv-python==4.4.0.46  Image reads and wirtes<jupyter_code>import cv2
import platform
from matplotlib import pyplot as plt
print('OpenCV version: {}'.format(cv2.__version__))
print('Python version: {}'.format(platform.python_version()))
!ls -l
src = cv2.imread('./data3.png')
type(src)
src.ndim
src.shape
rgb_src = cv2.cvtColor(src, cv2.COLOR_BGR2RGB)
#flipped = cv2.flip(src, -1)
#cv2.imshow('Image', rgb_src)
#cv2.imshow('Image flipped', flipped)

plt.imshow(rgb_src)
plt.show()
rgb_src.shape
# columv 260:350
# row 70:160
cropped_image = rgb_src[70:175, 260:370]
plt.imshow(cropped_image)
plt.show()
cropped_image_2 = rgb_src[275:375, 450:570]
plt.imshow(cropped_image_2)
plt.show()
cropped_image_2.shape<jupyter_output><empty_output><jupyter_text>Video reads and frame sampling rates controll<jupyter_code>import time
import cv2
# 0: Webcam or video mp4, avi etc.imput files
#cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture('.\\images\\park_people.mp4')
# Image resolution, image width & height frame cpunts & frame rates 
print('Frame width:  {0:03d}'.format(round(cap.get(cv2.CAP_PROP_FRAME_WIDTH))))
print('Frame height: {0:03d}'.format(round(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))))
print('Frame count:  {0:03d}'.format(round(cap.get(cv2.CAP_PROP_FRAME_COUNT))))

fps = round(cap.get(cv2.CAP_PROP_FPS))
print('FPS:          {0:03d}'.format(fps))
prev_time = 0
FPS = 10
while True:
    ret, frame = cap.read()

    if not ret:
        break
        
    frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5)
    
    current_time = time.time() - prev_time

    if (ret is True) and (current_time > 1./ FPS):
        prev_time = time.time()
     
        cv2.imshow('frame', frame)

    if cv2.waitKey(10) == 27:
        break

cap.release()
cv2.destroyAllWindows()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1490990990990991, 'fraction_numerical': 0.06531531531531531, 'mean_word_length': 4.680306905370844, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 15, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '26255', 'license': 'MIT', 'n_tokens_mistral': 985, 'n_tokens_neox': 893, 'n_words': 173, 'path': 'python/1_cv_intro.ipynb', 'repo_name': 'skawns0724/KOSA-Big-Data_Vision', 'size': '2236'}