How i can pixelate a image from opencv video capture in real time [closed]
Asked Answered
D

1

0
import cv2
import matplotlib 
  
capture = cv2.VideoCapture(0)
x=0 
while(True):
      
    ret, frame = capture.read()
 
    grayFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    cv2.imshow('video gray', grayFrame)
    cv2.imshow('video original', frame)
    print(grayFrame)
    w, h = (16, 16)
    temp = cv2.resize(input, (w, h), interpolation=cv2.INTER_LINEAR)
    cv2.imshow('video original', output)

    if cv2.waitKey(1) == 27:
        break
Depression answered 6/9, 2020 at 19:43 Comment(2)
https://mcmap.net/q/629419/-how-to-pixelate-a-square-image-to-256-big-pixels-with-pythonPanjabi
write in EnglishLickspittle
A
4

Here is how to do that in Python/OpenCV.

First, use INTER_AREA for resizing. Also, resize down and back up.

Input:

enter image description here

import cv2

# read the input
img = cv2.imread("barn.jpg")
hh, ww = img.shape[:2]

# resize down, then back up
w, h = (16, 16)
result = cv2.resize(img, (w, h), interpolation=cv2.INTER_AREA)
result = cv2.resize(result, (ww, hh), interpolation=cv2.INTER_AREA)

# save result
cv2.imwrite("barn_pixelated.png", result)

# show result
cv2.imshow("result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()

enter image description here

Asuncionasunder answered 6/9, 2020 at 21:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.