cv2

Opencv imshow is right whereas imwrite is wrong?

Opencv imshow is right whereas imwrite is wrong? Question: I just want to cover an png image with another png image, cv2.imshow got the right result, cv2.imwrite got the strange result. coverImg = cv2.imread(‘./images/cover.png’, cv2.IMREAD_UNCHANGED) back = cv2.imread(‘./images/back.png’, cv2.IMREAD_UNCHANGED) x_offset = y_offset = 0 y1, y2 = y_offset, y_offset + coverImg.shape[0] x1, x2 = x_offset, …

Total answers: 1

my OpenCV color detection (red) program doesn't work. it detects all colors instead of red

my OpenCV color detection (red) program doesn't work. it detects all colors instead of red Question: import numpy as np import cv2 img=cv2.imread(‘image.jpg’) hsvFrame=cv2.cvtColor(img ,cv2.COLOR_BGR2HSV) #SET RANGE FOR RED #DEFINE MASk red_lower=np.array([0,0,204],np.uint8) red_upper=np.array([0,0,255],np.uint8) red_mask=cv2.inRange(hsvFrame,red_lower,red_upper) kernel=np.ones((5,5),"uint8") red_mask=cv2.dilate(red_mask,kernel) res_red=cv2.bitwise_and(img,img,mask=red_mask) #creating contour contours,hierarchy=cv2.findContours(red_mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) for pic,contour in enumerate(contours): area=cv2.contourArea(contour) if area>300: x,y,w,h=cv2.boundingRect(contour) imageFrame=cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2) cv2.putText(img,"red colour",(x,y), cv2.FONT_HERSHEY_SIMPLEX,1.0,(0,0,255)) cv2.imshow("detected red ",img) …

Total answers: 1

Set other video on video end (cv2)

Set other video on video end (cv2) Question: I am trying to set other video on video end in cv2. I expected it to set other video (that i provided), and the actual results was none. The window just closes and displays an error in the command line. The error is: cv2.error: OpenCV(4.6.0) D:aopencv-pythonopencv-pythonopencvmoduleshighguisrcwindow.cpp:967: error: …

Total answers: 1

CV2 imshow function not responding

CV2 imshow function not responding Question: I try to detect color on the screen in real time and when I’m using imshow function it is not responding and I can’t see my screen live Someone can help? import numpy as np from PIL import Image from mss import mss import cv2 as cv import pyautogui …

Total answers: 1

How to use image from PIL ImageGrab without saving it to a file?

How to use image from PIL ImageGrab without saving it to a file? Question: I’m trying to compare the structural similarity of two images with the skimage package but it only works if use two images saved on my pc and not when I use an image created by ImageGrab from PIL even it’s basically …

Total answers: 1

How to convert a video in numpy array

How to convert a video in numpy array Question: Program to convert a video file into a NumPy array and vice-versa. I had searched for many search engines but was unable to find the answer. Asked By: Aakarsh Kumar || Source Answers: There are multiple libraries people use for this (i.e. PyAV, decord, opencv); I …

Total answers: 1

AttributeError: partially initialized module 'cv2' has no attribute 'CascadeClassifier' (most likely due to a circular import)

AttributeError: partially initialized module 'cv2' has no attribute 'CascadeClassifier' (most likely due to a circular import) Question: I’ve been going round in circles for ages trying to figure this out. Why am I getting this attribute error? I’ve tried using absolute references, and get the same issue. PyCharm is also highlighting CascadeClassifier, cvtColor and COLOR_BGR2GRAY …

Total answers: 2

expand a selection of pixels in opencv 2

expand a selection of pixels in opencv 2 Question: I have a selection mask on an image in cv2 and I want to expand the selection of pixels such that every pixel within a radius R of an already selected pixel can be added to the selection. I would like for it to work identical …

Total answers: 2

why does cv2.imwrite method write a black square for a mnist test image dataset?

why does cv2.imwrite method write a black square for a mnist test image dataset? Question: I am trying to .imwrite one of the MNIST test images with openCV but it shows just a black square. I don’t get why!! import keras import numpy as np import mnist import tensorflow as tf from tensorflow.keras.models import Sequential …

Total answers: 2

OpenCV (4.1.2) error !_src.empty() in function 'cvtColor'

OpenCV (4.1.2) error !_src.empty() in function 'cvtColor' Question: everyone. I`m trying to run a Unet script via Google Colab for training. But I have an error with cv2 function. Here is the part of the code where the error happened: def prepare_data(img_shape, ids, reader): img_count = len(ids) x_data = np.empty((img_count,) + img_shape, dtype=’uint8′) y_data = …

Total answers: 1