http://wiki.nosdigitais.teia.org.br/index.php?title=AHTcode&feed=atom&action=history
AHTcode - Histórico de revisão
2024-03-29T12:59:12Z
Histórico de revisões para esta página neste wiki
MediaWiki 1.39.0
http://wiki.nosdigitais.teia.org.br/index.php?title=AHTcode&diff=3079&oldid=prev
V1z em 13h28min de 15 de setembro de 2011
2011-09-15T13:28:34Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="pt-BR">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Edição anterior</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Edição das 10h28min de 15 de setembro de 2011</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l434">Linha 434:</td>
<td colspan="2" class="diff-lineno">Linha 434:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Pode comentar, se precisar de me contatar veja meus contatos [[Nivaldo Bondança|aqui]]</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Pode comentar, se precisar de me contatar veja meus contatos [[Nivaldo Bondança|aqui]]</div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[Category:Lab Macambira]]</ins></div></td></tr>
</table>
V1z
http://wiki.nosdigitais.teia.org.br/index.php?title=AHTcode&diff=3066&oldid=prev
Hick209 em 23h23min de 14 de setembro de 2011
2011-09-14T23:23:50Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="pt-BR">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Edição anterior</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Edição das 20h23min de 14 de setembro de 2011</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Linha 1:</td>
<td colspan="2" class="diff-lineno">Linha 1:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Aí está o código, na íntegra</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Aí está o código, na íntegra</div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><i> Em Breve: </i> More comments!</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre></div></td></tr>
</table>
Hick209
http://wiki.nosdigitais.teia.org.br/index.php?title=AHTcode&diff=3039&oldid=prev
Hick209: Nova página: Aí está o código, na íntegra <pre> /* Programa esqueleto da AirHackTable */ #include "opencv/highgui.h" #include "opencv/cv.h" #include <stdio.h> using namespace cv; voi...
2011-09-13T00:13:13Z
<p>Nova página: Aí está o código, na íntegra <pre> <span dir="auto"><span class="autocomment">Programa esqueleto da AirHackTable: </span> #include "opencv/highgui.h" #include "opencv/cv.h" #include <stdio.h> using namespace cv; voi...</span></p>
<p><b>Página nova</b></p><div>Aí está o código, na íntegra<br />
<br />
<pre><br />
/*<br />
Programa esqueleto da AirHackTable<br />
*/<br />
<br />
#include "opencv/highgui.h"<br />
#include "opencv/cv.h"<br />
#include <stdio.h><br />
<br />
<br />
using namespace cv;<br />
<br />
<br />
void pausef(void);<br />
<br />
class ColorHistogram<br />
{<br />
private:<br />
int histSize[3];<br />
float hranges[2];<br />
const float* ranges[3];<br />
int channels[3];<br />
public:<br />
ColorHistogram()<br />
{<br />
// Prepare arguments for a color histogram<br />
histSize[0]= histSize[1]= histSize[2]= 256;<br />
hranges[0]= 0.0; // BRG range<br />
hranges[1]= 255.0;<br />
ranges[0]= hranges; // all channels have the same range<br />
ranges[1]= hranges;<br />
ranges[2]= hranges;<br />
channels[0]= 0; // the three channels<br />
channels[1]= 1;<br />
channels[2]= 2;<br />
}<br />
<br />
cv::MatND getHistogram(const cv::Mat &image)<br />
{<br />
cv::MatND hist;<br />
// Compute histogram<br />
cv::calcHist(&image,<br />
1, // histogram of 1 image only<br />
channels, // the channel used<br />
cv::Mat(), // no mask is used<br />
hist, // the resulting histogram<br />
3, // it is a 3D histogram<br />
histSize, // number of bins<br />
ranges // pixel value range<br />
);<br />
return hist;<br />
}<br />
<br />
// Computes the 1D Hue histogram with a mask.<br />
// BGR source image is converted to HSV<br />
// Pixels with low saturation are ignored<br />
cv::MatND getHueHistogram(const cv::Mat &image,<br />
int minSaturation=0)<br />
{<br />
cv::MatND hist;<br />
<br />
// Convert to HSV color space<br />
cv::Mat hsv;<br />
cv::cvtColor(image, hsv, CV_BGR2HSV);<br />
<br />
// Mask to be used (or not)<br />
cv::Mat mask;<br />
if (minSaturation>0)<br />
{<br />
// Spliting the 3 channels into 3 images<br />
std::vector<cv::Mat> v;<br />
cv::split(hsv,v);<br />
<br />
// Mask out the low saturated pixels<br />
cv::threshold(v[1],mask,minSaturation,255,<br />
cv::THRESH_BINARY);<br />
}<br />
<br />
// Prepare arguments for a 1D hue histogram<br />
hranges[0]= 0.0;<br />
hranges[1]= 180.0;<br />
channels[0]= 0; // the hue channel<br />
<br />
// Compute histogram<br />
cv::calcHist(&hsv,<br />
1, // histogram of 1 image only<br />
channels, // the channel used<br />
mask, // binary mask<br />
hist, // the resulting histogram<br />
1, // it is a 1D histogram<br />
histSize, // number of bins<br />
ranges // pixel value range<br />
);<br />
<br />
return hist;<br />
}<br />
};<br />
<br />
class ContentFinder<br />
{<br />
private:<br />
float hranges[2];<br />
const float* ranges[3];<br />
int channels[3];<br />
float threshold;<br />
cv::MatND histogram;<br />
public:<br />
ContentFinder() : threshold(-1.0f)<br />
{<br />
ranges[0]= hranges; // all channels have same range<br />
ranges[1]= hranges;<br />
ranges[2]= hranges;<br />
}<br />
// Sets the threshold on histogram values [0,1]<br />
void setThreshold(float t)<br />
{<br />
threshold= t;<br />
}<br />
// Gets the threshold<br />
float getThreshold()<br />
{<br />
return threshold;<br />
}<br />
// Sets the reference histogram<br />
void setHistogram(const MatND& h)<br />
{<br />
histogram= h;<br />
cv::normalize(histogram,histogram,1.0);<br />
}<br />
<br />
Mat find(const cv::Mat& image)<br />
{<br />
Mat result;<br />
<br />
hranges[0]= 0.0; // range [0,255]<br />
hranges[1]= 255.0;<br />
channels[0]= 0; // the three channels<br />
channels[1]= 1;<br />
channels[2]= 2;<br />
<br />
cv::calcBackProject(&image,<br />
1, // one image<br />
channels, // vector specifying what histogram dimensions belong to what image channels<br />
histogram, // the histogram we are using<br />
result, // the resulting back projection image<br />
ranges, // the range of values, for each dimension<br />
255.0 // the scaling factor is chosen such that a histogram value of 1 maps to 255<br />
);<br />
<br />
// Threshold back projection to obtain a binary image<br />
if (threshold>0.0)<br />
cv::threshold(result, result, 255*threshold, 255, cv::THRESH_BINARY);<br />
<br />
return result;<br />
}<br />
<br />
Mat find(const cv::Mat& image, float minValue, float maxValue, int *channels, int dim) {<br />
<br />
cv::Mat result;<br />
<br />
hranges[0]= minValue;<br />
hranges[1]= maxValue;<br />
<br />
for (int i=0; i<dim; i++)<br />
this->channels[i]= channels[i];<br />
<br />
// NOT USING THIS PART<br />
// if (isSparse) { // call the right function based on histogram type<br />
//<br />
// cv::calcBackProject(&image,<br />
// 1, // we only use one image at a time<br />
// channels, // vector specifying what histogram dimensions belong to what image channels<br />
// shistogram, // the histogram we are using<br />
// result, // the resulting back projection image<br />
// ranges, // the range of values, for each dimension<br />
// 255.0 // the scaling factor is chosen such that a histogram value of 1 maps to 255<br />
// );<br />
//<br />
// } else {<br />
<br />
cv::calcBackProject(&image,<br />
1, // we only use one image at a time<br />
channels, // vector specifying what histogram dimensions belong to what image channels<br />
histogram, // the histogram we are using<br />
result, // the resulting back projection image<br />
ranges, // the range of values, for each dimension<br />
255.0 // the scaling factor is chosen such that a histogram value of 1 maps to 255<br />
);<br />
// }<br />
<br />
// Threshold back projection to obtain a binary image<br />
if (threshold>0.0)<br />
cv::threshold(result, result, 255*threshold, 255, cv::THRESH_BINARY);<br />
<br />
return result;<br />
}<br />
};<br />
<br />
// AirHackTable<br />
class AHT<br />
{<br />
private:<br />
// int pad;<br />
#define TAM 1<br />
#define PAD 15<br />
// amount of circles to be detected<br />
ContentFinder circleFinder;<br />
ColorHistogram hist;<br />
Point circleCenter;<br />
Point circleCenter2;<br />
<br />
void sharpen(Mat &image)<br />
{<br />
// Construct kernel (all entries initialized to 0)<br />
Mat kernel(3,3,CV_32F,Scalar(0));<br />
<br />
// assigns kernel values<br />
kernel.at<float>(1,1)= 5.0;<br />
kernel.at<float>(0,1)= -1.0;<br />
kernel.at<float>(2,1)= -1.0;<br />
kernel.at<float>(1,0)= -1.0;<br />
kernel.at<float>(1,2)= -1.0;<br />
<br />
// filter the image<br />
filter2D( image, image, image.depth(), kernel);<br />
}<br />
<br />
void colorReduce(Mat &image, int div=64)<br />
{<br />
int nl = image.rows; // number of lines<br />
// total number of elements per line<br />
int nc = image.cols * image.channels();<br />
for (int j = 0; j < nl; j++)<br />
{<br />
// get the address of row j<br />
uchar* data = image.ptr<uchar>(j);<br />
for (int i = 0; i < nc; i++)<br />
{<br />
data[i] = data[i]/div*div + div/2;<br />
} // end of line<br />
}<br />
}<br />
<br />
public:<br />
Mat process(Mat &image)<br />
{<br />
Mat result, thres;<br />
<br />
flip( image, image, 1 );<br />
<br />
sharpen( image );<br />
<br />
colorReduce( image, 32 );<br />
<br />
cvtColor( image, result, CV_RGB2GRAY );<br />
<br />
equalizeHist( result, result );<br />
<br />
// Canny( result, result, 0, 255);<br />
<br />
GaussianBlur( result, result, Size(7,7) , 3);<br />
<br />
// threshold( result, thres, 110, 255, CV_THRESH_BINARY);<br />
<br />
// result += thres/10;<br />
<br />
return result;<br />
}<br />
<br />
// old version, not using anymore<br />
// it is still here so I can use its code<br />
void findCircles(Mat &image, Mat result, int minSaturation=0)<br />
{<br />
circleFinder.setThreshold(0.05f);<br />
<br />
// pad = 15;<br />
<br />
double count, sx[TAM] = { 0 }, sy[TAM] = { 0 };<br />
<br />
// holds the detected circles<br />
vector<Vec3f> circles;<br />
<br />
HoughCircles( result( Rect( PAD, PAD, result.cols-PAD, result.rows-PAD) ), circles, CV_HOUGH_GRADIENT, 1.65, 32);<br />
<br />
// TODO<br />
// To be improved<br />
for( size_t i = 0, count = 0; i < circles.size() && count < TAM; i++, count++ )<br />
{<br />
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));<br />
<br />
// if ( (center.x - sx[count] < 5) && ( center.y - sy[count] < 5) )<br />
{<br />
Mat ROI = image( Rect( center.x-PAD, center.y-PAD, 2*PAD, 2*PAD ) );<br />
circleFinder.setHistogram(hist.getHueHistogram(ROI, minSaturation));<br />
<br />
// hist = f.find(image);<br />
// hist += f.find(image);<br />
<br />
circle( image, Point(center.x+PAD, center.y+PAD) , 19, 255, 2 );<br />
}<br />
<br />
sx[count] = center.x;<br />
sy[count] = center.y;<br />
}<br />
}<br />
<br />
void getCircles(Mat image, Mat result, int minSaturation=0)<br />
{<br />
// holds the detected circles<br />
vector<Vec3f> circles;<br />
<br />
HoughCircles( result( Rect( PAD, PAD, result.cols-PAD, result.rows-PAD) ), circles, CV_HOUGH_GRADIENT, 1.65, 32);<br />
<br />
// TODO<br />
if( circles.size() )<br />
{<br />
Point center(cvRound(circles[0][0]), cvRound(circles[0][1]));<br />
<br />
Mat ROI = image( Rect( center.x-PAD, center.y-PAD, 2*PAD, 2*PAD ) );<br />
circleFinder.setHistogram(hist.getHueHistogram(ROI, minSaturation));<br />
<br />
circleCenter = center;<br />
}<br />
}<br />
<br />
// not using yet<br />
void nextPosition(Mat image, int minSaturation=0)<br />
{<br />
Mat hsv;<br />
// Convert to HSV space<br />
cvtColor( image, hsv, CV_BGR2HSV );<br />
<br />
std::vector<Mat> v;<br />
// Split the image<br />
split( hsv, v );<br />
<br />
// Identify pixels with low saturation<br />
threshold( v[1], v[1], minSaturation, 255, THRESH_BINARY );<br />
<br />
int ch[1]={0};<br />
// Get back-projection of hue histogram<br />
Mat result = circleFinder.find( hsv, 0.0f, 180.0f, ch,1 );<br />
<br />
// Eliminate low stauration pixels<br />
bitwise_and( result, v[1], result );<br />
<br />
Rect rect(circleCenter.x+PAD,circleCenter.y+PAD,1,1);<br />
// rectangle(image, rect, cv::Scalar(0,0,255));<br />
<br />
TermCriteria criteria( cv::TermCriteria::MAX_ITER, 10, 0.01 );<br />
<br />
meanShift( result, rect, criteria );<br />
<br />
circleCenter2.x = rect.x;<br />
circleCenter2.y = rect.y;<br />
// return result;<br />
}<br />
<br />
void drawCircle(Mat &image)<br />
{<br />
if( circleCenter.x != 0 )<br />
circle( image, Point(circleCenter.x+PAD, circleCenter.y+PAD) , 19, 255, 2 );<br />
if( circleCenter2.x != 0 )<br />
circle( image, Point(circleCenter2.x, circleCenter2.y) , 19, 0, 2 );<br />
}<br />
};<br />
<br />
int main( int argc, char** argv )<br />
{<br />
char c;<br />
int minSat = 65;<br />
<br />
namedWindow( "player", 0 );<br />
// namedWindow( "mod", 0 );<br />
// namedWindow( "Histogram", 0 );<br />
<br />
CvCapture *cam;<br />
<br />
if( argc != 2 )<br />
cam = cvCreateCameraCapture(0);<br />
// else<br />
// cam.open( string(argv[1]) )<br />
Mat frame, modframe;<br />
<br />
AHT image;<br />
<br />
while(1)<br />
{<br />
// gets the next frame<br />
frame = cvQueryFrame(cam);<br />
<br />
if(!frame.data) break;<br />
<br />
modframe = image.process(frame);<br />
<br />
// look for the circles<br />
// image.findCircles(frame, modframe);<br />
if( c == 'g' )<br />
image.getCircles(frame, modframe, minSat);<br />
if( c == 'n' )<br />
image.nextPosition(frame, minSat);<br />
<br />
image.drawCircle(frame);<br />
<br />
// show results<br />
// imshow("Histogram", hist);<br />
imshow( "player", frame );<br />
// imshow( "mod", modframe );<br />
<br />
c = cvWaitKey(3);<br />
// c == ESC<br />
if( c == 27 ) break;<br />
else if( c == ' ' || c == 'p' ) pausef();<br />
}<br />
<br />
destroyWindow("player");<br />
// destroyWindow("mod");<br />
// destroyWindow("Histogram");<br />
<br />
return 0;<br />
}<br />
<br />
void pausef()<br />
{<br />
char c = 0;<br />
while( c != 'p' && c != ' ' )<br />
c = cvWaitKey(0);<br />
}<br />
</pre><br />
<br />
Pode comentar, se precisar de me contatar veja meus contatos [[Nivaldo Bondança|aqui]]</div>
Hick209