def Ipl2NumPy(img): """ Converts an openCV cvArray to a pygame surface. Parameters: IplImage img - image""" array = adaptors.Ipl2NumPy(img) surf = pygame.surfarray.make_surface(array) surf = pygame.transform.rotate(surf, -90) surf = pygame.transform.flip(surf, 1, 0) return surf
def __call__(self, image): # Convert CvMat to ndarray np_image = adaptors.Ipl2NumPy(image) # Call the original function np_image_filtered = self.f(np_image) # Convert back to CvMat return adaptors.NumPy2Ipl(np_image_filtered)
def static_test(): """Takes a full colour numpy image""" from opencv import highgui image = highgui.cvLoadImage( "/usr/share/doc/opencv-doc/examples/c/lena.jpg") result = adaptors.Ipl2NumPy(process_image(image)) imshow(result) savefig("harris_scipy_static.png", transparent=True) show()
def process_image(image): """Carry out harris detection on a cvMat image with scipy""" np_image = adaptors.Ipl2NumPy(image) im = np_image.astype(uint8).mean(2) harrisim = compute_harris_response(im) # 150ms #filtered_coords = get_harris_points(harrisim, 6) # 106ms #render_harris_points(np_image, filtered_coords) # 8ms #IPShellEmbed()() return filter_and_render_numpy(np_image, harrisim)
def cv2SurfArray(cvMat): """Given an open cvMat convert it to a pygame surface pixelArray Should be able to call blit_array directly on this. """ numpyImage = adaptors.Ipl2NumPy(cvMat) return numpyImage.transpose(1,0,2)