opencv3.0

Removing black background and make transparent from grabcut output in python open cv

末鹿安然 提交于 2019-11-26 16:09:33
问题 I have been trying to remove the black background from the grabcut output using python opencv. import numpy as np import cv2 img = cv2.imread(r'myfile_1.png') mask = np.zeros(img.shape[:2],np.uint8) bgdModel = np.zeros((1,65),np.float64) fgdModel = np.zeros((1,65),np.float64) rect = (1,1,665,344) cv2.grabCut(img,mask,rect,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_RECT) mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8') img = img*mask2[:,:,np.newaxis] cv2.imshow('img',img) cv2.imwrite('img

OpenCV 3.0 LineIterator

安稳与你 提交于 2019-11-26 11:07:12
问题 I want to use the LineIterator in OpenCV 3.0 using Python, is it still available with OpenCV 3.0 built for Python? It seems that the answers on the internet are all pointing to cv.InitLineIterator which is part of the cv module. I\'ve tried importing this module but it seems like it is not included with the current build. Has it been renamed or strictly just removed? 回答1: I've solved my own problem. Line iterator seems to be unavailable in the cv2 library. Therefore, I made my own line

Convert a single color with cvtColor

和自甴很熟 提交于 2019-11-26 09:55:05
问题 I have a color that I want to convert to a different color space. Is it possible to use cvtColor on a cv::Vec3f directly without creating a 1x1 cv::Mat and populating it with that pixel, using cvtColor on the cv::Mat , then getting the only pixel out of the output? I have tried the following, but it doesn\'t seem to like getting passed a vector. Any suggestions? #include <iostream> #include <opencv2/opencv.hpp> int main(int, char*[]) { cv::Vec3f hsv; hsv[0] = .9; hsv[1] = .8; hsv[2] = .7; std

Efficiently load a large Mat into memory in OpenCV

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 04:33:49
Is there a more efficient way to load a large Mat object into memory than the FileStorage method in OpenCV? I have a large Mat with 192 columns and 1 million rows I want to store locally in a file and load into memory then my application starts. There is no problem using the FileStorage, but I was wondering if there exists a more efficient method to do this. At the moment it takes about 5 minutes to load the Mat into memory using the Debug mode in Visual Studio and around 3 minutes in the Release mode and the size of the data file is around 1.2GB. Is the FileStorage method the only method