Skip to content

Commit

Permalink
Merge pull request #83 from cd-athena/dev
Browse files Browse the repository at this point in the history
Merge dev to stable
  • Loading branch information
vigneshvijay94 authored Mar 11, 2024
2 parents 13a42e7 + 44111d3 commit 1283f1f
Show file tree
Hide file tree
Showing 51 changed files with 1,044 additions and 176 deletions.
14 changes: 13 additions & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,19 @@
- `--no-simd`

VCA will use all detected CPU SIMD architectures by default. This will disable that detection.


- `--no-dctenergy`

Disable analysis of DCT-energy-based features (which is enabled by default).

- `--no-entropy`

Disable analysis of entropy-based features (which is enabled by default).

- `--no-edgedensity`

Disable analysis of edge density (which is enabled by default).

- `--threads <integer>`

Specify the number of threads to use. Default: 0 (autodetect).
Expand Down
59 changes: 41 additions & 18 deletions source/apps/common/stats/YUViewStatsFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,54 @@ YUViewStatsFile::YUViewStatsFile(const std::string &filename,
this->file << "%;defaultRange;0;3000;heat\n"s;
}

void YUViewStatsFile::write(const vca_frame_results &results, unsigned blockSize)
void YUViewStatsFile::write(const vca_frame_results &results,
unsigned blockSize,
bool enableDCTenergy,
bool enableEntropy)
{
auto widthInBlocks = (info.width + blockSize - 1) / blockSize;
auto heightInBlock = (info.height + blockSize - 1) / blockSize;

if (auto data = results.brightnessPerBlock)
if (enableDCTenergy)
{
for (unsigned y = 0; y < heightInBlock; y++)
for (unsigned x = 0; x < widthInBlocks; x++)
this->file << results.poc << ";" << x * blockSize << ";" << y * blockSize << ";"
<< blockSize << ";" << blockSize << ";0;" << *(data++) << "\n";
if (auto data = results.brightnessPerBlock)
{
for (unsigned y = 0; y < heightInBlock; y++)
for (unsigned x = 0; x < widthInBlocks; x++)
this->file << results.poc << ";" << x * blockSize << ";" << y * blockSize << ";"
<< blockSize << ";" << blockSize << ";0;" << *(data++) << "\n";
}
if (auto data = results.energyPerBlock)
{
for (unsigned y = 0; y < heightInBlock; y++)
for (unsigned x = 0; x < widthInBlocks; x++)
this->file << results.poc << ";" << x * blockSize << ";" << y * blockSize << ";"
<< blockSize << ";" << blockSize << ";1;" << *(data++) << "\n";
}
if (auto data = results.energyDiffPerBlock)
{
for (unsigned y = 0; y < heightInBlock; y++)
for (unsigned x = 0; x < widthInBlocks; x++)
this->file << results.poc << ";" << x * blockSize << ";" << y * blockSize << ";"
<< blockSize << ";" << blockSize << ";2;" << *(data++) << "\n";
}
}
if (auto data = results.energyPerBlock)
if (enableEntropy)
{
for (unsigned y = 0; y < heightInBlock; y++)
for (unsigned x = 0; x < widthInBlocks; x++)
this->file << results.poc << ";" << x * blockSize << ";" << y * blockSize << ";"
<< blockSize << ";" << blockSize << ";1;" << *(data++) << "\n";
}
if (auto data = results.sadPerBlock)
{
for (unsigned y = 0; y < heightInBlock; y++)
for (unsigned x = 0; x < widthInBlocks; x++)
this->file << results.poc << ";" << x * blockSize << ";" << y * blockSize << ";"
<< blockSize << ";" << blockSize << ";2;" << *(data++) << "\n";
if (auto data = results.entropyPerBlock)
{
for (unsigned y = 0; y < heightInBlock; y++)
for (unsigned x = 0; x < widthInBlocks; x++)
this->file << results.poc << ";" << x * blockSize << ";" << y * blockSize << ";"
<< blockSize << ";" << blockSize << ";1;" << *(data++) << "\n";
}
if (auto data = results.entropyDiffPerBlock)
{
for (unsigned y = 0; y < heightInBlock; y++)
for (unsigned x = 0; x < widthInBlocks; x++)
this->file << results.poc << ";" << x * blockSize << ";" << y * blockSize << ";"
<< blockSize << ";" << blockSize << ";2;" << *(data++) << "\n";
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion source/apps/common/stats/YUViewStatsFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class YUViewStatsFile
const vca_frame_info &info);
~YUViewStatsFile() = default;

void write(const vca_frame_results &results, unsigned blockSize);
void write(const vca_frame_results &results,
unsigned blockSize,
bool enableDCTenergy,
bool enableEntropy);

private:
std::ofstream file;
Expand Down
156 changes: 119 additions & 37 deletions source/apps/vca/vca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct Result
this->energyPerBlockData.resize(numberBlocks);
this->result.energyPerBlock = this->energyPerBlockData.data();
this->sadPerBlockData.resize(numberBlocks);
this->result.sadPerBlock = this->sadPerBlockData.data();
this->result.energyDiffPerBlock = this->sadPerBlockData.data();
}

std::vector<uint32_t> brightnessPerBlockData;
Expand Down Expand Up @@ -200,10 +200,18 @@ std::optional<CLIOptions> parseCLIOptions(int argc, char **argv)
options.vcaParam.enableSIMD = false;
options.vcaParam.cpuSimd = CpuSimd::None;
}
else if (name == "no-chroma")
options.vcaParam.enableChroma = false;
else if (name == "no-energy-chroma")
options.vcaParam.enableEnergyChroma = false;
else if (name == "no-entropy-chroma")
options.vcaParam.enableEntropyChroma = false;
else if (name == "no-lowpass")
options.vcaParam.enableLowpassDCT = false;
options.vcaParam.enableLowpass = false;
else if (name == "no-dctenergy")
options.vcaParam.enableDCTenergy = false;
else if (name == "no-entropy")
options.vcaParam.enableEntropy = false;
else if (name == "no-edgedensity")
options.vcaParam.enableEdgeDensity = false;
else if (name == "y4m")
options.openAsY4m = true;
else
Expand Down Expand Up @@ -302,6 +310,11 @@ bool checkOptions(CLIOptions options)
return false;
}

if (!options.vcaParam.enableDCTenergy && !options.vcaParam.enableEntropy && !options.vcaParam.enableEdgeDensity)
{
vca_log(LogLevel::Error, " Either DCT energy or entropy or edge density calculation should be enabled ");
return false;
}
return true;
}

Expand All @@ -313,9 +326,17 @@ void logOptions(const CLIOptions &options)
vca_log(LogLevel::Info,
" Enable SIMD: "s + (options.vcaParam.enableSIMD ? "True"s : "False"s));
vca_log(LogLevel::Info,
" Enable chroma: "s + (options.vcaParam.enableChroma ? "True"s : "False"s));
" Enable DCT energy chroma: "s + (options.vcaParam.enableEnergyChroma ? "True"s : "False"s));
vca_log(LogLevel::Info,
" Enable entropy chroma: "s + (options.vcaParam.enableEntropyChroma ? "True"s : "False"s));
vca_log(LogLevel::Info,
" Enable lowpass: "s + (options.vcaParam.enableLowpass ? "True"s : "False"s));
vca_log(LogLevel::Info,
" Enable DCTenergy: "s + (options.vcaParam.enableDCTenergy ? "True"s : "False"s));
vca_log(LogLevel::Info,
" Enable lowpassDCT: "s + (options.vcaParam.enableLowpassDCT ? "True"s : "False"s));
" Enable Entropy: "s + (options.vcaParam.enableEntropy ? "True"s : "False"s));
vca_log(LogLevel::Info,
" Enable Edge density: "s + (options.vcaParam.enableEdgeDensity ? "True"s : "False"s));
vca_log(LogLevel::Info, " Skip frames: "s + std::to_string(options.skipFrames));
vca_log(LogLevel::Info, " Frames to analyze: "s + std::to_string(options.framesToBeAnalyzed));
vca_log(LogLevel::Info, " Segment Size: "s + std::to_string(options.segmentSize));
Expand All @@ -342,18 +363,38 @@ void logResult(const Result &result, const vca_frame *frame, const unsigned resu
"Got results POC " + std::to_string(result.result.poc) + "averageBrightness "
+ std::to_string(result.result.averageBrightness) + " averageEnergy "
+ std::to_string(result.result.averageEnergy) + " sad "
+ std::to_string(result.result.sad));
+ std::to_string(result.result.energyDiff));
}

void writeComplexityStatsToFile(const Result &result, std::ofstream &file, bool enableChroma)
void writeComplexityStatsToFile(const Result &result,
std::ofstream &file,
bool enableEnergyChroma,
bool enableEntropyChroma,
bool enableDCTenergy,
bool enableEntropy,
bool enableEdgeDensity)
{
file << result.result.poc << ", " << result.result.averageEnergy << ", " << result.result.sad
<< ", " << result.result.epsilon << ", " << result.result.averageBrightness;
if (enableChroma)
file << ", " << result.result.averageU << ", " << result.result.energyU << ", "
<< result.result.averageV << ", " << result.result.energyV << "\n";
else
file << "\n";
file << result.result.poc;
if (enableDCTenergy)
{
file << "," << result.result.averageEnergy << "," << result.result.energyDiff << ","
<< result.result.energyEpsilon << ", " << result.result.averageBrightness;
if (enableEnergyChroma)
file << "," << result.result.averageU << "," << result.result.energyU << ","
<< result.result.averageV << "," << result.result.energyV;
}
if (enableEntropy)
{
file << "," << result.result.averageEntropy << "," << result.result.entropyDiff << ","
<<result.result.entropyEpsilon;
if (enableEntropyChroma)
file << "," << result.result.entropyU << "," << result.result.entropyV;
}
if (enableEdgeDensity)
{
file << "," << result.result.averageEdgeDensity;
}
file << "\n";
}

void writeShotDetectionResultsToFile(const std::vector<vca_frame_results> &shotDetectFrames,
Expand Down Expand Up @@ -404,12 +445,12 @@ void writeShotDetectionResultsToFile(const std::vector<vca_frame_results> &shotD
}
averageValuesShot->brightness += frame.averageBrightness;
averageValuesShot->energy += frame.averageEnergy;
averageValuesShot->sad += frame.sad;
averageValuesShot->sad += frame.energyDiff;
averageValuesShot->u += frame.averageU;
averageValuesShot->v += frame.averageV;
averageValuesShot->energyU += frame.energyU;
averageValuesShot->energyV += frame.energyV;
averageValuesShot->epsilon += frame.epsilon;
averageValuesShot->epsilon += frame.energyEpsilon;
averageValuesShot->nrFramesInAverage++;
}

Expand All @@ -420,9 +461,9 @@ void writeShotDetectionResultsToFile(const std::vector<vca_frame_results> &shotD
void segment_result_init(Result *segment_result)
{
segment_result->result.averageBrightness = 0;
segment_result->result.sad = 0;
segment_result->result.energyDiff = 0;
segment_result->result.averageEnergy = 0;
segment_result->result.epsilon = 0;
segment_result->result.energyEpsilon = 0;
segment_result->result.poc = 0;
segment_result->result.averageU = 0;
segment_result->result.energyU = 0;
Expand All @@ -438,9 +479,9 @@ void segment_complexity_function(vca_frame_results *segment_result,
unsigned resultsCounter)
{
segment_result->averageBrightness += frame_result->averageBrightness;
segment_result->sad += frame_result->sad;
segment_result->energyDiff += frame_result->energyDiff;
segment_result->averageEnergy += frame_result->averageEnergy;
segment_result->epsilon += frame_result->epsilon;
segment_result->energyEpsilon += frame_result->energyEpsilon;
if (chroma_flag)
{
segment_result->averageU += frame_result->averageU;
Expand All @@ -454,8 +495,8 @@ void segment_complexity_function(vca_frame_results *segment_result,
{
segment_result->averageBrightness = (segment_result->averageBrightness / Segment_size);
segment_result->averageEnergy = (segment_result->averageEnergy / Segment_size);
segment_result->sad = (segment_result->sad / Segment_size);
segment_result->epsilon = (segment_result->epsilon / Segment_size);
segment_result->energyDiff = (segment_result->energyDiff / Segment_size);
segment_result->energyEpsilon = (segment_result->energyEpsilon / Segment_size);
if (resultsCounter == (pushedFrames - 1))
segment_result->poc = pushedFrames;
else
Expand Down Expand Up @@ -563,11 +604,24 @@ int main(int argc, char **argv)
"Error opening complexity CSV file " + options.complexityCSVFilename);
return 1;
}
complexityFile << "POC,E,h,epsilon,L";
if (options.vcaParam.enableChroma)
complexityFile << ", avgU, energyU, avgV, energyV\n ";
else
complexityFile << "\n";
complexityFile << "POC";
if (options.vcaParam.enableDCTenergy)
{
complexityFile << ",E,h,epsilon,L";
if (options.vcaParam.enableEnergyChroma)
complexityFile << ",avgU,energyU,avgV,energyV";
}
if (options.vcaParam.enableEntropy)
{
complexityFile << ",entropy,entropyDiff, entropyEpsilon";
if (options.vcaParam.enableEntropyChroma)
complexityFile << ",entropyU,entropyV";
}
if (options.vcaParam.enableEdgeDensity)
{
complexityFile << ",edgeDensity";
}
complexityFile << "\n";
}

std::ofstream segmentFeatureFile;
Expand All @@ -581,7 +635,7 @@ int main(int argc, char **argv)
return 1;
}
segmentFeatureFile << "POC,E,h,epsilon,L";
if (options.vcaParam.enableChroma)
if (options.vcaParam.enableEnergyChroma)
segmentFeatureFile << ", avgU, energyU, avgV, energyV \n ";
else
segmentFeatureFile << "\n";
Expand Down Expand Up @@ -704,21 +758,36 @@ int main(int argc, char **argv)
segment_complexity_function(&segment_result.result,
&result.result,
Segment_size,
options.vcaParam.enableChroma,
options.vcaParam.enableEnergyChroma,
pushedFrames,
resultsCounter);

if (((result.result.poc) % Segment_size == 0) && !(result.result.poc == 0))
{
writeComplexityStatsToFile(segment_result, segmentFeatureFile, options.vcaParam.enableChroma);
writeComplexityStatsToFile(segment_result,
segmentFeatureFile,
options.vcaParam.enableEnergyChroma,
options.vcaParam.enableEntropyChroma,
options.vcaParam.enableDCTenergy,
options.vcaParam.enableEntropy,
options.vcaParam.enableEdgeDensity);
segment_result_init(&segment_result);
}
}

if (yuviewStatsFile)
yuviewStatsFile->write(result.result, options.vcaParam.blockSize);
yuviewStatsFile->write(result.result,
options.vcaParam.blockSize,
options.vcaParam.enableDCTenergy,
options.vcaParam.enableEntropy);
if (complexityFile.is_open())
writeComplexityStatsToFile(result, complexityFile, options.vcaParam.enableChroma);
writeComplexityStatsToFile(result,
complexityFile,
options.vcaParam.enableEnergyChroma,
options.vcaParam.enableEntropyChroma,
options.vcaParam.enableDCTenergy,
options.vcaParam.enableEntropy,
options.vcaParam.enableEdgeDensity);
if (!options.shotCSVFilename.empty())
shotDetectFrames.push_back(result.result);

Expand Down Expand Up @@ -749,21 +818,34 @@ int main(int argc, char **argv)
segment_complexity_function(&segment_result.result,
&result.result,
Segment_size,
options.vcaParam.enableChroma,
options.vcaParam.enableEnergyChroma,
pushedFrames, resultsCounter);

if (resultsCounter == (pushedFrames - 1))
{
writeComplexityStatsToFile(segment_result,
segmentFeatureFile,
options.vcaParam.enableChroma);
options.vcaParam.enableEnergyChroma,
options.vcaParam.enableEntropyChroma,
options.vcaParam.enableDCTenergy,
options.vcaParam.enableEntropy,
options.vcaParam.enableEdgeDensity);
segment_result_init(&segment_result);
}
}
if (yuviewStatsFile)
yuviewStatsFile->write(result.result, options.vcaParam.blockSize);
yuviewStatsFile->write(result.result,
options.vcaParam.blockSize,
options.vcaParam.enableDCTenergy,
options.vcaParam.enableEntropy);
if (complexityFile.is_open())
writeComplexityStatsToFile(result, complexityFile, options.vcaParam.enableChroma);
writeComplexityStatsToFile(result,
complexityFile,
options.vcaParam.enableEnergyChroma,
options.vcaParam.enableEntropyChroma,
options.vcaParam.enableDCTenergy,
options.vcaParam.enableEntropy,
options.vcaParam.enableEdgeDensity);
if (!options.shotCSVFilename.empty())
shotDetectFrames.push_back(result.result);

Expand Down
Loading

0 comments on commit 1283f1f

Please sign in to comment.