|
|
|
@ -189,7 +189,7 @@ void TransformImage_NV12( |
|
|
|
|
CGrayscale::CGrayscale() : |
|
|
|
|
m_pSample(NULL), m_pInputType(NULL), m_pOutputType(NULL), |
|
|
|
|
m_imageWidthInPixels(0), m_imageHeightInPixels(0), m_cbImageSize(0), |
|
|
|
|
m_TransformType(Preview), m_rcDest(D2D1::RectU()), m_bStreamingInitialized(false), |
|
|
|
|
m_TransformType(Preview), m_rcDest(D2D1::RectU()), m_bStreamingInitialized(false), |
|
|
|
|
m_pAttributes(NULL) |
|
|
|
|
{ |
|
|
|
|
InitializeCriticalSectionEx(&m_critSec, 3000, 0); |
|
|
|
@ -1350,10 +1350,13 @@ HRESULT CGrayscale::BeginStreaming() |
|
|
|
|
goto done; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get the chroma transformations.
|
|
|
|
|
// Get the effect type
|
|
|
|
|
UINT32 effect = MFGetAttributeUINT32(m_pAttributes, MFT_IMAGE_EFFECT, 1); |
|
|
|
|
|
|
|
|
|
// float scale = (float)MFGetAttributeDouble(m_pAttributes, MFT_GRAYSCALE_SATURATION, 0.0f);
|
|
|
|
|
// float angle = (float)MFGetAttributeDouble(m_pAttributes, MFT_GRAYSCALE_CHROMA_ROTATION, 0.0f);
|
|
|
|
|
if ((effect >= 0) && (effect < InvalidEffect)) |
|
|
|
|
{ |
|
|
|
|
m_TransformType = (ProcessingType)effect; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_bStreamingInitialized = true; |
|
|
|
|
} |
|
|
|
@ -1414,15 +1417,71 @@ HRESULT CGrayscale::OnProcessOutput(IMFMediaBuffer *pIn, IMFMediaBuffer *pOut) |
|
|
|
|
return hr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//(*m_pTransformFn)(m_transform, m_rcDest, pDest, lDestStride, pSrc, lSrcStride,
|
|
|
|
|
// m_imageWidthInPixels, m_imageHeightInPixels);
|
|
|
|
|
cv::Mat InputFrame(m_imageHeightInPixels + m_imageHeightInPixels/2, m_imageWidthInPixels, CV_8UC1, pSrc, lSrcStride); |
|
|
|
|
cv::Mat InputGreyScale(InputFrame, cv::Range(0, m_imageHeightInPixels), cv::Range(0, m_imageWidthInPixels)); |
|
|
|
|
cv::Mat OutputFrame(m_imageHeightInPixels + m_imageHeightInPixels/2, m_imageWidthInPixels, CV_8UC1, pDest, lDestStride); |
|
|
|
|
|
|
|
|
|
switch (m_TransformType) |
|
|
|
|
{ |
|
|
|
|
case Preview: |
|
|
|
|
{ |
|
|
|
|
InputFrame.copyTo(OutputFrame); |
|
|
|
|
} break; |
|
|
|
|
case GrayScale: |
|
|
|
|
{ |
|
|
|
|
OutputFrame.setTo(cv::Scalar(128)); |
|
|
|
|
cv::Mat OutputGreyScale(OutputFrame, cv::Range(0, m_imageHeightInPixels), cv::Range(0, m_imageWidthInPixels)); |
|
|
|
|
InputGreyScale.copyTo(OutputGreyScale); |
|
|
|
|
} break; |
|
|
|
|
case Canny: |
|
|
|
|
{ |
|
|
|
|
OutputFrame.setTo(cv::Scalar(128)); |
|
|
|
|
cv::Mat OutputGreyScale(OutputFrame, cv::Range(0, m_imageHeightInPixels), cv::Range(0, m_imageWidthInPixels)); |
|
|
|
|
cv::Canny(InputGreyScale, OutputGreyScale, 80, 90); |
|
|
|
|
|
|
|
|
|
cv::Mat InputFrame(m_imageHeightInPixels + m_imageHeightInPixels/2, m_imageWidthInPixels, CV_8UC1, pSrc, lSrcStride); |
|
|
|
|
cv::Mat InputGreyScale(InputFrame, cv::Range(0, m_imageHeightInPixels), cv::Range(0, m_imageWidthInPixels)); |
|
|
|
|
cv::Mat OutputFrame(m_imageHeightInPixels + m_imageHeightInPixels/2, m_imageWidthInPixels, CV_8UC1, pDest, lDestStride); |
|
|
|
|
OutputFrame.setTo(cv::Scalar(128)); |
|
|
|
|
cv::Mat OutputGreyScale(OutputFrame, cv::Range(0, m_imageHeightInPixels), cv::Range(0, m_imageWidthInPixels)); |
|
|
|
|
cv::Canny(InputGreyScale, OutputGreyScale, 80, 90); |
|
|
|
|
} break; |
|
|
|
|
case Sobel: |
|
|
|
|
{ |
|
|
|
|
OutputFrame.setTo(cv::Scalar(128)); |
|
|
|
|
cv::Mat OutputGreyScale(OutputFrame, cv::Range(0, m_imageHeightInPixels), cv::Range(0, m_imageWidthInPixels)); |
|
|
|
|
cv::Sobel(InputGreyScale, OutputGreyScale, CV_8U, 1, 1); |
|
|
|
|
} break; |
|
|
|
|
case Histogram: |
|
|
|
|
{ |
|
|
|
|
const int mHistSizeNum = 25; |
|
|
|
|
const int channels[3][1] = {{0}, {1}, {2}}; |
|
|
|
|
const int mHistSize[] = {25}; |
|
|
|
|
const float baseRabge[] = {0.f,256.f}; |
|
|
|
|
const float* ranges[] = {baseRabge}; |
|
|
|
|
const cv::Scalar mColorsRGB[] = { cv::Scalar(200, 0, 0, 255), cv::Scalar(0, 200, 0, 255), |
|
|
|
|
cv::Scalar(0, 0, 200, 255) }; |
|
|
|
|
|
|
|
|
|
cv::Mat BgrFrame; |
|
|
|
|
cv::cvtColor(InputFrame, BgrFrame, cv::COLOR_YUV420sp2BGR); |
|
|
|
|
int thikness = (int) (BgrFrame.cols / (mHistSizeNum + 10) / 5); |
|
|
|
|
if(thikness > 5) thikness = 5; |
|
|
|
|
int offset = (int) ((BgrFrame.cols - (5*mHistSizeNum + 4*10)*thikness)/2); |
|
|
|
|
|
|
|
|
|
// RGB
|
|
|
|
|
for (int c=0; c<3; c++) |
|
|
|
|
{ |
|
|
|
|
std::vector<int> hist; |
|
|
|
|
cv::calcHist(&BgrFrame, 1, channels[c], cv::Mat(), hist, 1, mHistSize, ranges); |
|
|
|
|
cv::normalize(hist, hist, BgrFrame.rows/2, 0, cv::NORM_INF); |
|
|
|
|
for(int h=0; h<mHistSizeNum; h++) { |
|
|
|
|
cv::Point mP1, mP2; |
|
|
|
|
mP1.x = mP2.x = offset + (c * (mHistSizeNum + 10) + h) * thikness; |
|
|
|
|
mP1.y = BgrFrame.rows-1; |
|
|
|
|
mP2.y = mP1.y - 2 - (int)hist[h]; |
|
|
|
|
cv::line(BgrFrame, mP1, mP2, mColorsRGB[c], thikness); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cv::cvtColor(BgrFrame, OutputFrame, cv::COLOR_BGR2YUV_I420); |
|
|
|
|
} break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Set the data size on the output buffer.
|
|
|
|
|
hr = pOut->SetCurrentLength(m_cbImageSize); |
|
|
|
@ -1461,7 +1520,7 @@ HRESULT CGrayscale::UpdateFormatInfo() |
|
|
|
|
{ |
|
|
|
|
goto done; |
|
|
|
|
} |
|
|
|
|
if (subtype != MFVideoFormat_NV12) |
|
|
|
|
if (subtype != MFVideoFormat_NV12) |
|
|
|
|
{ |
|
|
|
|
hr = E_UNEXPECTED; |
|
|
|
|
goto done; |
|
|
|
|