OpenCV

OpenCV 4 TypeError: Expected cv::UMat for argument 'labels'

大城市里の小女人 提交于 2021-01-22 09:51:10
问题 I am writing a facial recognition program and I keep getting this error when I try to train my recognizer TypeError: Expected cv::UMat for argument 'labels' my code is def detect_face(img): gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml") faces = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5); if (len(faces)==0): return None, None (x, y, w, h) = faces[0] return gray[y:y+w, x:x

opencv error multiplying 2 Mat's

我怕爱的太早我们不能终老 提交于 2021-01-22 05:18:29
问题 I am multiplying 2 matrices (Mat objects) in opencv. Here is how first Mat was generated : cv::Mat R(m, k, CV_8UC1); rm.generateRandomMatrix(m, k, 255, R); Here is how the second one was generated: for (int i=0; i<=n; i++) { randomMatrix_Xi rm; cv::Mat Xi(k, 1, CV_8UC1); rm.generateRandomMatrix(k, 1, 255, Xi); random_Xi_Vectors.push_back(Xi); sleep(2); } Here is the generateRandomMatrix() function definition which I have used in both places: int randomMatrix_Xi::generateRandomMatrix(int m,

opencv error multiplying 2 Mat's

◇◆丶佛笑我妖孽 提交于 2021-01-22 05:18:06
问题 I am multiplying 2 matrices (Mat objects) in opencv. Here is how first Mat was generated : cv::Mat R(m, k, CV_8UC1); rm.generateRandomMatrix(m, k, 255, R); Here is how the second one was generated: for (int i=0; i<=n; i++) { randomMatrix_Xi rm; cv::Mat Xi(k, 1, CV_8UC1); rm.generateRandomMatrix(k, 1, 255, Xi); random_Xi_Vectors.push_back(Xi); sleep(2); } Here is the generateRandomMatrix() function definition which I have used in both places: int randomMatrix_Xi::generateRandomMatrix(int m,

How to correctly increase the size of rectangle found with cv::findContours

自古美人都是妖i 提交于 2021-01-21 11:22:02
问题 I have a function that uses cv::findContours to create rectangles around one or many detected objects which I then want to use to store a cropped image of each object. My problem is that cv::findContours draws its rectangle right around the object but since I also need parts of the background around the object I want to increase each rectangles size. This could be easily done with something like rectangleVector[i] += cv::Size(10, 10) . The problem with this though is that if the detected

How to correctly increase the size of rectangle found with cv::findContours

﹥>﹥吖頭↗ 提交于 2021-01-21 11:21:22
问题 I have a function that uses cv::findContours to create rectangles around one or many detected objects which I then want to use to store a cropped image of each object. My problem is that cv::findContours draws its rectangle right around the object but since I also need parts of the background around the object I want to increase each rectangles size. This could be easily done with something like rectangleVector[i] += cv::Size(10, 10) . The problem with this though is that if the detected

How to correctly increase the size of rectangle found with cv::findContours

强颜欢笑 提交于 2021-01-21 11:20:27
问题 I have a function that uses cv::findContours to create rectangles around one or many detected objects which I then want to use to store a cropped image of each object. My problem is that cv::findContours draws its rectangle right around the object but since I also need parts of the background around the object I want to increase each rectangles size. This could be easily done with something like rectangleVector[i] += cv::Size(10, 10) . The problem with this though is that if the detected

Faster way than concatenate of combining multiple cv2 images (numpy arrays) in python?

假如想象 提交于 2021-01-21 10:19:08
问题 I have 100 small images which I want to combine into one large (10x10) grid image for display with imshow. Each image (as a numpy array) is within the variable of a cell object. At the moment I'm using concatenate to first create vertical strips then using concatenate to connect all of those strips but it seems kinda clunky. Is there a better way to do this? I feel like I should be able to just create a numpy array the size of the final image (800 x 600) then plop each image in, but it seems

Python OpenCV实例:图像灰度拉伸

倖福魔咒の 提交于 2021-01-21 05:01:59
#coding:utf-8 ''' 灰度拉伸 定义:灰度拉伸,也称对比度拉伸,是一种简单的线性点运算。作用:扩展图像的 直方图,使其充满整个灰度等级范围内 公式: g(x,y) = 255 / (B - A) * [f(x,y) - A], 其中,A = min[f(x,y)],最小灰度级;B = max[f(x,y)],最大灰度级; f(x,y)为输入图像,g(x,y)为输出图像 缺点:如果灰度图像中最小值A=0,最大值B=255,则图像没有什么改变 ''' import cv2 import numpy as np def grey_scale(image): img_gray = cv2.cvtColor(image,cv2.COLOR_RGB2GRAY) rows,cols = img_gray.shape flat_gray = img_gray.reshape((cols * rows,)).tolist() A = min(flat_gray) B = max(flat_gray) print('A = %d,B = %d' %(A,B)) output = np.uint8(255 / (B - A) * (img_gray - A) + 0.5) return output src = cv2.imread('datas/f4.jpg') result =

Parse error. Expected a command name

穿精又带淫゛_ 提交于 2021-01-20 10:54:02
Parse error. Expected a command name CMake Error at CMakeLists.txt:9: Parse error. Expected a command name, got unquoted argument with text "set(OpenCV_DIR". 原因:出现了中文括号,正确代码: set (OpenCV_DIR E:/opencv/opencv) #opencv find_package(OpenCV REQUIRED) 来源: oschina 链接: https://my.oschina.net/u/4383691/blog/4915016

How to convert a rgb image into a cmyk?

二次信任 提交于 2021-01-20 06:13:28
问题 I want to convert a rgb image into cmyk. This is my code the first problem is, when I divide each pixel by 255 the value closes to zero so the result image is approximately black! The second problem is, I don't know how to convert the 1 channel resulted image to 4 channel. Of course I'm not sure the made CMYK in the following code is correct. Thank you for your attention import cv2 import numpy as np import time img = cv2.imread('image/dr_trump.jpg') B = img[:, :, 0] G = img[:, :, 1] R = img[