Python3 & OpenCV3 [ Part 4 : Image Manipulations ] 😝

Nonpavit Detbun 🔋🍺
2 min readSep 10, 2018

--

เรียนรู้พื้นฐานการจัดการรูปภาพ

จากบทความที่แล้ว เราได้สอนการจัดการกับ Video กันไปบ้างแล้ว
ครั้งนี้เราจะมาดูคำสั่งพื้นฐานในการจัดการ รูปภาพกัน 💻

open terminal in VS Code (Ctrl + `)

workon opencv

Crop Image OpenCV

var_image_form_imread()[y: y + h, x: x + w]

  • [y: y+h, x: x+w] : เป็นคำสั่งสำหรับ crop image
  • x :ตำแหน่งที่ต้องการ crop แกน x (pixel)
  • y : ตำแหน่งที่ต้องการ crop แกน y (pixel)
  • h : ความสูงขนาดที่ต้องการ crop (pixel)
  • w : ความกว้างขนาดที่ต้องการ crop (pixel)

Resizing (scaling) Image OpenCV

cv.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]])

  • src : input image.
  • dsize : output image size; if it equals zero, it is computed as:
    dsize = Size(round(fx*src.cols), round(fy*src.rows))
    Either dsize or both fx and fy must be non-zero.
  • fx : scale factor along the horizontal axis; when it equals 0, it is computed as (double)dsize.width/src.cols
  • fy : scale factor along the vertical axis; when it equals 0, it is computed as: (double)dsize.height/src.rows
  • interpolation : interpolation method, see InterpolationFlags

Rotating Image OpenCV

cv.warpAffine(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]])

M = cv2.getRotationMatrix2D(center, angle, scale, mapMatrix)

dst(x,y) = src(M11x+M12y+M13,M21x+M22y+M23)

  • src : input image.dstoutput image that has the size dsize and the same type as src .
  • M: 2×3 transformation matrix.
  • dsize : size of the output image.
  • flags : combination of interpolation methods (see InterpolationFlags) and the optional flag WARP_INVERSE_MAP that means that M is the inverse transformation ( dst→src ).
  • borderMode : pixel extrapolation method (see BorderTypes); when borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image corresponding to the “outliers” in the source image are not modified by the function.
  • borderValue : value used in case of a constant border; by default, it is 0.

……………………………………………………………………………………….

Source Code :

แล้วพบกันใหม่ Part 5เราจะมารู้จักกับ Drawingกัน 😵

……………………………………………………………………………………….

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Nonpavit Detbun 🔋🍺
Nonpavit Detbun 🔋🍺

Written by Nonpavit Detbun 🔋🍺

I’m Electrical Engineering. 📟 I have an interest in Web App, Mobile App, IoT and Microcontroller 🧐

No responses yet

Write a response