cv2

Wrong colours with cv2.imdecode (python opencv)

雨燕双飞 提交于 2019-12-08 03:51:28
问题 I try to display the image located here: http://skyservice.pha.jhu.edu/DR12/ImgCutout/getjpeg.aspx?ra=118.70299999999999&dec=45.721000000000004&width=10&height=10&scale=0.6 The image looks like this: I use this code: import matplotlib.pyplot as plt import numpy as np import urllib import cv2 url = 'http://skyservice.pha.jhu.edu/DR12/ImgCutout/getjpeg.aspx?ra=118.70299999999999&dec=45.721000000000004&width=10&height=10&scale=0.6' def url_to_image(url): resp = urllib.request.urlopen(url) image

Python Open CV2 Color Detection Mask to Pixel Coordinates

柔情痞子 提交于 2019-12-06 13:33:38
I am currently working in Python to do color detection on a single image. After loading my image and establishing my RGB (or BGR in CV2), I use the following 2 lines to produce a mask and a output image. mask = cv2.inRange(image, lower, upper) output = cv2.bitwise_and(image, image, mask = mask) Then the code displays the following image. But now, I would like to take the processed image and extract pixel coordinate points for the green line. Thanks. Any help would be appreciated. Soltius So, how about findNonZeros() on a binarised version of your image ? Starting with the image with the green

converting 12 bit DICOM image to 8 bit jpeg

无人久伴 提交于 2019-12-06 09:29:32
I am trying to load DICOM files into python using the dicom library. I have done the following ds=dicom.read_file(r"C:\Users\Z003SPFR.AD005\ML\GLCM AND SVM\data\NECT\1.IMA") # # store the raw image data DicomImage = ds.pixel_array This gives me values that appear to be 12 bit, since the highest value obtained was around 3047 and lowest value was 0. Then i made my own mapping function to bring it to the range 0-255. I used the following code: leftMin = 0 leftMax = np.amax(DicomImage) rightMin = 0 rightMax = 255 def translate(value, leftMin, leftMax, rightMin, rightMax): # Figure out how 'wide'

Python 2.7/OpenCV 3.3: Error in cv2.initUndistortRectifyMap . Not showing undistort rectified images

孤街醉人 提交于 2019-12-06 07:42:59
I want to distort and rectified my stereo images. For which I used Opencv 3.3 in Python 2.7. Code I used is : import cv2 import numpy as np cameraMatrixL = np.load('mtx_left.npy') distCoeffsL = np.load('dist_left.npy') cameraMatrixR = np.load('mtx_right.npy') distCoeffsR = np.load('dist_right.npy') R = np.load('R.npy') T = np.load('T.npy') imgleft = cv2.imread('D:\python\camera calibration and 3d const\left\left60.png',0) imgright = cv2.imread('D:\python\camera calibration and 3d const\Right/right60.png',0) R1,R2,P1,P2,Q,validPixROI1, validPixROI2 = cv2.stereoRectify(cameraMatrixL,distCoeffsL

Wrong colours with cv2.imdecode (python opencv)

China☆狼群 提交于 2019-12-06 04:13:11
I try to display the image located here: http://skyservice.pha.jhu.edu/DR12/ImgCutout/getjpeg.aspx?ra=118.70299999999999&dec=45.721000000000004&width=10&height=10&scale=0.6 The image looks like this: I use this code: import matplotlib.pyplot as plt import numpy as np import urllib import cv2 url = 'http://skyservice.pha.jhu.edu/DR12/ImgCutout/getjpeg.aspx?ra=118.70299999999999&dec=45.721000000000004&width=10&height=10&scale=0.6' def url_to_image(url): resp = urllib.request.urlopen(url) image = np.asarray(bytearray(resp.read()), dtype="uint8") image = cv2.imdecode(image, cv2.IMREAD_COLOR)

My python code doesn't save video frames as images

徘徊边缘 提交于 2019-12-06 04:05:19
I'm trying to grab specific frames (e.g. frame 0, 10, 20, ...) within a video and save them as images using Python and CV2. For some reasons, my code only saves the first frame. All other frames are created, but with size 0 (they are corrupt). How can I fix the problem? import cv2 from numpy import integer number = 10; filename = "18s.mp4"; def uniform(): cap = cv2.VideoCapture(filename); frame_count= int(cap.get(cv2.CAP_PROP_FRAME_COUNT)); print(frame_count) for x in range(0, number): frame_no = 1*(x/number) frame_no_int=int(frame_no*frame_count) cap.set(2,frame_no); ret, frame = cap.read()

OpenCv, Python3: No icons in the toolbar

僤鯓⒐⒋嵵緔 提交于 2019-12-05 21:34:37
I am using Python 3.5 on Linux along with OpenCV 3.4.0 (installed by pip install opencv-python ) to display the images from my webcam and I want to use the toolbar at the top of my frame. But the icons of this toolbar aren't shown. (I could use the Buttons without the icons, but where are the Icons) Is there any way to get the usual icons or write Text instead of icons on these buttons. Here is my code: import cv2 cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml") def show_webcam(): cam = cv2.VideoCapture(0) cv2.namedWindow("webcam", cv2.WINDOW_NORMAL|cv2

Unable to import cv2 module (Python 3.6)

a 夏天 提交于 2019-12-05 12:03:58
total nexwbie here. I'm unsuccessfully trying to install the cv2 module for python but it doesn't work. I'm working with Python 3.6 (64bits) I typed the following commands in the cmd : C:\Users\leahj>C:\Users\leahj\AppData\Local\Programs\Python\Python36\Scripts\pip3 install cv2 Collecting cv2 Could not find a version that satisfies the requirement cv2 (from versions: ) No matching distribution found for cv2 C:\Users\leahj>C:\Users\leahj\AppData\Local\Programs\Python\Python36\Scripts\pip3 install opencv Collecting opencv Could not find a version that satisfies the requirement opencv (from

How to find the coordinates of the outside corners of these 4 squares? (morphological closing/opening does not conserve squares if image is rotated)

大兔子大兔子 提交于 2019-12-04 17:32:23
One of the first processing steps in a tool I'm coding is to find the coordinates of the outside corners of 4 big black squares . They will then be used to do a homographic transform, in order to deskew / unrotate the image (a.k.a perspective transform), to finally get a rectangular image. Here is an example of - rotated and noisy - input ( download link here ): To keep the big squares only, I'm using morphological transformations like closing/opening: import cv2, numpy as np img = cv2.imread('rotatednoisy-cropped.png', cv2.IMREAD_GRAYSCALE) kernel = np.ones((30, 30), np.uint8) img = cv2

How to crop the biggest object in image with python opencv?

夙愿已清 提交于 2019-12-04 14:59:26
I want to crop the biggest object in the image (Characters). This code only works if there is no line (shown in the first image). But I need to ignore the line and make the image of the second image. Only crop the biggest object image. import cv2 x1, y1, w1, h1 = (0,0,0,0) points = 0 # load image img = cv2.imread('Image.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # convert to grayscale # threshold to get just the signature retval, thresh_gray = cv2.threshold(gray, thresh=100, maxval=255, type=cv2.THRESH_BINARY) # find where the signature is and make a cropped region points = np.argwhere