opencv-python

Convert RGB image to YUV and YCbCr color space image in Opencv Python

时光总嘲笑我的痴心妄想 提交于 2020-01-16 13:14:13
问题 Can anyone help me to convert an RGB colour space image to YUV colour space image and to YCbCr colour space image using opencv Python? 回答1: Use cv2.cvtColor(src, code) to convert Color-Space, the code starts with COLOR_ . You can use this to look for the color code. import cv2 ## get all color codes codes = [x for x in dir(cv2) if x.startswith("COLOR_")] ## print first three color codes print(codes[:3]) # ['COLOR_BAYER_BG2BGR', 'COLOR_BAYER_BG2BGRA', 'COLOR_BAYER_BG2BGR_EA'] ## print all

Convert RGB image to YUV and YCbCr color space image in Opencv Python

坚强是说给别人听的谎言 提交于 2020-01-16 13:13:31
问题 Can anyone help me to convert an RGB colour space image to YUV colour space image and to YCbCr colour space image using opencv Python? 回答1: Use cv2.cvtColor(src, code) to convert Color-Space, the code starts with COLOR_ . You can use this to look for the color code. import cv2 ## get all color codes codes = [x for x in dir(cv2) if x.startswith("COLOR_")] ## print first three color codes print(codes[:3]) # ['COLOR_BAYER_BG2BGR', 'COLOR_BAYER_BG2BGRA', 'COLOR_BAYER_BG2BGR_EA'] ## print all

OpenCV python: How do I draw a line using the gradient and the first point?

空扰寡人 提交于 2020-01-06 08:05:30
问题 I am trying to draw a line using a live feed with opencv. I am using one frame and storing the x,y coordinates. I use the next frame's x,y coordinate of the point to work out the gradient ((y2-y1)/(x2-x1)). I want to draw a straight line from the first coordinate straight through the second and continue past which would draw a trajectory. I can currently draw a straight line between the two points using cv2.line() . My code is below. Any suggestions would be wonderful! Thank you import numpy

how to install openCV_python with no import cv2 error?

懵懂的女人 提交于 2019-12-24 13:47:05
问题 I am trying to install the OpenCV-python on my mac and i have used the following: $pip install opencv-python which gave me the following error: $pip install opencv-python Collecting opencv-python Using cached opencv_python-3.4.0.12-cp27-cp27m macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl Collecting numpy>=1.11.1 (from opencv-python) Using cached numpy-1.14.2-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel

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

Split image horizontally with python based on dark center line

江枫思渺然 提交于 2019-12-24 05:49:46
问题 Goal is to horizontally split an image (double newspaper page) in python based on a vertical centerline that is darker than other areas around. Example image: Had some luck using opencv ( cv2 ) for the initial crop and rotation of the double page from a black background using cv2.Canny , and then sorting the contours based on cv2.contourArea . But, now I'm just interested in finding a center line and then splitting the image into two separate images. Using cv2.Canny again I see that it's able

Azure Functions: In a Python function under Linux, how do I import a non-standard module such as opencv/imutils?

我怕爱的太早我们不能终老 提交于 2019-12-23 05:04:43
问题 I am trying to export my computer vision API, which is functioning correctly under macOS, to an Azure Function. I tried to use the docker approach: func azure functionapp publish --build-native-deps but I keep getting the error: can't import cv2 and imutils log file and Exception: ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory Here is the requirements.txt: requirements.txt How do I solve this problem? Or must I switch to AWS Lambda? I have access

How to load and convert .mat file into numpy 2D array?

百般思念 提交于 2019-12-22 17:34:54
问题 I have a data in mat file (observations and features) and i want to load it into numpy 2D array. I dont want to convert it into csv first and then load csv into numpy. 回答1: Use scipy's loadmat (API-docs). The docs should be sufficient to get you going, but make sure to read the notes. There is also the io-tutorial with some examples. 来源: https://stackoverflow.com/questions/43952620/how-to-load-and-convert-mat-file-into-numpy-2d-array

How to use OpenCV ConnectedComponents to get the images

末鹿安然 提交于 2019-12-12 09:40:43
问题 How to use Python OpenCV ConnectedComponents function to obtain the images? From searching some past question, I have only been able to find how to shade the connected objects in different colors (Which I tested and it worked, but I have no idea how the labels work) Reference from these previously answered questions: Stackoverflow question 48303309 and Stackoverflow question 46441893 Using this code, I can get the shaded output import cv2 import numpy as np img = cv2.imread('eGaIy.jpg', 0)

ValueError: invalid literal for int() with base 10: 'f'

自闭症网瘾萝莉.ら 提交于 2019-12-11 16:26:27
问题 I have been trying to iterate through text files to create some text files with the same name in other directory, but with other values. Here is the code import numpy as np import cv2, os from glob import glob path_in = 'C:/Users/user/labels' path_out = 'C:/Users/user/labels_90' for filename in os.listdir(path_in): if filename.endswith('txt'): filename_edited = [] for line in filename: numericdata = line.split(' ') numbers = [] for i in numericdata: numbers.append(int(i)) c,x,y = numbers