opencv-python

How to create a transparent mask in opencv-python

时光毁灭记忆、已成空白 提交于 2021-02-18 13:53:35
问题 I have sign (signs with arbitrary shape) images with white background and I want to get an image of the sign with transparent background. I have managed to create a mask and apply it to the image and thought making the mask transparent would be doable. I searched a lot here and elsewhere, but nothing really helped me. import cv2 import numpy as np file_name = "/path/to/input/img/Unbenannt.jpg" # can be also .png img = cv2.imread(file_name) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) th,

How to create a transparent mask in opencv-python

南楼画角 提交于 2021-02-18 13:52:37
问题 I have sign (signs with arbitrary shape) images with white background and I want to get an image of the sign with transparent background. I have managed to create a mask and apply it to the image and thought making the mask transparent would be doable. I searched a lot here and elsewhere, but nothing really helped me. import cv2 import numpy as np file_name = "/path/to/input/img/Unbenannt.jpg" # can be also .png img = cv2.imread(file_name) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) th,

Opencv-Overlay a Video on Webcam

℡╲_俬逩灬. 提交于 2021-02-11 12:03:55
问题 Guys I am having problem on overlaying my video to webcam. I can open webcam without any issues or errors but my video is not being showed. I am trying to play my video in specific x-y coordinates.I take most of my code from an other stackoverflow question but I cannot find it know so that I cannot mention it here. So can someone help me to solve this? Why my video is not being played in my webcam? I have following code: from os.path import sep import cv2 as cv2 # load the overlay image. size

opencv issues with M1 MAC - OpenCV imshow doesnot work

∥☆過路亽.° 提交于 2021-02-11 08:20:35
问题 I purchased a M1 Mac. Is anyone having issues with imshow with opencv. I did pip install opencv-python and brew install opencv and brew install opencv as well. import cv2 import urllib import numpy as np import requests url = 'https://www.visitcalifornia.com/sites/visitcalifornia.com/files/styles/welcome_image/public/vc_crtr_borntobewild_module_mendocino_st_rf_623667652_1280x640.jpg' from skimage import io img = io.imread(url) img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) cv2.imshow('URL Image',

opencv issues with M1 MAC - OpenCV imshow doesnot work

戏子无情 提交于 2021-02-11 08:19:53
问题 I purchased a M1 Mac. Is anyone having issues with imshow with opencv. I did pip install opencv-python and brew install opencv and brew install opencv as well. import cv2 import urllib import numpy as np import requests url = 'https://www.visitcalifornia.com/sites/visitcalifornia.com/files/styles/welcome_image/public/vc_crtr_borntobewild_module_mendocino_st_rf_623667652_1280x640.jpg' from skimage import io img = io.imread(url) img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) cv2.imshow('URL Image',

OpenCV-(-215:Assertion failed) _src.total() > 0 in function 'cv::warpPerspective'

余生颓废 提交于 2021-01-29 15:35:57
问题 My full code: import cv2 as cv import numpy as np cap = cv.VideoCapture(0 + cv.CAP_DSHOW) imgTarget = cv.imread('photos\TargetImage.jpg') #bu resmimiz myVid = cv.VideoCapture('photos\video.mp4') detection = False frameCounter = 0 imgVideo = cap.read() success, imgVideo = myVid.read() hT,wT,cT = imgTarget.shape #burada resmimizin yüksekliğini, kalınlığını genişliğini falan alıyoruz. '''while myVid.isOpened(): success, Video = myVid.read() if success: Video = cv.resize(Video, (wT, hT))'''

try to implement cv2.findContours for person detection

假装没事ソ 提交于 2021-01-29 07:32:49
问题 I'm new to opencv and I'm trying to detect person through cv2.findContours with morphological transformation of the video. Here is the code snippet.. import numpy as np import imutils import cv2 as cv import time cap = cv.VideoCapture(0) while(cap.isOpened()): ret, frame = cap.read() #frame = imutils.resize(frame, width=700,height=100) gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) gray = cv.GaussianBlur(gray, (21, 21), 0) cv.accumulateWeighted(gray, avg, 0.5) mask2 = cv.absdiff(gray, cv

Python opencv optimal thresholding

人盡茶涼 提交于 2021-01-29 07:20:08
问题 I am trying to detect roi in my image dataset using Otsu thresholding. While in some cases results are on the point, some cases are not that good. I'm using the code below. import cv2 as cv import numpy as np path = "./images/{}.png".format for num in range(1000): filename = path(num) img = cv.imread(filename, cv.IMREAD_GRAYSCALE) res = cv.threshold(img, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)[1] res = np.hstack((img, res)) cv.imwrite(filename.replace(".png", "_.png"), res) While these

how to make work opencv with FFMPEG driver

点点圈 提交于 2021-01-28 04:06:09
问题 I have a camera on my linuxbox it is working well: # $ ls -al /dev/video* # crw-rw----+ 1 root video 81, 0 janv. 8 16:13 /dev/video0 # crw-rw----+ 1 root video 81, 1 janv. 8 16:13 /dev/video1 # $ groups # adm cdrom sudo dip video plugdev lpadmin lxd sambashare docker libvirt From python with cv2 it work well with the default driver CAP_V4L2 >>> from pathlib import Path >>> import cv2 >>> print(cv2.VideoCapture(0, apiPreference=cv2.cv2.CAP_V4L2).isOpened()) True >>> I would like to access it

OpenCV: using Canny and Shi-Tomasi to detect round corners of a playing card

最后都变了- 提交于 2021-01-27 11:47:59
问题 I want to do some planar rectification, to convert from left to right: I have the code to do the correction, but I need the 4 corner coords. I'm using the following code to find them: import cv2 image = cv2.imread('input.png') gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) canny = cv2.Canny(gray, 120, 255, 1) corners = cv2.goodFeaturesToTrack(canny,4,0.5,50) for corner in corners: x,y = corner.ravel() cv2.circle(image,(x,y),5,(36,255,12),-1) cv2.imshow("result", image) cv2.waitKey() It reads