我正试图在我用OpenCV的相机方法提取的图像上使用Zbar库的QR码检测方法.通常,QR码检测方法可以在我的计算机上使用图像(jpg,png等),但我猜测OpenCV的捕获帧是不同的.
有没有办法将捕获的帧变成PIL图像?
谢谢.
from PIL import Image
import zbar
import cv2.cv as cv
capture = cv.CaptureFromCAM(1)
imgSize = cv.GetSize(cv.QueryFrame(capture))
img = cv.QueryFrame(capture)
#SOMETHING GOES HERE TO TURN FRAME INTO IMAGE
img = img.convert('L')
width, height = img.size
scanner = zbar.ImageScanner()
scanner.parse_config('enable')
zbar_img = zbar.Image(width, height, 'Y800', img.tostring())
# scan the image for barcodes
scanner.scan(zbar_img)
for symbol in zbar_img:
print symbol.data
Run Code Online (Sandbox Code Playgroud) 我一直试图通过Python上的OpenCV获得单色blob跟踪.下面的代码工作正常,但它找到了所有跟踪像素的质心,而不仅仅是最大blob的质心.这是因为我正在拍摄所有像素的时刻,但我不确定如何进行色彩跟踪.我有点困惑于我需要做什么才能使这个单一的blob跟踪器而不是多blob平均值.
这是代码:
#! /usr/bin/env python
#if using newer versions of opencv, just "import cv"
import cv2.cv as cv
color_tracker_window = "Color Tracker"
class ColorTracker:
def __init__(self):
cv.NamedWindow( color_tracker_window, 1 )
self.capture = cv.CaptureFromCAM(0)
def run(self):
while True:
img = cv.QueryFrame( self.capture )
#blur the source image to reduce color noise
cv.Smooth(img, img, cv.CV_BLUR, 3);
#convert the image to hsv(Hue, Saturation, Value) so its
#easier to determine the color to track(hue)
hsv_img = cv.CreateImage(cv.GetSize(img), 8, 3)
cv.CvtColor(img, hsv_img, cv.CV_BGR2HSV)
#limit all …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用带有Python 2.7和Windows 64位的zbar库,但是没有很容易制作的.exe安装.
我自己也很擅长"制作".步骤是什么?
有没有一种方法可以移位我的位串,直到我将第一个1作为最低有效位为止?例如
0001000100 right shifts twice to 0000010001
0100001010 right shifts once to 0010000101
0010000000 right shifts seven times to 0000000001
Run Code Online (Sandbox Code Playgroud)
我试图通过按位操作来做到这一点。