OpenCV

Undo np.fft.fft2 to get the original image

孤街醉人 提交于 2021-02-05 06:25:06
问题 I've just started to learn about images frecuency domain. I have this function: def fourier_transform(img): f = np.fft.fft2(img) fshift = np.fft.fftshift(f) magnitude_spectrum = 20*np.log(np.abs(fshift)) return magnitude_spectrum And I want to implement this function: def inverse_fourier_transform(magnitude_spectrum): return img But I don't know how. My idea is to use magnitude_spectrum to get the original img . How can I do it? 回答1: You are loosing phases here: np.abs(fshift) . np.abs takes

How to count number of white and black pixels in color picture in python? How to count total pixels using numpy

和自甴很熟 提交于 2021-02-05 06:13:45
问题 I want to calculate persentage of black pixels and white pixels for the picture, its colorful one import numpy as np import matplotlib.pyplot as plt image = cv2.imread("image.png") cropped_image = image[183:779,0:1907,:] 回答1: You don't want to run for loops over images - it is dog slow - no disrespect to dogs. Use Numpy. #!/usr/bin/env python3 import numpy as np import random # Generate a random image 640x150 with many colours but no black or white im = np.random.randint(1,255,(150,640,3),

Trouble with “ cv2.imshow ()” function

别等时光非礼了梦想. 提交于 2021-02-05 05:45:09
问题 I installed openCV and numpy libraries in python 2.7. I've tested them using commands import cv2 and import numpy and it compiled. But when I use the cv2.imshow('frame', ----) function it displays a window but not displaying the image. And it's showing " frame is Not Responding". So, I tried with matplotlib functions for displaying image and it worked. I inserted cv2.imshow function in the 2nd case and it worked. Versions [Python-2.7.10, OpenCV-2.4.11] Below is the code, Case 1: Not Working

List available cameras OpenCV/Python

自古美人都是妖i 提交于 2021-02-05 05:43:52
问题 I have multiple webcams connected to my PC and I would like to select one camera based on its info (name, resolution etc.). Is there a way to list all the cameras available on a PC, instead of trying all the indices in cv2.VideoCapture()? 回答1: The answer is negative. OpenCV doesn't have a method for listing the available video capture devices on your system. If you look at the code you see how currently OpenCV handles invalid device indices that don't exist. For instance for MacOS here is the

OpenCV: error: (-215:Assertion failed) _src.type() == CV_8UC1 in function 'cv::equalizeHist'

泪湿孤枕 提交于 2021-02-05 02:26:06
问题 I'm trying with the code from link below to blur faces in images: How to use opencv (python) to blur faces? image = cv2.imread('45.jpg') result_image = image.copy() # Specify the trained cascade classifier face_cascade_name = "‪C:/Users/User/Desktop/haarcascade_frontalface_alt.xml" # Create a cascade classifier face_cascade = cv2.CascadeClassifier() # Load the specified classifier face_cascade.load(face_cascade_name) #Preprocess the image grayimg = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

Blur content from a rectangle with Opencv

♀尐吖头ヾ 提交于 2021-02-05 02:23:05
问题 in the following rectangle function, rectangles are drawn. // Draw the predicted bounding box void drawPred(int classId, float conf, int left, int top, int right, int bottom, Mat& frame) { //Draw a rectangle displaying the bounding box rectangle(frame, Point(left, top), Point(right, bottom), Scalar(255, 178, 50),LINE_4); //bluring region cout << frame; //Get the label for the class name and its confidence string label = format("%.2f", conf); if (!classes.empty()) { CV_Assert(classId < (int

OpenCV: error: (-215:Assertion failed) _src.type() == CV_8UC1 in function 'cv::equalizeHist'

我只是一个虾纸丫 提交于 2021-02-05 02:21:41
问题 I'm trying with the code from link below to blur faces in images: How to use opencv (python) to blur faces? image = cv2.imread('45.jpg') result_image = image.copy() # Specify the trained cascade classifier face_cascade_name = "‪C:/Users/User/Desktop/haarcascade_frontalface_alt.xml" # Create a cascade classifier face_cascade = cv2.CascadeClassifier() # Load the specified classifier face_cascade.load(face_cascade_name) #Preprocess the image grayimg = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

OpenCV: error: (-215:Assertion failed) _src.type() == CV_8UC1 in function 'cv::equalizeHist'

早过忘川 提交于 2021-02-05 02:20:49
问题 I'm trying with the code from link below to blur faces in images: How to use opencv (python) to blur faces? image = cv2.imread('45.jpg') result_image = image.copy() # Specify the trained cascade classifier face_cascade_name = "‪C:/Users/User/Desktop/haarcascade_frontalface_alt.xml" # Create a cascade classifier face_cascade = cv2.CascadeClassifier() # Load the specified classifier face_cascade.load(face_cascade_name) #Preprocess the image grayimg = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

Blur content from a rectangle with Opencv

心不动则不痛 提交于 2021-02-05 02:18:43
问题 in the following rectangle function, rectangles are drawn. // Draw the predicted bounding box void drawPred(int classId, float conf, int left, int top, int right, int bottom, Mat& frame) { //Draw a rectangle displaying the bounding box rectangle(frame, Point(left, top), Point(right, bottom), Scalar(255, 178, 50),LINE_4); //bluring region cout << frame; //Get the label for the class name and its confidence string label = format("%.2f", conf); if (!classes.empty()) { CV_Assert(classId < (int

Remove top section of image above border line to detect text document

ε祈祈猫儿з 提交于 2021-02-04 19:47:06
问题 Using OpenCV (python) I am trying to remove the section of image which is above the border line (white area in this sample image where ORIGINAL is writtn) in the image shown below Using horizontal and vertical kernels I am able to draw the wireframe, however that does not work many times because many times due to scanning quality few horizontal or vertical lines appear outside the wireframe which causes wrong contour detection. In this image also you can see on top right there is noise which