From 9ccaf6ebab9d445e5b8ed04f58956cacb7ac7467 Mon Sep 17 00:00:00 2001 From: "N.N." Date: Sat, 29 Aug 2009 19:03:18 +0000 Subject: rename histo to hist_compare svn path=/trunk/externals/pix_opencv/; revision=12136 --- Makefile | 2 +- pix_opencv_hist_compare-help.pd | 116 +++++++++ pix_opencv_hist_compare.cc | 533 ++++++++++++++++++++++++++++++++++++++++ pix_opencv_hist_compare.h | 89 +++++++ pix_opencv_histo-help.pd | 100 -------- pix_opencv_histo.cc | 514 -------------------------------------- pix_opencv_histo.h | 88 ------- 7 files changed, 739 insertions(+), 703 deletions(-) create mode 100755 pix_opencv_hist_compare-help.pd create mode 100755 pix_opencv_hist_compare.cc create mode 100755 pix_opencv_hist_compare.h delete mode 100755 pix_opencv_histo-help.pd delete mode 100755 pix_opencv_histo.cc delete mode 100755 pix_opencv_histo.h diff --git a/Makefile b/Makefile index 8fc259e..1deb95f 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ endif .SUFFIXES = $(EXTENSION) -SOURCES = pix_opencv_edge.cc pix_opencv_laplace.cc pix_opencv_morphology.cc pix_opencv_distrans.cc pix_opencv_motempl.cc pix_opencv_haarcascade.cc pix_opencv_contours_boundingrect.cc pix_opencv_bgsubstract.cc pix_opencv_contours_convexity.cc pix_opencv_dft.cc pix_opencv_lk.cc pix_opencv_histo.cc pix_opencv_knear.cc pix_opencv_threshold.cc +SOURCES = pix_opencv_edge.cc pix_opencv_laplace.cc pix_opencv_morphology.cc pix_opencv_distrans.cc pix_opencv_motempl.cc pix_opencv_haarcascade.cc pix_opencv_contours_boundingrect.cc pix_opencv_bgsubstract.cc pix_opencv_contours_convexity.cc pix_opencv_dft.cc pix_opencv_lk.cc pix_opencv_hist_compare.cc pix_opencv_knear.cc pix_opencv_threshold.cc all: $(SOURCES:.cc=.$(EXTENSION)) diff --git a/pix_opencv_hist_compare-help.pd b/pix_opencv_hist_compare-help.pd new file mode 100755 index 0000000..17268b7 --- /dev/null +++ b/pix_opencv_hist_compare-help.pd @@ -0,0 +1,116 @@ +#N canvas 41 167 1154 642 10; +#X obj 396 -37 gemhead; +#X obj 364 478 pix_texture; +#X obj 364 506 square 2; +#X obj 9 -28 cnv 15 220 70 empty empty empty 20 12 0 14 -195568 -66577 +0; +#N canvas 0 22 454 304 gemwin 0; +#X obj 132 136 gemwin; +#X obj 67 89 outlet; +#X obj 67 10 inlet; +#X obj 67 41 route create; +#X msg 67 70 set destroy; +#X msg 182 68 set create; +#X msg 132 112 create \, 1; +#X msg 238 112 destroy; +#N canvas 87 154 247 179 Gem.init 0; +#X obj 118 46 loadbang; +#X msg 118 81 reset; +#X obj 118 113 outlet; +#X connect 0 0 1 0; +#X connect 1 0 2 0; +#X restore 289 80 pd Gem.init; +#X connect 2 0 3 0; +#X connect 3 0 4 0; +#X connect 3 0 6 0; +#X connect 3 1 5 0; +#X connect 3 1 7 0; +#X connect 4 0 1 0; +#X connect 5 0 1 0; +#X connect 6 0 0 0; +#X connect 7 0 0 0; +#X connect 8 0 0 0; +#X restore 14 16 pd gemwin; +#X msg 14 -8 destroy; +#X text 15 -26 Create window and render; +#X obj 216 478 pix_texture; +#X obj 216 506 square 2; +#X obj 367 159 translateXYZ -2 0 0; +#X obj 367 224 separator; +#X obj 350 285 cnv 15 500 180 empty empty empty 20 12 0 14 -24198 -66577 +0; +#X obj 511 -66 bng 25 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 524 128 unpack 0 0 0; +#X floatatom 514 151 5 0 0 3 length - -; +#X floatatom 563 151 5 0 0 3 width - -; +#X floatatom 613 151 5 0 0 3 height - -; +#X obj 568 109 bng 15 250 50 0 empty empty end_reached 20 7 0 10 -262144 +-1 -1; +#X floatatom 550 74 5 0 10000 1 frame# - -; +#X obj 511 -37 openpanel; +#X msg 511 -17 open \$1; +#X obj 499 92 pix_film; +#X msg 517 26 auto \$1; +#X obj 517 8 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 +; +#X obj 364 259 translateXYZ 4 0 0; +#X obj 580 26 loadbang; +#X msg 528 50 colorspace RGBA; +#X obj 439 290 hradio 15 1 0 5 empty empty empty 0 -8 0 10 -262144 +-1 -1 0; +#X text 522 289 save an histogram at position nth ( 0 <= n <= 80 ) +; +#X text 5 -87 record histograms of specific situations; +#X text 7 -75 the object will recognize the situations if they occur +again; +#X text 7 -61 Written by Lluis Gomez i Bigorda ( lluisgomez@hangar.org +); +#X floatatom 443 421 5 0 0 0 - - -; +#X obj 505 346 unpack f f f f f; +#X text 598 381 nearest to 1 is the winner; +#X text 479 422 closest histogram (winner); +#X obj 505 374 vsl 15 37 0 1 0 0 empty empty empty 0 -9 0 10 -262144 +-1 -1 0 1; +#X obj 528 374 vsl 15 37 0 1 0 0 empty empty empty 0 -9 0 10 -262144 +-1 -1 0 1; +#X obj 551 374 vsl 15 37 0 1 0 0 empty empty empty 0 -9 0 10 -262144 +-1 -1 0 1; +#X obj 574 374 vsl 15 37 0 1 0 0 empty empty empty 0 -9 0 10 -262144 +-1 -1 0 1; +#X text 597 370 matching measure with stored histograms; +#X obj 364 315 pix_opencv_hist_compare; +#X text 7 -100 pix_opencv_hist_compare : image recognition using histograms +; +#X connect 0 0 21 0; +#X connect 1 0 2 0; +#X connect 4 0 5 0; +#X connect 5 0 4 0; +#X connect 7 0 8 0; +#X connect 9 0 7 0; +#X connect 9 0 10 0; +#X connect 10 0 24 0; +#X connect 12 0 19 0; +#X connect 13 0 14 0; +#X connect 13 1 15 0; +#X connect 13 2 16 0; +#X connect 17 0 18 0; +#X connect 18 0 21 1; +#X connect 19 0 20 0; +#X connect 20 0 21 0; +#X connect 21 0 9 0; +#X connect 21 1 13 0; +#X connect 21 2 17 0; +#X connect 22 0 21 0; +#X connect 23 0 22 0; +#X connect 24 0 41 0; +#X connect 25 0 26 0; +#X connect 26 0 21 0; +#X connect 27 0 41 1; +#X connect 33 0 36 0; +#X connect 33 1 37 0; +#X connect 33 2 38 0; +#X connect 33 3 39 0; +#X connect 41 0 1 0; +#X connect 41 1 32 0; +#X connect 41 2 33 0; diff --git a/pix_opencv_hist_compare.cc b/pix_opencv_hist_compare.cc new file mode 100755 index 0000000..865b090 --- /dev/null +++ b/pix_opencv_hist_compare.cc @@ -0,0 +1,533 @@ +//////////////////////////////////////////////////////// +// +// GEM - Graphics Environment for Multimedia +// +// zmoelnig@iem.kug.ac.at +// +// Implementation file +// +// Copyright (c) 1997-2000 Mark Danks. +// Copyright (c) Günther Geiger. +// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM +// Copyright (c) 2002 James Tittle & Chris Clepper +// For information on usage and redistribution, and for a DISCLAIMER OF ALL +// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. +// +///////////////////////////////////////////////////////// + +#include "pix_opencv_hist_compare.h" + +CPPEXTERN_NEW(pix_opencv_hist_compare) + +///////////////////////////////////////////////////////// +// +// pix_opencv_hist_compare +// +///////////////////////////////////////////////////////// +// Constructor +// +///////////////////////////////////////////////////////// + +pix_opencv_hist_compare :: pix_opencv_hist_compare() +{ + int i; + + comp_xsize=320; + comp_ysize=240; + + inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("save")); + m_dataout = outlet_new(this->x_obj, &s_anything); + m_measureout = outlet_new(this->x_obj, &s_anything); + + save_now = 0; + + rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4); + rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3); + grey = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3 ); + + h_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + s_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + v_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + planes[0] = h_plane; + planes[1] = s_plane; + h_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + s_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + v_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + saved_planes[0] = h_saved_plane; + saved_planes[1] = s_saved_plane; + + int h_bins = (int)(comp_xsize/10), s_bins = (int)(comp_ysize/10); + { + int hist_size[] = { h_bins, s_bins }; + float h_ranges[] = { 0, 180 }; // hue is [0,180] + float s_ranges[] = { 0, 255 }; + float* ranges[] = { h_ranges, s_ranges }; + hist = cvCreateHist( + 2, + hist_size, + CV_HIST_ARRAY, + ranges, + 1 + ); + int n; + for (n=0; ncomp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize)) { + + this->comp_xsize=image.xsize; + this->comp_ysize=image.ysize; + + post( "pix_opencv_hist_compare : reallocating buffers" ); + + //Destroy cv_images to clean memory + cvReleaseImage(&rgba); + cvReleaseImage(&rgb); + cvReleaseImage(&grey); + cvReleaseImage(&h_plane); + cvReleaseImage(&s_plane); + cvReleaseImage(&v_plane); + cvReleaseImage(&h_saved_plane); + cvReleaseImage(&s_saved_plane); + cvReleaseImage(&v_saved_plane); + + //Create cv_images + rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4); + rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3); + grey = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3 ); + + h_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + s_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + v_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + planes[0] = h_plane; + planes[1] = s_plane; + cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); + h_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + s_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + v_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + saved_planes[0] = h_saved_plane; + saved_planes[1] = s_saved_plane; + + h_bins = (int)(comp_xsize/10); + s_bins = (int)(comp_ysize/10); + { + int hist_size[] = { h_bins, s_bins }; + float h_ranges[] = { 0, 180 }; // hue is [0,180] + float s_ranges[] = { 0, 255 }; + float* ranges[] = { h_ranges, s_ranges }; + hist = cvCreateHist( + 2, + hist_size, + CV_HIST_ARRAY, + ranges, + 1 + ); + int n; + for (n=0; nimageData, image.data, image.xsize*image.ysize*4 ); + + // Convert to hsv + cvCvtColor( rgba, rgb, CV_BGRA2BGR ); + cvCvtColor( rgb, hsv, CV_BGR2HSV ); + cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); + + // Build the histogram and compute its contents. + if (save_now>=0) { + post("saving histogram %d\n",save_now); + cvCvtPixToPlane( hsv, h_saved_plane, s_saved_plane, v_saved_plane, 0 ); + cvCalcHist( saved_planes, saved_hist[save_now], 0, 0 ); //Compute histogram + cvNormalizeHist( saved_hist[save_now], 1.0 ); //Normalize it + save_now=-1; + nbsaved++; + } + cvCalcHist( planes, hist, 0, 0 ); //Compute histogram + cvNormalizeHist( hist, 1.0 ); //Normalize it + + double tato[MAX_HISTOGRAMS_TO_COMPARE]; + t_atom datalist[MAX_HISTOGRAMS_TO_COMPARE]; + int nearest = -1; + double max = 0; + + int n; + if ( nbsaved > 0 ) + for (n=0; nmax) { + max = tato[n]; + nearest = n; + } + } + + if ( nbsaved > 0 ) { + outlet_float(m_dataout, (float)nearest); + outlet_list( m_measureout, 0, MAX_HISTOGRAMS_TO_COMPARE , datalist ); + } else + outlet_float(m_dataout, -1.0); + + // Create an image to use to visualize our histogram. + int scale = 10; + // populate our visualization with little gray squares. + float max_value = 0; + cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 ); + + int h = 0; + int s = 0; + + for( h = 0; h < h_bins; h++ ) { + for( s = 0; s < s_bins; s++ ) { + float bin_val = cvQueryHistValue_2D( hist, h, s ); + int intensity = cvRound( bin_val * 255 / max_value ); + cvRectangle( + rgba, + cvPoint( h*scale, s*scale ), + cvPoint( (h+1)*scale - 1, (s+1)*scale - 1), + CV_RGB(intensity,intensity,intensity), CV_FILLED, 8 , 0 ); + } + } + + memcpy( image.data, rgba->imageData, image.xsize*image.ysize*4 ); + +} + +void pix_opencv_hist_compare :: processRGBImage(imageStruct &image) +{ + int i; + int h_bins = (int)(comp_xsize/10), s_bins = (int)(comp_ysize/10); + + if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize)) { + + this->comp_xsize=image.xsize; + this->comp_ysize=image.ysize; + + //Destroy cv_images to clean memory + cvReleaseImage(&rgba); + cvReleaseImage(&rgb); + cvReleaseImage(&grey); + cvReleaseImage(&h_plane); + cvReleaseImage(&s_plane); + cvReleaseImage(&v_plane); + cvReleaseImage(&h_saved_plane); + cvReleaseImage(&s_saved_plane); + cvReleaseImage(&v_saved_plane); + + //Create cv_images + rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4); + rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3); + grey = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3 ); + + h_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + s_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + v_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + planes[0] = h_plane; + planes[1] = s_plane; + cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); + h_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + s_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + v_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + saved_planes[0] = h_saved_plane; + saved_planes[1] = s_saved_plane; + + h_bins = (int)(comp_xsize/10); + s_bins = (int)(comp_ysize/10); + { + int hist_size[] = { h_bins, s_bins }; + float h_ranges[] = { 0, 180 }; // hue is [0,180] + float s_ranges[] = { 0, 255 }; + float* ranges[] = { h_ranges, s_ranges }; + hist = cvCreateHist( + 2, + hist_size, + CV_HIST_ARRAY, + ranges, + 1 + ); + int n; + for (n=0; nimageData, image.data, image.xsize*image.ysize*3 ); + + // Convert to hsv + cvCvtColor( rgb, hsv, CV_BGR2HSV ); + cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); + + // Build the histogram and compute its contents. + if (save_now>=0) { + post("saving histogram %d\n",save_now); + cvCvtPixToPlane( hsv, h_saved_plane, s_saved_plane, v_saved_plane, 0 ); + cvCalcHist( saved_planes, saved_hist[save_now], 0, 0 ); //Compute histogram + cvNormalizeHist( saved_hist[save_now], 1.0 ); //Normalize it + save_now=-1; + nbsaved++; + } + cvCalcHist( planes, hist, 0, 0 ); //Compute histogram + cvNormalizeHist( hist, 1.0 ); //Normalize it + + double tato[MAX_HISTOGRAMS_TO_COMPARE]; + t_atom datalist[MAX_HISTOGRAMS_TO_COMPARE]; + int nearest = -1; + double max = 0; + + int n; + if ( nbsaved > 0 ) + for (n=0; nmax) { + max = tato[n]; + nearest = n; + } + } + + if ( nbsaved > 0 ) { + outlet_float(m_dataout, (float)nearest); + outlet_list( m_measureout, 0, MAX_HISTOGRAMS_TO_COMPARE , datalist ); + } else + outlet_float(m_dataout, -1.0); + + // Create an image to use to visualize our histogram. + int scale = 10; + // populate our visualization with little gray squares. + float max_value = 0; + cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 ); + + int h = 0; + int s = 0; + + for( h = 0; h < h_bins; h++ ) { + for( s = 0; s < s_bins; s++ ) { + float bin_val = cvQueryHistValue_2D( hist, h, s ); + int intensity = cvRound( bin_val * 255 / max_value ); + cvRectangle( + rgb, + cvPoint( h*scale, s*scale ), + cvPoint( (h+1)*scale - 1, (s+1)*scale - 1), + CV_RGB(intensity,intensity,intensity), CV_FILLED, 8 , 0 ); + } + } + + memcpy( image.data, rgb->imageData, image.xsize*image.ysize*3 ); + +} + +void pix_opencv_hist_compare :: processYUVImage(imageStruct &image) +{ + post( "pix_opencv_hist_compare : yuv format not supported" ); +} + +void pix_opencv_hist_compare :: processGrayImage(imageStruct &image) +{ + int i; + int h_bins = (int)(comp_xsize/10), s_bins = (int)(comp_ysize/10); + + if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize)) { + + this->comp_xsize=image.xsize; + this->comp_ysize=image.ysize; + + //Destroy cv_images to clean memory + cvReleaseImage(&rgba); + cvReleaseImage(&rgb); + cvReleaseImage(&grey); + cvReleaseImage(&h_plane); + cvReleaseImage(&s_plane); + cvReleaseImage(&v_plane); + cvReleaseImage(&h_saved_plane); + cvReleaseImage(&s_saved_plane); + cvReleaseImage(&v_saved_plane); + + //Create cv_images + rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4); + rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3); + grey = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3 ); + + h_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + s_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + v_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + planes[0] = h_plane; + planes[1] = s_plane; + cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); + h_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + s_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + v_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); + saved_planes[0] = h_saved_plane; + saved_planes[1] = s_saved_plane; + + h_bins = (int)(comp_xsize/10); + s_bins = (int)(comp_ysize/10); + { + int hist_size[] = { h_bins, s_bins }; + float h_ranges[] = { 0, 180 }; // hue is [0,180] + float s_ranges[] = { 0, 255 }; + float* ranges[] = { h_ranges, s_ranges }; + hist = cvCreateHist( + 2, + hist_size, + CV_HIST_ARRAY, + ranges, + 1 + ); + int n; + for (n=0; nimageData, image.data, image.xsize*image.ysize ); + + // Convert to hsv + cvCvtColor( grey, rgb, CV_GRAY2BGR ); + cvCvtColor( rgb, hsv, CV_BGR2HSV ); + cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); + + // Build the histogram and compute its contents. + if (save_now>=0) { + post("saving histogram %d\n",save_now); + cvCvtPixToPlane( hsv, h_saved_plane, s_saved_plane, v_saved_plane, 0 ); + cvCalcHist( saved_planes, saved_hist[save_now], 0, 0 ); //Compute histogram + cvNormalizeHist( saved_hist[save_now], 1.0 ); //Normalize it + save_now=-1; + nbsaved++; + } + cvCalcHist( planes, hist, 0, 0 ); //Compute histogram + cvNormalizeHist( hist, 1.0 ); //Normalize it + + double tato[MAX_HISTOGRAMS_TO_COMPARE]; + t_atom datalist[MAX_HISTOGRAMS_TO_COMPARE]; + int nearest = -1; + double max = 0; + + int n; + if ( nbsaved > 0 ) + for (n=0; nmax) { + max = tato[n]; + nearest = n; + } + } + + if ( nbsaved > 0 ) { + outlet_float(m_dataout, (float)nearest); + outlet_list( m_measureout, 0, MAX_HISTOGRAMS_TO_COMPARE , datalist ); + } else + outlet_float(m_dataout, -1.0); + + // Create an image to use to visualize our histogram. + int scale = 10; + // populate our visualization with little gray squares. + float max_value = 0; + cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 ); + + int h = 0; + int s = 0; + + for( h = 0; h < h_bins; h++ ) { + for( s = 0; s < s_bins; s++ ) { + float bin_val = cvQueryHistValue_2D( hist, h, s ); + int intensity = cvRound( bin_val * 255 / max_value ); + cvRectangle( + grey, + cvPoint( h*scale, s*scale ), + cvPoint( (h+1)*scale - 1, (s+1)*scale - 1), + CV_RGB(intensity,intensity,intensity), CV_FILLED, 8 , 0 ); + } + } + + memcpy( image.data, grey->imageData, image.xsize*image.ysize ); + +} + +///////////////////////////////////////////////////////// +// static member function +// +///////////////////////////////////////////////////////// + +void pix_opencv_hist_compare :: obj_setupCallback(t_class *classPtr) +{ + class_addmethod(classPtr, (t_method)&pix_opencv_hist_compare::saveMessCallback, + gensym("save"), A_FLOAT, A_NULL); +} + +void pix_opencv_hist_compare :: saveMess(float index) +{ + if (((int)index>=0)&&((int)indexsaveMess(index); +} diff --git a/pix_opencv_hist_compare.h b/pix_opencv_hist_compare.h new file mode 100755 index 0000000..7e07f0b --- /dev/null +++ b/pix_opencv_hist_compare.h @@ -0,0 +1,89 @@ +/*----------------------------------------------------------------- +LOG + GEM - Graphics Environment for Multimedia + + Change pix to greyscale + + Copyright (c) 1997-1999 Mark Danks. mark@danks.org + Copyright (c) Günther Geiger. geiger@epy.co.at + Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM. zmoelnig@iem.kug.ac.at + Copyright (c) 2002 James Tittle & Chris Clepper + For information on usage and redistribution, and for a DISCLAIMER OF ALL + WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. + +-----------------------------------------------------------------*/ + +#ifndef INCLUDE_PIX_OPENCV_HISTO_H_ +#define INCLUDE_PIX_OPENCV_HISTO_H_ + +#include "Base/GemPixObj.h" + +#ifndef _EiC +#include "cv.h" +#endif + +#define MAX_HISTOGRAMS_TO_COMPARE 80 + +/*----------------------------------------------------------------- +------------------------------------------------------------------- +CLASS + pix_opencv_hist_compare + + Histogram reognition object using Open CV + +KEYWORDS + pix + +DESCRIPTION + +-----------------------------------------------------------------*/ + +class GEM_EXTERN pix_opencv_hist_compare : public GemPixObj +{ + CPPEXTERN_HEADER(pix_opencv_hist_compare, GemPixObj) + + public: + + ////////// + // Constructor + pix_opencv_hist_compare(); + + protected: + + ////////// + // Destructor + virtual ~pix_opencv_hist_compare(); + + ////////// + // Do the processing + virtual void processRGBAImage(imageStruct &image); + virtual void processRGBImage(imageStruct &image); + virtual void processYUVImage(imageStruct &image); + virtual void processGrayImage(imageStruct &image); + + void saveMess(float index); + + int comp_xsize; + int comp_ysize; + + t_outlet *m_dataout; + t_outlet *m_measureout; + + private: + + ////////// + // Static member functions + static void saveMessCallback(void *data, t_floatarg index); + + // The output and temporary images + int save_now; + int nbsaved; + + CvHistogram *hist; + CvHistogram *saved_hist[MAX_HISTOGRAMS_TO_COMPARE]; + IplImage *rgba, *rgb, *grey, *hsv, *h_plane, *s_plane, *v_plane, *h_saved_plane, *s_saved_plane, *v_saved_plane, *planes[2],*saved_planes[2]; + + +}; + +#endif // for header file diff --git a/pix_opencv_histo-help.pd b/pix_opencv_histo-help.pd deleted file mode 100755 index 5dd00c9..0000000 --- a/pix_opencv_histo-help.pd +++ /dev/null @@ -1,100 +0,0 @@ -#N canvas 36 143 1154 642 10; -#X obj 396 -37 gemhead; -#X obj 364 372 pix_texture; -#X obj 364 400 square 2; -#X obj 9 -28 cnv 15 220 70 empty empty empty 20 12 0 14 -195568 -66577 -0; -#N canvas 0 22 454 304 gemwin 0; -#X obj 132 136 gemwin; -#X obj 67 89 outlet; -#X obj 67 10 inlet; -#X obj 67 41 route create; -#X msg 67 70 set destroy; -#X msg 182 68 set create; -#X msg 132 112 create \, 1; -#X msg 238 112 destroy; -#N canvas 87 154 247 179 Gem.init 0; -#X obj 118 46 loadbang; -#X msg 118 81 reset; -#X obj 118 113 outlet; -#X connect 0 0 1 0; -#X connect 1 0 2 0; -#X restore 289 80 pd Gem.init; -#X connect 2 0 3 0; -#X connect 3 0 4 0; -#X connect 3 0 6 0; -#X connect 3 1 5 0; -#X connect 3 1 7 0; -#X connect 4 0 1 0; -#X connect 5 0 1 0; -#X connect 6 0 0 0; -#X connect 7 0 0 0; -#X connect 8 0 0 0; -#X restore 14 16 pd gemwin; -#X msg 14 -8 destroy; -#X text 15 -26 Create window and render; -#X obj 200 368 pix_texture; -#X obj 200 396 square 2; -#X obj 367 159 translateXYZ -2 0 0; -#X obj 367 224 separator; -#X obj 350 285 cnv 15 500 80 empty empty empty 20 12 0 14 -24198 -66577 -0; -#X obj 511 -66 bng 25 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 --1; -#X obj 524 128 unpack 0 0 0; -#X floatatom 514 151 5 0 0 3 length - -; -#X floatatom 563 151 5 0 0 3 width - -; -#X floatatom 613 151 5 0 0 3 height - -; -#X obj 568 109 bng 15 250 50 0 empty empty end_reached 20 7 0 10 -262144 --1 -1; -#X floatatom 550 74 5 0 10000 1 frame# - -; -#X obj 511 -37 openpanel; -#X msg 511 -17 open \$1; -#X obj 499 92 pix_film; -#X msg 517 26 auto \$1; -#X obj 517 8 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 -; -#X obj 364 259 translateXYZ 4 0 0; -#X obj 580 26 loadbang; -#X msg 528 50 colorspace RGBA; -#X floatatom 456 349 5 0 0 0 - - -; -#X obj 439 290 hradio 15 1 0 5 empty empty empty 0 -8 0 10 -262144 --1 -1 0; -#X text 522 289 save an histogram at position nth ( 0 <= n <= 80 ) -; -#X text 496 350 closest histogram; -#X obj 364 315 pix_opencv_histo; -#X text 5 -87 record histograms of specific situations; -#X text 7 -75 the object will recognize the situations if they occur -again; -#X text 7 -61 Written by Lluis Gomez i Bigorda ( lluisgomez@hangar.org -); -#X text 6 -100 pix_opencv_histo : image recognition using histograms -; -#X connect 0 0 21 0; -#X connect 1 0 2 0; -#X connect 4 0 5 0; -#X connect 5 0 4 0; -#X connect 7 0 8 0; -#X connect 9 0 7 0; -#X connect 9 0 10 0; -#X connect 10 0 24 0; -#X connect 12 0 19 0; -#X connect 13 0 14 0; -#X connect 13 1 15 0; -#X connect 13 2 16 0; -#X connect 17 0 18 0; -#X connect 18 0 21 1; -#X connect 19 0 20 0; -#X connect 20 0 21 0; -#X connect 21 0 9 0; -#X connect 21 1 13 0; -#X connect 21 2 17 0; -#X connect 22 0 21 0; -#X connect 23 0 22 0; -#X connect 24 0 31 0; -#X connect 25 0 26 0; -#X connect 26 0 21 0; -#X connect 28 0 31 1; -#X connect 31 0 1 0; -#X connect 31 1 27 0; diff --git a/pix_opencv_histo.cc b/pix_opencv_histo.cc deleted file mode 100755 index c5000ce..0000000 --- a/pix_opencv_histo.cc +++ /dev/null @@ -1,514 +0,0 @@ -//////////////////////////////////////////////////////// -// -// GEM - Graphics Environment for Multimedia -// -// zmoelnig@iem.kug.ac.at -// -// Implementation file -// -// Copyright (c) 1997-2000 Mark Danks. -// Copyright (c) Günther Geiger. -// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM -// Copyright (c) 2002 James Tittle & Chris Clepper -// For information on usage and redistribution, and for a DISCLAIMER OF ALL -// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. -// -///////////////////////////////////////////////////////// - -#include "pix_opencv_histo.h" - -CPPEXTERN_NEW(pix_opencv_histo) - -///////////////////////////////////////////////////////// -// -// pix_opencv_histo -// -///////////////////////////////////////////////////////// -// Constructor -// -///////////////////////////////////////////////////////// - -pix_opencv_histo :: pix_opencv_histo() -{ - int i; - - comp_xsize=320; - comp_ysize=240; - - inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("save")); - m_dataout = outlet_new(this->x_obj, &s_anything); - - save_now = 0; - - rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4); - rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3); - grey = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3 ); - - h_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - s_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - v_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - planes[0] = h_plane; - planes[1] = s_plane; - h_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - s_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - v_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - saved_planes[0] = h_saved_plane; - saved_planes[1] = s_saved_plane; - - int h_bins = (int)(comp_xsize/10), s_bins = (int)(comp_ysize/10); - { - int hist_size[] = { h_bins, s_bins }; - float h_ranges[] = { 0, 180 }; // hue is [0,180] - float s_ranges[] = { 0, 255 }; - float* ranges[] = { h_ranges, s_ranges }; - hist = cvCreateHist( - 2, - hist_size, - CV_HIST_ARRAY, - ranges, - 1 - ); - int n; - for (n=0; ncomp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize)) { - - this->comp_xsize=image.xsize; - this->comp_ysize=image.ysize; - - post( "pix_opencv_histo : reallocating buffers" ); - - //Destroy cv_images to clean memory - cvReleaseImage(&rgba); - cvReleaseImage(&rgb); - cvReleaseImage(&grey); - cvReleaseImage(&h_plane); - cvReleaseImage(&s_plane); - cvReleaseImage(&v_plane); - cvReleaseImage(&h_saved_plane); - cvReleaseImage(&s_saved_plane); - cvReleaseImage(&v_saved_plane); - - //Create cv_images - rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4); - rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3); - grey = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3 ); - - h_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - s_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - v_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - planes[0] = h_plane; - planes[1] = s_plane; - cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); - h_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - s_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - v_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - saved_planes[0] = h_saved_plane; - saved_planes[1] = s_saved_plane; - - h_bins = (int)(comp_xsize/10); - s_bins = (int)(comp_ysize/10); - { - int hist_size[] = { h_bins, s_bins }; - float h_ranges[] = { 0, 180 }; // hue is [0,180] - float s_ranges[] = { 0, 255 }; - float* ranges[] = { h_ranges, s_ranges }; - hist = cvCreateHist( - 2, - hist_size, - CV_HIST_ARRAY, - ranges, - 1 - ); - int n; - for (n=0; nimageData, image.data, image.xsize*image.ysize*4 ); - - // Convert to hsv - cvCvtColor( rgba, rgb, CV_BGRA2BGR ); - cvCvtColor( rgb, hsv, CV_BGR2HSV ); - cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); - - // Build the histogram and compute its contents. - if (save_now>=0) { - post("saving histogram %d\n",save_now); - cvCvtPixToPlane( hsv, h_saved_plane, s_saved_plane, v_saved_plane, 0 ); - cvCalcHist( saved_planes, saved_hist[save_now], 0, 0 ); //Compute histogram - cvNormalizeHist( saved_hist[save_now], 1.0 ); //Normalize it - save_now=-1; - nbsaved++; - } - cvCalcHist( planes, hist, 0, 0 ); //Compute histogram - cvNormalizeHist( hist, 1.0 ); //Normalize it - - double tato[MAX_HISTOGRAMS_TO_COMPARE]; - int nearest = -1; - double max = 0; - - int n; - if ( nbsaved > 0 ) - for (n=0; nmax) { - max = tato[n]; - nearest = n; - } - } - - outlet_float(m_dataout, (float)nearest); - - // Create an image to use to visualize our histogram. - int scale = 10; - // populate our visualization with little gray squares. - float max_value = 0; - cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 ); - - int h = 0; - int s = 0; - - for( h = 0; h < h_bins; h++ ) { - for( s = 0; s < s_bins; s++ ) { - float bin_val = cvQueryHistValue_2D( hist, h, s ); - int intensity = cvRound( bin_val * 255 / max_value ); - cvRectangle( - rgba, - cvPoint( h*scale, s*scale ), - cvPoint( (h+1)*scale - 1, (s+1)*scale - 1), - CV_RGB(intensity,intensity,intensity), CV_FILLED, 8 , 0 ); - } - } - - memcpy( image.data, rgba->imageData, image.xsize*image.ysize*4 ); - -} - -void pix_opencv_histo :: processRGBImage(imageStruct &image) -{ - int i; - int h_bins = (int)(comp_xsize/10), s_bins = (int)(comp_ysize/10); - - if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize)) { - - this->comp_xsize=image.xsize; - this->comp_ysize=image.ysize; - - //Destroy cv_images to clean memory - cvReleaseImage(&rgba); - cvReleaseImage(&rgb); - cvReleaseImage(&grey); - cvReleaseImage(&h_plane); - cvReleaseImage(&s_plane); - cvReleaseImage(&v_plane); - cvReleaseImage(&h_saved_plane); - cvReleaseImage(&s_saved_plane); - cvReleaseImage(&v_saved_plane); - - //Create cv_images - rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4); - rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3); - grey = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3 ); - - h_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - s_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - v_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - planes[0] = h_plane; - planes[1] = s_plane; - cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); - h_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - s_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - v_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - saved_planes[0] = h_saved_plane; - saved_planes[1] = s_saved_plane; - - h_bins = (int)(comp_xsize/10); - s_bins = (int)(comp_ysize/10); - { - int hist_size[] = { h_bins, s_bins }; - float h_ranges[] = { 0, 180 }; // hue is [0,180] - float s_ranges[] = { 0, 255 }; - float* ranges[] = { h_ranges, s_ranges }; - hist = cvCreateHist( - 2, - hist_size, - CV_HIST_ARRAY, - ranges, - 1 - ); - int n; - for (n=0; nimageData, image.data, image.xsize*image.ysize*3 ); - - // Convert to hsv - cvCvtColor( rgb, hsv, CV_BGR2HSV ); - cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); - - // Build the histogram and compute its contents. - if (save_now>=0) { - post("saving histogram %d\n",save_now); - cvCvtPixToPlane( hsv, h_saved_plane, s_saved_plane, v_saved_plane, 0 ); - cvCalcHist( saved_planes, saved_hist[save_now], 0, 0 ); //Compute histogram - cvNormalizeHist( saved_hist[save_now], 1.0 ); //Normalize it - save_now=-1; - nbsaved++; - } - cvCalcHist( planes, hist, 0, 0 ); //Compute histogram - cvNormalizeHist( hist, 1.0 ); //Normalize it - - double tato[MAX_HISTOGRAMS_TO_COMPARE]; - int nearest = -1; - double max = 0; - - int n; - if ( nbsaved > 0 ) - for (n=0; nmax) { - max = tato[n]; - nearest = n; - } - } - - outlet_float(m_dataout, (float)nearest); - - // Create an image to use to visualize our histogram. - int scale = 10; - // populate our visualization with little gray squares. - float max_value = 0; - cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 ); - - int h = 0; - int s = 0; - - for( h = 0; h < h_bins; h++ ) { - for( s = 0; s < s_bins; s++ ) { - float bin_val = cvQueryHistValue_2D( hist, h, s ); - int intensity = cvRound( bin_val * 255 / max_value ); - cvRectangle( - rgb, - cvPoint( h*scale, s*scale ), - cvPoint( (h+1)*scale - 1, (s+1)*scale - 1), - CV_RGB(intensity,intensity,intensity), CV_FILLED, 8 , 0 ); - } - } - - memcpy( image.data, rgb->imageData, image.xsize*image.ysize*3 ); - -} - -void pix_opencv_histo :: processYUVImage(imageStruct &image) -{ - post( "pix_opencv_histo : yuv format not supported" ); -} - -void pix_opencv_histo :: processGrayImage(imageStruct &image) -{ - int i; - int h_bins = (int)(comp_xsize/10), s_bins = (int)(comp_ysize/10); - - if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize)) { - - this->comp_xsize=image.xsize; - this->comp_ysize=image.ysize; - - //Destroy cv_images to clean memory - cvReleaseImage(&rgba); - cvReleaseImage(&rgb); - cvReleaseImage(&grey); - cvReleaseImage(&h_plane); - cvReleaseImage(&s_plane); - cvReleaseImage(&v_plane); - cvReleaseImage(&h_saved_plane); - cvReleaseImage(&s_saved_plane); - cvReleaseImage(&v_saved_plane); - - //Create cv_images - rgba = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 4); - rgb = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3); - grey = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - hsv = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 3 ); - - h_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - s_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - v_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - planes[0] = h_plane; - planes[1] = s_plane; - cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); - h_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - s_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - v_saved_plane = cvCreateImage(cvSize(comp_xsize,comp_ysize), IPL_DEPTH_8U, 1); - saved_planes[0] = h_saved_plane; - saved_planes[1] = s_saved_plane; - - h_bins = (int)(comp_xsize/10); - s_bins = (int)(comp_ysize/10); - { - int hist_size[] = { h_bins, s_bins }; - float h_ranges[] = { 0, 180 }; // hue is [0,180] - float s_ranges[] = { 0, 255 }; - float* ranges[] = { h_ranges, s_ranges }; - hist = cvCreateHist( - 2, - hist_size, - CV_HIST_ARRAY, - ranges, - 1 - ); - int n; - for (n=0; nimageData, image.data, image.xsize*image.ysize ); - - // Convert to hsv - cvCvtColor( grey, rgb, CV_GRAY2BGR ); - cvCvtColor( rgb, hsv, CV_BGR2HSV ); - cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 ); - - // Build the histogram and compute its contents. - if (save_now>=0) { - post("saving histogram %d\n",save_now); - cvCvtPixToPlane( hsv, h_saved_plane, s_saved_plane, v_saved_plane, 0 ); - cvCalcHist( saved_planes, saved_hist[save_now], 0, 0 ); //Compute histogram - cvNormalizeHist( saved_hist[save_now], 1.0 ); //Normalize it - save_now=-1; - nbsaved++; - } - cvCalcHist( planes, hist, 0, 0 ); //Compute histogram - cvNormalizeHist( hist, 1.0 ); //Normalize it - - double tato[MAX_HISTOGRAMS_TO_COMPARE]; - int nearest = -1; - double max = 0; - - int n; - if ( nbsaved > 0 ) - for (n=0; nmax) { - max = tato[n]; - nearest = n; - } - } - - outlet_float(m_dataout, (float)nearest); - - // Create an image to use to visualize our histogram. - int scale = 10; - // populate our visualization with little gray squares. - float max_value = 0; - cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 ); - - int h = 0; - int s = 0; - - for( h = 0; h < h_bins; h++ ) { - for( s = 0; s < s_bins; s++ ) { - float bin_val = cvQueryHistValue_2D( hist, h, s ); - int intensity = cvRound( bin_val * 255 / max_value ); - cvRectangle( - grey, - cvPoint( h*scale, s*scale ), - cvPoint( (h+1)*scale - 1, (s+1)*scale - 1), - CV_RGB(intensity,intensity,intensity), CV_FILLED, 8 , 0 ); - } - } - - memcpy( image.data, grey->imageData, image.xsize*image.ysize ); - -} - -///////////////////////////////////////////////////////// -// static member function -// -///////////////////////////////////////////////////////// - -void pix_opencv_histo :: obj_setupCallback(t_class *classPtr) -{ - class_addmethod(classPtr, (t_method)&pix_opencv_histo::saveMessCallback, - gensym("save"), A_FLOAT, A_NULL); -} - -void pix_opencv_histo :: saveMess(float index) -{ - if (((int)index>=0)&&((int)indexsaveMess(index); -} diff --git a/pix_opencv_histo.h b/pix_opencv_histo.h deleted file mode 100755 index ca27166..0000000 --- a/pix_opencv_histo.h +++ /dev/null @@ -1,88 +0,0 @@ -/*----------------------------------------------------------------- -LOG - GEM - Graphics Environment for Multimedia - - Change pix to greyscale - - Copyright (c) 1997-1999 Mark Danks. mark@danks.org - Copyright (c) Günther Geiger. geiger@epy.co.at - Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM. zmoelnig@iem.kug.ac.at - Copyright (c) 2002 James Tittle & Chris Clepper - For information on usage and redistribution, and for a DISCLAIMER OF ALL - WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. - ------------------------------------------------------------------*/ - -#ifndef INCLUDE_PIX_OPENCV_HISTO_H_ -#define INCLUDE_PIX_OPENCV_HISTO_H_ - -#include "Base/GemPixObj.h" - -#ifndef _EiC -#include "cv.h" -#endif - -#define MAX_HISTOGRAMS_TO_COMPARE 80 - -/*----------------------------------------------------------------- -------------------------------------------------------------------- -CLASS - pix_opencv_histo - - Histogram reognition object using Open CV - -KEYWORDS - pix - -DESCRIPTION - ------------------------------------------------------------------*/ - -class GEM_EXTERN pix_opencv_histo : public GemPixObj -{ - CPPEXTERN_HEADER(pix_opencv_histo, GemPixObj) - - public: - - ////////// - // Constructor - pix_opencv_histo(); - - protected: - - ////////// - // Destructor - virtual ~pix_opencv_histo(); - - ////////// - // Do the processing - virtual void processRGBAImage(imageStruct &image); - virtual void processRGBImage(imageStruct &image); - virtual void processYUVImage(imageStruct &image); - virtual void processGrayImage(imageStruct &image); - - void saveMess(float index); - - int comp_xsize; - int comp_ysize; - - t_outlet *m_dataout; - - private: - - ////////// - // Static member functions - static void saveMessCallback(void *data, t_floatarg index); - - // The output and temporary images - int save_now; - int nbsaved; - - CvHistogram *hist; - CvHistogram *saved_hist[MAX_HISTOGRAMS_TO_COMPARE]; - IplImage *rgba, *rgb, *grey, *hsv, *h_plane, *s_plane, *v_plane, *h_saved_plane, *s_saved_plane, *v_saved_plane, *planes[2],*saved_planes[2]; - - -}; - -#endif // for header file -- cgit v1.2.1