如何从python中opencv的数组读取原始PNG
1个回答
展开全部
1. 另一种方式,
也是在阅读一个实际的文件的情况下,这将适用于一个unicode路径(在Windows上进行测试)
with open(image_full_path, 'rb') as img_stream:
file_bytes = numpy.asarray(bytearray(img_stream.read()), dtype=numpy.uint8)
img_data_ndarray = cv2.imdecode(file_bytes, cv2.CV_LOAD_IMAGE_UNCHANGED)
img_data_cvmat = cv.fromarray(img_data_ndarray) # convert to old cvmat if needed
2.
(你的问题似乎被标记的Objective-C,但你问的Python,所以是你的榜样,所以我'的。)
我的优先篇文章对堆栈溢出!
简历。似乎是你在找什么。
的LoadImage(iscolor=CV_LOAD_IMAGE_COLOR)→无
Loads an image from a file as an IplImage.
Parameters:
filename (str) – Name of file to be loaded.
iscolor (int) –
Specific color type of the loaded image:
CV_LOAD_IMAGE_COLOR the loaded image is forced to be a 3-channel color image
CV_LOAD_IMAGE_GRAYSCALE the loaded image is forced to be grayscale
CV_LOAD_IMAGE_UNCHANGED the loaded image will be loaded as is.
该函数cvLoadImage加载图像从指定的文件和
返回的指针加载的图像。目前,下列文件
格式支持:
Windows bitmaps - BMP, DIB
JPEG files - JPEG, JPG, JPE
Portable Network Graphics - PNG
Portable image format - PBM, PGM, PPM
Sun rasters - SR, RAS
TIFF files - TIFF, TIF
注意 CodeGo.net,在当前的alpha通道,如果有的话,是
从输出图像除去,例如4通道的RGBA图像会
加载为RGB。
3.
我想通了:
# Read rawImage from a file, but in reality will have it from TCPServer
f = open('frame.png', "rb")
rawImage = f.read()
f.close()
# Convert rawImage to Mat
pilImage = Image.open(StringIO(rawImage));
npImage = np.array(pilImage)
matImage = cv.fromarray(npImage)
#show it
cv.NamedWindow('display')
cv.MoveWindow('display', 10, 10)
cv.ShowImage('display', matImage)
cv. WaitKey(0)
也是在阅读一个实际的文件的情况下,这将适用于一个unicode路径(在Windows上进行测试)
with open(image_full_path, 'rb') as img_stream:
file_bytes = numpy.asarray(bytearray(img_stream.read()), dtype=numpy.uint8)
img_data_ndarray = cv2.imdecode(file_bytes, cv2.CV_LOAD_IMAGE_UNCHANGED)
img_data_cvmat = cv.fromarray(img_data_ndarray) # convert to old cvmat if needed
2.
(你的问题似乎被标记的Objective-C,但你问的Python,所以是你的榜样,所以我'的。)
我的优先篇文章对堆栈溢出!
简历。似乎是你在找什么。
的LoadImage(iscolor=CV_LOAD_IMAGE_COLOR)→无
Loads an image from a file as an IplImage.
Parameters:
filename (str) – Name of file to be loaded.
iscolor (int) –
Specific color type of the loaded image:
CV_LOAD_IMAGE_COLOR the loaded image is forced to be a 3-channel color image
CV_LOAD_IMAGE_GRAYSCALE the loaded image is forced to be grayscale
CV_LOAD_IMAGE_UNCHANGED the loaded image will be loaded as is.
该函数cvLoadImage加载图像从指定的文件和
返回的指针加载的图像。目前,下列文件
格式支持:
Windows bitmaps - BMP, DIB
JPEG files - JPEG, JPG, JPE
Portable Network Graphics - PNG
Portable image format - PBM, PGM, PPM
Sun rasters - SR, RAS
TIFF files - TIFF, TIF
注意 CodeGo.net,在当前的alpha通道,如果有的话,是
从输出图像除去,例如4通道的RGBA图像会
加载为RGB。
3.
我想通了:
# Read rawImage from a file, but in reality will have it from TCPServer
f = open('frame.png', "rb")
rawImage = f.read()
f.close()
# Convert rawImage to Mat
pilImage = Image.open(StringIO(rawImage));
npImage = np.array(pilImage)
matImage = cv.fromarray(npImage)
#show it
cv.NamedWindow('display')
cv.MoveWindow('display', 10, 10)
cv.ShowImage('display', matImage)
cv. WaitKey(0)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询