Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

84 rader
1.8 KiB

  1. /*
  2. * libpipi Proper image processing implementation library
  3. * Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * image.c: image I/O functions
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <cv.h>
  23. #include <highgui.h>
  24. #include "pipi.h"
  25. #include "pipi_internals.h"
  26. pipi_image_t *pipi_load_opencv(const char *name)
  27. {
  28. pipi_image_t *img;
  29. IplImage *priv = cvLoadImage(name, -1);
  30. if(!priv)
  31. return NULL;
  32. img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
  33. img->width = priv->width;
  34. img->height = priv->height;
  35. img->pitch = priv->widthStep;
  36. img->channels = priv->nChannels;
  37. img->pixels = priv->imageData;
  38. img->priv = (void *)priv;
  39. return img;
  40. }
  41. pipi_image_t *pipi_new_opencv(int width, int height)
  42. {
  43. pipi_image_t *img;
  44. IplImage *priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
  45. if(!priv)
  46. return NULL;
  47. img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
  48. img->width = priv->width;
  49. img->height = priv->height;
  50. img->pitch = priv->widthStep;
  51. img->channels = priv->nChannels;
  52. img->pixels = priv->imageData;
  53. img->priv = (void *)priv;
  54. return img;
  55. }
  56. void pipi_free_opencv(pipi_image_t *img)
  57. {
  58. IplImage *iplimg;
  59. iplimg = (IplImage *)img->priv;
  60. cvReleaseImage(&iplimg);
  61. free(img);
  62. }
  63. void pipi_save_opencv(pipi_image_t *img, const char *name)
  64. {
  65. cvSaveImage(name, img->priv);
  66. }