<jupyter_start><jupyter_text>"""Hint: 人物原始邊框座標 (60, 40), (420, 510)請根據 Lena 圖做以下處理對明亮度做直方圖均衡處理水平鏡像 + 縮放處理 (0.5 倍)畫出人物矩形邊框"""<jupyter_code>import cv2
import numpy as np

img = cv2.imread('lena.png')
img_rect = img.copy()
cv2.rectangle(img_rect, (60, 40), (420, 510), (0, 0, 255), 3)

while True:
    cv2.imshow('image', img_rect)
    k = cv2.waitKey(0)
    if k == 27:
        cv2.destroyAllWindows()
        break
img_hw = img.copy()
point1 = (60, 40)
point2 = (420, 510)

"""
對明亮度做直方圖均衡
"""
# 原始 BGR 圖片轉 HSV 圖片
img_hw = cv2.cvtColor(img_hw, cv2.COLOR_BGR2HSV)

# 對明亮度做直方圖均衡 -> 對 HSV 的 V 做直方圖均衡
img_hw[..., -1] = cv2.equalizeHist(img_hw[..., -1])  # equalizeHist   圖像均衡化

# 將圖片轉回 BGR
img_hw = cv2.cvtColor(img_hw, cv2.COLOR_HSV2BGR)

"""
畫出人物矩形邊框
"""
cv2.rectangle(img_hw, point1, point2, (0, 0, 255), 3)

"""
水平鏡像 + 縮放處理 (0.5 倍)
"""
# 水平鏡像 (圖片)
img_hw = img_hw[:, ::-1, :]

# 縮放處理
img_hw = cv2.resize(img_hw, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_LINEAR)

while True:
    cv2.imshow('image', img_hw)
    k = cv2.waitKey(0)
    if k == 27:
        cv2.destroyAllWindows()
        break<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1772039180765806, 'fraction_numerical': 0.0730186999109528, 'mean_word_length': 3.683333333333333, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '589772', 'license': 'MIT', 'n_tokens_mistral': 669, 'n_tokens_neox': 669, 'n_words': 109, 'path': 'Day5/Day5.ipynb', 'repo_name': 'freddykao/Opencv_for_kaggle', 'size': '1123'}