7 #include "libavutil/frame.h"
29 unsigned int w,
unsigned int h,
30 unsigned int commdetectborder_in)
32 m_commDetector(commdetector),
33 m_commDetectBorder(commdetectborder_in),
36 m_logoMaxValues(new unsigned char[m_width * m_height]),
37 m_logoMinValues(new unsigned char[m_width * m_height]),
38 m_logoFrame(new unsigned char[m_width * m_height]),
39 m_logoMask(new unsigned char[m_width * m_height]),
40 m_logoCheckMask(new unsigned char[m_width * m_height])
82 LogoDetectorBase::deleteLater();
90 const std::array<const int,9> edgeDiffs {5, 7, 10, 15, 20, 30, 40, 50, 60 };
93 LOG(VB_COMMFLAG, LOG_INFO,
"Searching for Station Logo");
107 int minPixelsInMask =
110 for (
uint edgediff : edgeDiffs)
112 int pixelsInMask = 0;
114 LOG(VB_COMMFLAG, LOG_INFO,
115 QString(
"Trying with edgeDiff == %1, minPixelsInMask=%2")
116 .arg(edgediff).arg(minPixelsInMask));
125 while (loops < maxLoops && player->GetEof() ==
kEofStateNone)
129 if ((loops % 50) == 0)
140 std::this_thread::sleep_for(10ms);
144 seekFrame += seekIncrement;
150 LOG(VB_COMMFLAG, LOG_INFO,
"Analyzing edge data");
152 #ifdef SHOW_DEBUG_WIN
153 unsigned char *fakeFrame;
170 if (edgeCounts[pos].m_isEdge > (maxLoops * 0.66))
174 #ifdef SHOW_DEBUG_WIN
175 fakeFrame[pos] = 0xff;
180 if (edgeCounts[pos].m_horiz > (maxLoops * 0.66))
183 if (edgeCounts[pos].m_vert > (maxLoops * 0.66))
186 if (edgeCounts[pos].m_ldiag > (maxLoops * 0.66))
188 if (edgeCounts[pos].m_rdiag > (maxLoops * 0.66))
204 for (
uint dy = y - 2; dy <= (y + 2); dy++ )
206 for (
uint dx = x - 2; dx <= (x + 2); dx++ )
219 LOG(VB_COMMFLAG, LOG_INFO,
220 QString(
"Testing Logo area: topleft (%1,%2), bottomright (%3,%4)")
224 #ifdef SHOW_DEBUG_WIN
228 fakeFrame[pos] = 0x7f;
230 fakeFrame[pos] = 0x7f;
235 fakeFrame[pos] = 0x7f;
237 fakeFrame[pos] = 0x7f;
240 comm_debug_show(fakeFrame);
243 cerr <<
"Hit ENTER to continue" << endl;
248 (pixelsInMask > minPixelsInMask))
253 LOG(VB_COMMFLAG, LOG_INFO,
254 QString(
"Using Logo area: topleft (%1,%2), "
255 "bottomright (%3,%4), pixelsInMask (%5).")
262 LOG(VB_COMMFLAG, LOG_INFO,
263 QString(
"Rejecting Logo area: topleft (%1,%2), "
264 "bottomright (%3,%4), pixelsInMask (%5). "
265 "Not within specified limits.")
271 delete [] edgeCounts;
274 LOG(VB_COMMFLAG, LOG_NOTICE,
"No suitable logo area found.");
283 LOG(VB_COMMFLAG, LOG_INFO,
"SetLogoMaskArea()");
290 for (
unsigned int y = 0; y <
m_height; y++)
292 for (
unsigned int x = 0; x <
m_width; x++)
325 const unsigned char* framePtr)
327 std::string scrPixels {
" .oxX"};
332 std::cerr <<
"\nLogo Data ";
333 if (fromCurrentFrame)
334 std::cerr <<
"from current frame\n";
339 std::cerr << (x % 10);
344 QString
tmp = QString(
"%1: ").arg(y, 3);
345 QString ba =
tmp.toLatin1();
346 std::cerr << ba.constData();
349 if (fromCurrentFrame)
351 std::cerr << scrPixels[framePtr[y *
m_width + x] / 50];
358 case 2: std::cerr <<
" ";
360 case 1: std::cerr <<
"*";
362 case 3: std::cerr <<
".";
383 int testNotEdges = 0;
385 unsigned char* framePtr = frame->
m_buffer;
392 int pos1 = y * bytesPerLine + x;
394 int pos2 = (y - radius) * bytesPerLine + x;
395 int pos3 = (y + radius) * bytesPerLine + x;
397 int pixel = framePtr[pos1];
432 double goodEdgeRatio = (testEdges) ?
433 (
double)goodEdges / (double)testEdges : 0.0;
434 double badEdgeRatio = (testNotEdges) ?
435 (
double)badEdges / (double)testNotEdges : 0.0;
453 unsigned char *buf = frame->
m_buffer;
477 uchar
p = buf[y * bytesPerLine + x];
479 if (( abs(buf[y * bytesPerLine + (x - r)] -
p) >= edgeDiff) ||
480 ( abs(buf[y * bytesPerLine + (x + r)] -
p) >= edgeDiff))
485 if (( abs(buf[(y - r) * bytesPerLine + x] -
p) >= edgeDiff) ||
486 ( abs(buf[(y + r) * bytesPerLine + x] -
p) >= edgeDiff))
492 if (( abs(buf[(y - r) * bytesPerLine + (x - r)] -
p) >= edgeDiff) ||
493 ( abs(buf[(y + r) * bytesPerLine + (x + r)] -
p) >= edgeDiff))
499 if (( abs(buf[(y - r) * bytesPerLine + (x + r)] -
p) >= edgeDiff) ||
500 ( abs(buf[(y + r) * bytesPerLine + (x - r)] -
p) >= edgeDiff))