如何操縱跟踪器區域使其變成方形? (How can I manipulate the tracker area to make it into a square shape?)


問題描述

如何操縱跟踪器區域使其變成方形? (How can I manipulate the tracker area to make it into a square shape?)

我目前正在開發一個關於相機跟踪應用程序的項目。當我不得不改變檢測到的物體的區域時,我發現沒有什麼麻煩。該區域必須轉換為正方形,以便在顯示到屏幕時變得更加合適和真實。

這是我正在處理的幾行代碼。

for cam, coll in _colls.items():

get all track

tracks = coll.getAllTracks() #tracks is a dictionary that stores the details of object that being detected.

for x in range(len(tracks)):

# get the selected area for croping
edge = tracks[x]['box']

crop_img = frame[int(edge[0]):int(edge[2]), int(edge[1]):int(edge[3])]
# edge[0] = ymin
# edge[1] = xmin
# edge[2] = ymax
# edge[3] = xmax

</code></pre>

根據該代碼,我得到了一個正在檢測對象的區域。

enter image description here

問題是當我得到了邊緣,它並不總是方形的,它也可以是矩形的。


參考解法

方法 1:

You have to compute the width and height of the area. Compute the difference between the width and the height and enlarge the smaller side of the area. For isntance:

left, right, top, bottom = edge[0], edge[1], edge[2], edge[3]

width = right ‑ left
height = bottom ‑ top
delta = width ‑ height

if delta > 0:
    top ‑= delta / 2
    bottom += delta / 2
else
    left ‑= ‑delta / 2
    right += ‑delta / 2

crop_img = frame[int(left):int(top), int(right):int(bottom)]

(by Idhar DzulfikarRabbid76)

參考文件

  1. How can I manipulate the tracker area to make it into a square shape? (CC BY‑SA 2.5/3.0/4.0)

#image-processing #Python #image-manipulation #OpenCV






相關問題

在 matlab 中用 imread 讀取圖像文件會給出什麼樣的表示? (reading a image file with imread in matlab gives what kind of representation?)

使用 CRF 的圖像標記性能 (Image labeling performance using CRF)

Opencv:獲取圖像中的段大小並刪除小段 (Opencv: Get segments sizes in image and remove small segments)

將 PHP 頁面作為圖像返回 (Return a PHP page as an image)

我在哪裡可以找到有關雙三次插值和 Lanczos 重採樣的好讀物? (Where can I find a good read about bicubic interpolation and Lanczos resampling?)

從圖像中刪除白色背景 (Remove white backgrounds from images)

如何填充投影圖像的空白部分? (How to fill empty parts of a projected image?)

如何使圖像亮度均勻(使用 Python/PIL) (How to Make an Image Uniform Brightness (using Python/PIL))

圖像處理公式可生成類似通過 Mac 相機拍攝的照片的效果 (Image manipulation formula to generate effects like pictures taken via Mac's camera)

從照片生成漂亮的直方圖? (generating nice looking histogram from photo?)

使用 DjVu 工具進行背景/前景分離? (Using the DjVu tools to for background / foreground seperation?)

如何操縱跟踪器區域使其變成方形? (How can I manipulate the tracker area to make it into a square shape?)







留言討論