paralleization wip

This commit is contained in:
2023-06-30 00:48:56 +02:00
parent f5dad284e6
commit b3c2d585ae
5 changed files with 230 additions and 237 deletions

View File

@ -11,38 +11,53 @@
bool SeamCarving::strechImage(cv::Mat& image, int seams, bool grow, std::vector<std::vector<int>>* seamsVect)
{
cv::Mat newFrame = image.clone();
assert(!newFrame.empty());
std::vector<std::vector<int>> vecSeams;
for(int i = 0; i < seams; i++)
{
Log(Log::DEBUG)<<"Seam "<<i<<" of "<<seams;
//Gradient Magnitude for intensity of image.
cv::Mat gradientMagnitude = computeGradientMagnitude(image);
cv::Mat gradientMagnitude = computeGradientMagnitude(newFrame);
//Use DP to create the real energy map that is used for path calculation.
// Strictly using vertical paths for testing simplicity.
cv::Mat pathIntensityMat = computePathIntensityMat(gradientMagnitude);
if(pathIntensityMat.rows == 0 && pathIntensityMat.cols == 0)
return false;
std::vector<int> seam = getLeastImportantPath(pathIntensityMat);
vecSeams.push_back(seam);
if(seamsVect)
seamsVect->push_back(seam);
if(!grow)
image = removeLeastImportantPath(image, seam);
else
image = addLeastImportantPath(image, seam);
newFrame = removeLeastImportantPath(newFrame, seam);
if(image.rows == 0 && image.cols == 0)
if(newFrame.rows == 0 || newFrame.cols == 0)
return false;
}
if (grow)
{
cv::Mat growMat = image.clone();
for(size_t i = 0; i < vecSeams.size(); i++)
{
growMat = addLeastImportantPath(growMat,vecSeams[i]);
}
image = growMat;
}
else
{
image = newFrame;
}
return true;
}
bool SeamCarving::strechImageVert(cv::Mat& image, int seams, bool grow, std::vector<std::vector<int>>* seamsVect)
{
image = image.t();
cv::transpose(image, image);
bool ret = strechImage(image, seams, grow, seamsVect);
image = image.t();
cv::transpose(image, image);
return ret;
}