cv2

Unresolved reference “cv2” inside cv2 (cv2.cv2)

浪尽此生 提交于 2019-12-24 10:48:12
问题 I've looked around and people seem to have similar problems but none described my case exactly, and solutions that worked for them didn't seem to work for me (or there was no answer to the question at all). Using pycharm, after having installed opencv-python and opencv-contrib-python I noticed that import cv2 works, but when I tried accessing cv2.imread() pycharm complained about not being able to find it. So I went to the cv2 init file, which looks like this: import importlib from .cv2

cv2.imshow crashing - libc++abi.dylib: terminating with uncaught exception of type NSException

人走茶凉 提交于 2019-12-24 10:37:22
问题 I am reading an image and then displaying the image using cv2.imshow however this crashes my script with the below stack trace. Code from flask_restful import Resource from flask import jsonify, request from .repository import DocumentRepository import cv2 class DocumentsResource(Resource): def __init__(self): self.document_repository = DocumentRepository() def post(self): img = cv2.imread('front.jpg') cv2.imshow('front.jpg', img) cv2.waitKey(0) Stack Trace 2018-10-23 11:35:09.828 python3

Simple method to extract specific color range from an image in Python?

南笙酒味 提交于 2019-12-24 07:04:19
问题 I'm trying to extract a specific color from an image within a defined RGB range using the cv2 module. In the example below I am trying to isolate the fire from the exhaust of the space shuttle between yellow and white RGB values and then print out the percentage of RGB values within that range compared to the rest of the image. Here is my minimal working example: import cv2 import numpy as np from matplotlib import pyplot as plt import imageio img = imageio.imread(r"shuttle.jpg") plt.imshow

Why the automatic change in pixel value in python?

两盒软妹~` 提交于 2019-12-24 05:52:04
问题 I am extracting frames from video with the help of VideoCapture. Extracted the first frame converted the frame into an image with the help of PIL. Printed the previous pixel value at position (1,1) Printed the pixel value at position(1,1) of the newly created image Can anyone explain why? Function to extract frames import cv2 from PIL import Image def FrameCapture(path): # Path to video file vidObj = cv2.VideoCapture(path) fourcc = cv2.VideoWriter_fourcc(*'mp4v') width = cv2.CAP_PROP_FRAME

Why the automatic change in pixel value in python?

被刻印的时光 ゝ 提交于 2019-12-24 05:51:32
问题 I am extracting frames from video with the help of VideoCapture. Extracted the first frame converted the frame into an image with the help of PIL. Printed the previous pixel value at position (1,1) Printed the pixel value at position(1,1) of the newly created image Can anyone explain why? Function to extract frames import cv2 from PIL import Image def FrameCapture(path): # Path to video file vidObj = cv2.VideoCapture(path) fourcc = cv2.VideoWriter_fourcc(*'mp4v') width = cv2.CAP_PROP_FRAME

converting 12 bit DICOM image to 8 bit jpeg

笑着哭i 提交于 2019-12-22 17:28:31
问题 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

My python code doesn't save video frames as images

浪子不回头ぞ 提交于 2019-12-22 09:40:02
问题 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

Robustly crop rotated bounding box on photos

时光总嘲笑我的痴心妄想 提交于 2019-12-21 05:40:44
问题 I'm trying to extract the rotated bounding box of contours robustly. I would like to take an image, find the largest contour, get its rotated bounding box, rotate the image to make the bounding box vertical, and crop to size. For a demonstration, here is an original image linked in the following code. I would like to end up with that shoe rotated to vertical and cropped to size. The following code from this answer seems to work on simple images like opencv lines, etc., but not on photos. Ends

Python OpenCV Error: Current thread is not the object's thread

狂风中的少年 提交于 2019-12-20 02:13:24
问题 I'm having an error running simple code using cv2 module. It's just: import cv2 img = cv2.imread('sudoku.png',0) cv2.imshow('image',img) And it fails with the following error: QObject::moveToThread: Current thread (0x1b74720) is not the object's thread (0x1e57d70). Cannot move to target thread (0x1b74720) I googled this error and tried a lot of things but it doesn't help. I tried installing without pip, I tried using step-by-step installation (from official OpenCV) but nothing helps. When I

ModuleNotFoundError: No module named 'cv2'

半世苍凉 提交于 2019-12-19 07:22:35
问题 I have been working on this error for a long time now. I have Python 3.6 and Python 2.7. I have tried to install opencv 2 and 3 in Python 2.7 and Python 3.6 respectively. I know the python interpreter I am using and I can interchange between them when I want. When I run Python interpreter and write import cv2 it does import it. When I run the code from command prompt it says ModuleNotFoundError: No module named 'cv2' . The module is installed. The cv2.pyd file is in C:\Python27\Lib\site