OpenCV

OpenCV - How to apply Kmeans on a grayscale image?

我怕爱的太早我们不能终老 提交于 2021-01-29 13:17:52
问题 I am trying to cluster a grayscale image using Kmeans. First, I have a question: Is Kmeans the best way to cluster a Mat or are there newer more efficient approaches? Second, when I try this: Mat degrees = imread("an image" , IMREAD_GRAYSCALE); const unsigned int singleLineSize = degrees.rows * degrees.cols; Mat data = degrees.reshape(1, singleLineSize); data.convertTo(data, CV_32F); std::vector<int> labels; cv::Mat1f colors; cv::kmeans(data, 3, labels, cv::TermCriteria(cv::TermCriteria::EPS

How to fill black region by white inside a write circular shaped object using OpenCV and Python?

折月煮酒 提交于 2021-01-29 13:00:40
问题 I would like to detect black region inside a write circular or semi circular shaped object and then fill it with white color. Here, I have shown two input images below. This two images have some black region surrounded by white. It these black can be converted to white, the perimeter of the whole object can be calculated. For example: I got one image (below) from where I could calculate perimeter. Are there any function or method in OpenCV and python for this operation? 回答1: You can try the

Process finished with exit code 134 (interrupted by signal 6: SIGABRT) in python OpenCV

让人想犯罪 __ 提交于 2021-01-29 11:22:49
问题 import numpy as np import cv2 cap = cv2.VideoCapture(0) while(True): # Capture frame-by-frame ret, frame = cap.read() # Our operations on the frame come here gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Display the resulting frame cv2.imshow('frame',gray) if cv2.waitKey(1) & 0xFF == ord('q'): break # When everything done, release the capture cap.release() cv2.destroyAllWindows() I'm using Python and OpenCV in Pycharm IDE. When I try to open the webcam using OpenCV, it gives the following

Detect facial landmarks inside a detected face image using opencv dnn face detector

丶灬走出姿态 提交于 2021-01-29 11:12:42
问题 I trying to detect the 68 facial landmarks of human face. I detected the face using OpenCV dnn face detector as in https://www.pyimagesearch.com/2018/02/26/face-detection-with-opencv-and-deep-learning/ The face detection process done successfully, this is my code: # import the necessary packages import numpy as np import argparse import cv2 import dlib ap = argparse.ArgumentParser() ap.add_argument("-c", "--confidence", type=float, default=0.5, help="minimum probability to filter weak

Detecting Arc in an image using OpenCV and Python

余生长醉 提交于 2021-01-29 11:06:32
问题 I want to detect a arc in an image using opencv and Python. I want is to detect the green highlighted part of the image. This shape is of like arc type. After applying thresholding on SobelX image bounding box are coming on these arcs. I don't want bounding box on these arcs. Is there anyway to exclude these arc from top. 回答1: Try this code : It will detect all the circle, curve and arc : int main() { //RANSAC //load edge image cv::Mat color = cv::imread("../circleDetectionEdges.png"); //

LabVIEW not responding when I run this code. C++ code issue or LabVIEW issue?

喜你入骨 提交于 2021-01-29 10:38:42
问题 For some background, I am compiling in Visual Studio 2019 and running the code inside LabVIEW 2017. The reason I am doing it in LabVIEW is for research to control a robotic gantry. This is the vision system and it is supposed to detect rectangles (wirebond pads for silicon detectors). I need it to atleast show me a picture or something but when I run it in LabVIEW, it just says it is not responding and makes me hard close the program. So frustrating! If theres no huge errors in my C++ code

OpenCV can't be found but can be imported

China☆狼群 提交于 2021-01-29 10:31:20
问题 I've installed opencv from source using a virtualenv, however I faced some errors and needed to reinstall it. I tried removing all the files with sudo find / -name "opencv" -exec rm {} \; and checked if the package was removed with pkg-config --modversion opencv , and it said it could not be found, but when I open the terminal with python3 and enter import cv2 then print(cv2.__version__) , the terminal returns 4.0.0 . How can I completely remove opencv? I'm on Ubuntu 18.04 LTS. 回答1: Run this

OpenCV Transparent API UMat is missing

回眸只為那壹抹淺笑 提交于 2021-01-29 09:57:51
问题 I tried to use OpenCV Transparent API UMat class for hardware acceleration in my desktop java application but I couldn't find the UMat class implementation. I'm using OpenCV version 4.1 , where T-API java bindings are said to be available up from version 3.0 as said here: T-API (transparent API) has been introduced, this is transparent GPU acceleration layer using OpenCL. It does not add any compile-time or runtime dependency of OpenCL. When OpenCL is available, it’s detected and used, but it

(-215:Assertion failed) with initUndistortRectifyMap

强颜欢笑 提交于 2021-01-29 09:48:13
问题 I am getting (-215:Assertion failed) while using initUndistortRectifyMap Python 3 function. Please let me know why I am getting this error as below: map1,map2 = cv2.initUndistortRectifyMap(cam_m, dist_c, None, None, (2316,3088), cv2.CV_32FC1) cv2.error: OpenCV(4.1.0) /tmp/opencv-20190505-12101-14vk1fh/opencv-4.1.0/modules/calib3d/src/undistort.cpp:232: error: (-215:Assertion failed) A.size() == Size(3,3) && A.size() == R.size() in function 'initUndistortRectifyMap' I have looked at below

Remove Background from Image - Python

懵懂的女人 提交于 2021-01-29 09:39:15
问题 I am trying to remove the black background from an image using OpenCV, but I am unable to remove the pixels to capture just the main imagery without the black background. Here is the code I am using, along with the original input image. import numpy as np import cv2 from matplotlib import pyplot as plt img = cv2.imread('C:\\Users\\mdl518\\Desktop\\input.png') mask = np.zeros(img.shape[:2],np.uint8) bgdModel = np.zeros((1,65),np.float64) fgdModel = np.zeros((1,65),np.float64) rect = (0,0,1035