Python cv2.cv.fromarray() Examples
The following are 4
code examples of cv2.cv.fromarray().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2.cv
, or try the search function
.
Example #1
Source File: qrxfer.py From qrxfer with MIT License | 5 votes |
def process_frames(self): while True: frame = cv.QueryFrame(self.capture) aframe = numpy.asarray(frame[:, :]) g = cv.fromarray(aframe) g = numpy.asarray(g) imgray = cv2.cvtColor(g, cv2.COLOR_BGR2GRAY) raw = str(imgray.data) scanner = zbar.ImageScanner() scanner.parse_config('enable') imagezbar = zbar.Image(frame.width, frame.height, 'Y800', raw) scanner.scan(imagezbar) # Process the frames for symbol in imagezbar: if not self.process_symbol(symbol): return # Update the preview window cv2.imshow(self.window_name, aframe) cv.WaitKey(5)
Example #2
Source File: color_replace.py From virtual-dressing-room with Apache License 2.0 | 5 votes |
def replace_color(self,col=None): print self.hue[0][0] self.hue_val=col #cv2.imshow("hue",self.hue) if col!=None: cv.Set(cv.fromarray(self.hue),(self.hue_val),cv.fromarray(self.mask)) self.scratch=cv2.merge([self.hue,self.sat,self.val]) self.scratch=cv2.cvtColor(self.scratch,cv2.cv.CV_HSV2BGR) print 'replaced' return self.scratch
Example #3
Source File: Input.py From DanceCV with BSD 3-Clause "New" or "Revised" License | 5 votes |
def getCurrentFrameAsImage(self): im = numpy.array(self.currentFrame) im = cv.fromarray(im) cv.CvtColor(im, im, cv.CV_BGR2RGB) pgImg = pygame.image.frombuffer(im.tostring(), cv.GetSize(im), "RGB") return pgImg
Example #4
Source File: Camera.py From SimpleCV2 with BSD 3-Clause "New" or "Revised" License | 4 votes |
def undistort(self, image_or_2darray): """ **SUMMARY** If given an image, apply the undistortion given by the camera's matrix and return the result. If given a 1xN 2D cvmat or a 2xN numpy array, it will un-distort points of measurement and return them in the original coordinate system. **PARAMETERS** * *image_or_2darray* - an image or an ndarray. **RETURNS** The undistorted image or the undistorted points. If the camera is un-calibrated we return None. **EXAMPLE** >>> img = cam.getImage() >>> result = cam.undistort(img) """ if(type(self._calibMat) != cv.cvmat or type(self._distCoeff) != cv.cvmat ): logger.warning("FrameSource.undistort: This operation requires calibration, please load the calibration matrix") return None if (type(image_or_2darray) == InstanceType and image_or_2darray.__class__ == Image): inImg = image_or_2darray # we have an image retVal = inImg.getEmpty() cv.Undistort2(inImg.getBitmap(), retVal, self._calibMat, self._distCoeff) return Image(retVal) else: mat = '' if (type(image_or_2darray) == cv.cvmat): mat = image_or_2darray else: arr = cv.fromarray(np.array(image_or_2darray)) mat = cv.CreateMat(cv.GetSize(arr)[1], 1, cv.CV_64FC2) cv.Merge(arr[:, 0], arr[:, 1], None, None, mat) upoints = cv.CreateMat(cv.GetSize(mat)[1], 1, cv.CV_64FC2) cv.UndistortPoints(mat, upoints, self._calibMat, self._distCoeff) #undistorted.x = (x* focalX + principalX); #undistorted.y = (y* focalY + principalY); return (np.array(upoints[:, 0]) *\ [self.getCameraMatrix()[0, 0], self.getCameraMatrix()[1, 1]] +\ [self.getCameraMatrix()[0, 2], self.getCameraMatrix()[1, 2]])[:, 0]