8 #include "libavutil/frame.h"
30 unsigned int w,
unsigned int h,
31 unsigned int commdetectborder_in)
33 m_commDetector(commdetector),
34 m_commDetectBorder(commdetectborder_in),
35 m_commDetectLogoSecondsNeeded((int)(1.3 * m_commDetectLogoSamplesNeeded *
36 m_commDetectLogoSampleSpacing)),
39 m_logoMaxValues(new unsigned char[m_width * m_height]),
40 m_logoMinValues(new unsigned char[m_width * m_height]),
41 m_logoFrame(new unsigned char[m_width * m_height]),
42 m_logoMask(new unsigned char[m_width * m_height]),
43 m_logoCheckMask(new unsigned char[m_width * m_height])
83 LogoDetectorBase::deleteLater();
91 const std::array<const int,9> edgeDiffs {5, 7, 10, 15, 20, 30, 40, 50, 60 };
94 LOG(VB_COMMFLAG, LOG_INFO,
"Searching for Station Logo");
108 int minPixelsInMask =
111 for (
uint edgediff : edgeDiffs)
113 int pixelsInMask = 0;
115 LOG(VB_COMMFLAG, LOG_INFO,
116 QString(
"Trying with edgeDiff == %1, minPixelsInMask=%2")
117 .arg(edgediff).arg(minPixelsInMask));
126 while (loops < maxLoops && player->GetEof() ==
kEofStateNone)
130 if ((loops % 50) == 0)
141 std::this_thread::sleep_for(10ms);
145 seekFrame += seekIncrement;
151 LOG(VB_COMMFLAG, LOG_INFO,
"Analyzing edge data");
153 #ifdef SHOW_DEBUG_WIN
154 unsigned char *fakeFrame;
171 if (edgeCounts[pos].m_isEdge > (maxLoops * 0.66))
175 #ifdef SHOW_DEBUG_WIN
176 fakeFrame[pos] = 0xff;
181 if (edgeCounts[pos].m_horiz > (maxLoops * 0.66))
184 if (edgeCounts[pos].m_vert > (maxLoops * 0.66))
187 if (edgeCounts[pos].m_ldiag > (maxLoops * 0.66))
189 if (edgeCounts[pos].m_rdiag > (maxLoops * 0.66))
205 for (
uint dy = y - 2; dy <= (y + 2); dy++ )
207 for (
uint dx = x - 2; dx <= (x + 2); dx++ )
220 LOG(VB_COMMFLAG, LOG_INFO,
221 QString(
"Testing Logo area: topleft (%1,%2), bottomright (%3,%4)")
225 #ifdef SHOW_DEBUG_WIN
229 fakeFrame[pos] = 0x7f;
231 fakeFrame[pos] = 0x7f;
236 fakeFrame[pos] = 0x7f;
238 fakeFrame[pos] = 0x7f;
241 comm_debug_show(fakeFrame);
244 cerr <<
"Hit ENTER to continue" << endl;
249 (pixelsInMask > minPixelsInMask))
254 LOG(VB_COMMFLAG, LOG_INFO,
255 QString(
"Using Logo area: topleft (%1,%2), "
256 "bottomright (%3,%4), pixelsInMask (%5).")
263 LOG(VB_COMMFLAG, LOG_INFO,
264 QString(
"Rejecting Logo area: topleft (%1,%2), "
265 "bottomright (%3,%4), pixelsInMask (%5). "
266 "Not within specified limits.")
272 delete [] edgeCounts;
275 LOG(VB_COMMFLAG, LOG_NOTICE,
"No suitable logo area found.");
284 LOG(VB_COMMFLAG, LOG_INFO,
"SetLogoMaskArea()");
291 for (
unsigned int y = 0; y <
m_height; y++)
293 for (
unsigned int x = 0; x <
m_width; x++)
318 const unsigned char* framePtr)
320 std::string scrPixels {
" .oxX"};
325 std::cerr <<
"\nLogo Data ";
326 if (fromCurrentFrame)
327 std::cerr <<
"from current frame\n";
332 std::cerr << (x % 10);
337 QString
tmp = QString(
"%1: ").arg(y, 3);
338 QString ba =
tmp.toLatin1();
339 std::cerr << ba.constData();
342 if (fromCurrentFrame)
344 std::cerr << scrPixels[framePtr[(y *
m_width) + x] / 50];
351 case 2: std::cerr <<
" ";
353 case 1: std::cerr <<
"*";
355 case 3: std::cerr <<
".";
376 int testNotEdges = 0;
378 unsigned char* framePtr = frame->
m_buffer;
385 int pos1 = (y * bytesPerLine) + x;
386 int edgePos = (y *
m_width) + x;
387 int pos2 = ((y - radius) * bytesPerLine) + x;
388 int pos3 = ((y + radius) * bytesPerLine) + x;
390 int pixel = framePtr[pos1];
425 double goodEdgeRatio = (testEdges) ?
426 (
double)goodEdges / (double)testEdges : 0.0;
427 double badEdgeRatio = (testNotEdges) ?
428 (
double)badEdges / (double)testNotEdges : 0.0;
446 unsigned char *buf = frame->
m_buffer;
470 uchar
p = buf[(y * bytesPerLine) + x];
472 if (( abs(buf[(y * bytesPerLine) + (x - r)] -
p) >= edgeDiff) ||
473 ( abs(buf[(y * bytesPerLine) + (x + r)] -
p) >= edgeDiff))
478 if (( abs(buf[((y - r) * bytesPerLine) + x] -
p) >= edgeDiff) ||
479 ( abs(buf[((y + r) * bytesPerLine) + x] -
p) >= edgeDiff))
485 if (( abs(buf[((y - r) * bytesPerLine) + (x - r)] -
p) >= edgeDiff) ||
486 ( abs(buf[((y + r) * bytesPerLine) + (x + r)] -
p) >= edgeDiff))
492 if (( abs(buf[((y - r) * bytesPerLine) + (x + r)] -
p) >= edgeDiff) ||
493 ( abs(buf[((y + r) * bytesPerLine) + (x - r)] -
p) >= edgeDiff))