image-processing

Efficiently converting color to transparency in python

余生颓废 提交于 2021-02-16 18:13:25
问题 GIMP has a convenient function that allows you to convert an arbitrary color to an alpha channel. Essentially all pixels become transparent relative to how far away from the chosen color they are. I want to replicate this functionality with opencv. I tried iterating through the image: for x in range(rows): for y in range(cols): mask_img[y, x][3] = cv2.norm(img[y, x] - (255, 255, 255, 255)) But this is prohibitively expensive, it takes about 10 times longer to do that iteration than it takes

Getting color from external image using JavaScript

拜拜、爱过 提交于 2021-02-16 14:40:13
问题 So, I have tried looking this up in many places, but have not yet found an answer for my situation. What I have is a loop, looping for each hour in a day for every day in a year, and, with many insanely ridiculous mathematical equations, getting the angle and distance of the sun at a specific location. The outcome of the equations gives me a number that I use as an x value to obtain to the image's pixel color at that point. The image is a gradient: when x=0; no sunlight, when x=(1/2

Is there a simple method to highlight the mask?

痞子三分冷 提交于 2021-02-16 13:16:10
问题 If I have mask like And I have a image( the size is same to the mask) like I want to hightlight the mask in the image. If I'm in other Language,I just As you can see, the result image have a transparent red show the mask. I hope implement this in OpenCV. So I write this code #include <opencv.hpp> using namespace cv; using namespace std; int main() { Mat srcImg = imread("image.jpg"); Mat mask = imread("mask.jpg", IMREAD_GRAYSCALE)>200; for(int i=0;i<srcImg.rows;i++) for(int j=0;j<srcImg.cols;j

Is there a simple method to highlight the mask?

我与影子孤独终老i 提交于 2021-02-16 13:15:18
问题 If I have mask like And I have a image( the size is same to the mask) like I want to hightlight the mask in the image. If I'm in other Language,I just As you can see, the result image have a transparent red show the mask. I hope implement this in OpenCV. So I write this code #include <opencv.hpp> using namespace cv; using namespace std; int main() { Mat srcImg = imread("image.jpg"); Mat mask = imread("mask.jpg", IMREAD_GRAYSCALE)>200; for(int i=0;i<srcImg.rows;i++) for(int j=0;j<srcImg.cols;j

How to straight an image by selecting four points in an Image?

本小妞迷上赌 提交于 2021-02-16 05:11:58
问题 I want to straight an image by selecting four points in the image using getPerspectiveTransform() method of opencv in java. I know it can be done using with opencv in python: getPerspectiveTransform. If anyone used this to achieve image straightening ..please help. 回答1: There is perspective transformation which can be used to achieve quad to quad conversion. In OpenCV , there are mainly two methods to achieve getPerspectiveTransformation() and warpPerspective() method. Here is a sample code

How to straight an image by selecting four points in an Image?

試著忘記壹切 提交于 2021-02-16 05:09:42
问题 I want to straight an image by selecting four points in the image using getPerspectiveTransform() method of opencv in java. I know it can be done using with opencv in python: getPerspectiveTransform. If anyone used this to achieve image straightening ..please help. 回答1: There is perspective transformation which can be used to achieve quad to quad conversion. In OpenCV , there are mainly two methods to achieve getPerspectiveTransformation() and warpPerspective() method. Here is a sample code

How do I fix “RuntimeError: Unable to open shape_predictor_68_face_landmarks.dat” while using google colab?

烈酒焚心 提交于 2021-02-11 15:18:12
问题 I am writing the following Python code in Google Colaboratory and get an error: Code : import cv2 import dlib cap = cv2.VideoCapture(0) hog_face_detector = dlib.get_frontal_face_detector() dlib_facelandmark = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") while True: _, frame = cap.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = hog_face_detector(gray) for face in faces: face_landmarks = dlib_facelandmark(gray, face) for n in range(0, 16): x = face_landmarks.part

Decode image bytes data stream to JPEG

守給你的承諾、 提交于 2021-02-11 14:35:31
问题 I am struggling to successfully decode a JPEG image from bytes, back to JPEG again. I started from encoded frame from a MJPG bytes stream, which I want to decode in order to manipulate with OpenCV. I am a bit of a newbie at Python, numpy, opencv etc! I now have the frame JPG data in a text file as: b'\xf\xd8\xff\xdb\x00....etc etc for purposes of testing: code seems to fail when I try to Resize the numpy array to the original video stream resolution (640, 480) on line 14 (npFlat.reshape((640

Find contours based on edges

ⅰ亾dé卋堺 提交于 2021-02-11 14:13:07
问题 I want to detect the contours of an equipment label. Although the code runs correctly, it never quite detects the contours of the label. Original Image Using this code: import numpy as np import cv2 import imutils #resizeimage import pytesseract # convert img to string pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe" # Read the image file image = cv2.imread('Car Images/5.JPG') # Resize the image - change width to 500 image = imutils.resize(image, width

How to find duplicated jpgs by content?

人走茶凉 提交于 2021-02-11 12:40:57
问题 I'd like to find and remove an image in a series of folders. The problem is that the image names are not necessarily the same. What I did was to copy an arbitrary string from the images bytecode and use it like grep -ir 'YA'uu�KU���^H2�Q�W^YSp��.�^H^\^Q��P^T' . But since there are thousands of images this method lasts for ever. Also, some images are created by imagemagic of the original, so can not use size to find them all. So I'm wondering what is the most efficient way to do so? 回答1: