提交 cc4082b4 编写于 作者: G gineshidalgo99

Last frame flag & googly eyes fixed, COCO & MPI render similar

上级 550be9a7
......@@ -33,8 +33,8 @@ namespace op
};
const unsigned int POSE_COCO_NUMBER_PARTS = 18u; // Equivalent to size of std::map POSE_COCO_BODY_PARTS - 1 (removing background)
const std::vector<unsigned int> POSE_COCO_MAP_IDX {31,32, 39,40, 33,34, 35,36, 41,42, 43,44, 19,20, 21,22, 23,24, 25,26, 27,28, 29,30, 47,48, 49,50, 53,54, 51,52, 55,56, 37,38, 45,46};
const std::vector<unsigned int> POSE_COCO_PAIRS {1,2, 1,5, 2,3, 3,4, 5,6, 6,7, 1,8, 8,9, 9,10, 1,11, 11,12, 12,13, 1,0, 0,14, 14,16, 0,15, 15,17, 2,16, 5,17};
#define POSE_COCO_PAIRS_TO_RENDER {1,2, 1,5, 2,3, 3,4, 5,6, 6,7, 1,8, 8,9, 9,10, 1,11, 11,12, 12,13, 1,0, 0,14, 14,16, 0,15, 15,17}
const std::vector<unsigned int> POSE_COCO_PAIRS {1,2, 1,5, 2,3, 3,4, 5,6, 6,7, 1,8, 8,9, 9,10, 1,11, 11,12, 12,13, 1,0, 0,14, 14,16, 0,15, 15,17, 2,16, 5,17};
const std::map<unsigned int, std::string> POSE_MPI_BODY_PARTS{
{0, "Head"},
......@@ -55,9 +55,9 @@ namespace op
{15, "Background"}
};
const unsigned int POSE_MPI_NUMBER_PARTS = 15; // Equivalent to size of std::map POSE_MPI_NUMBER_PARTS - 1 (removing background)
const std::vector<unsigned int> POSE_MPI_MAP_IDX {16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 38, 39, 40, 41, 42, 43, 32, 33, 34, 35, 36, 37};
const std::vector<unsigned int> POSE_MPI_PAIRS {0,1, 1,2, 2,3, 3,4, 1,5, 5,6, 6,7, 1,14, 14,11, 11,12, 12,13, 14,8, 8,9, 9,10};
#define POSE_MPI_PAIRS_TO_RENDER {0,1, 2,3, 3,4, 5,6, 6,7, 11,12, 12,13, 8,9, 9,10}
const std::vector<unsigned int> POSE_MPI_MAP_IDX {16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43};
#define POSE_MPI_PAIRS_TO_RENDER { 0,1, 1,2, 2,3, 3,4, 1,5, 5,6, 6,7, 1,14, 14,8, 8,9, 9,10, 14,11, 11,12, 12,13}
const std::vector<unsigned int> POSE_MPI_PAIRS POSE_MPI_PAIRS_TO_RENDER;
// Constant Global Parameters
const unsigned int POSE_MAX_PEOPLE = 96u;
......
......@@ -100,6 +100,9 @@ namespace op
// Check producer is running
if (!datumProducerRunning)
datums = nullptr;
// Increase counter if successful image
if (datums != nullptr)
mGlobalCounter++;
// Return result
return std::make_pair(datumProducerRunning, datums);
}
......
......@@ -5,14 +5,14 @@ namespace op
{
inline __device__ void renderKeyPoints(float* targetPtr, float2* sharedMaxs, float2* sharedMins, float* sharedScaleF,
const int globalIdx, const int x, const int y, const int targetWidth, const int targetHeight,
const float* const facePtr, const unsigned char* const partPairsPtr,
const int numberFaces, const int numberParts, const int numberPartPairs,
const float* const keypointsPtr, const unsigned char* const partPairsPtr,
const int numberPeople, const int numberParts, const int numberPartPairs,
const float* const rgbColorsPtr, const int numberColors,
const float radius, const float stickwidth, const float threshold, const float alphaColorToAdd,
const bool blendOriginalFrame = true)
const bool blendOriginalFrame = true, const int googlyEye1 = -1, const int googlyEye2 = -1)
{
// Fill shared parameters
if (globalIdx < numberFaces)
if (globalIdx < numberPeople)
{
sharedMins[globalIdx].x = targetWidth;
sharedMins[globalIdx].y = targetHeight;
......@@ -21,9 +21,9 @@ namespace op
for (auto part = 0 ; part < numberParts ; part++)
{
const auto index = 3 * (globalIdx*numberParts + part);
const auto x = facePtr[index];
const auto y = facePtr[index+1];
const auto score = facePtr[index+2];
const auto x = keypointsPtr[index];
const auto y = keypointsPtr[index+1];
const auto score = keypointsPtr[index+2];
if (score > threshold)
{
if (x < sharedMins[globalIdx].x)
......@@ -62,24 +62,24 @@ namespace op
r = 0.f;
}
for (auto person = 0; person < numberFaces; person++)
for (auto person = 0; person < numberPeople; person++)
{
if (x <= sharedMaxs[person].x && x >= sharedMins[person].x && y <= sharedMaxs[person].y && y >= sharedMins[person].y)
{
// Hand part connections
for (auto facePart = 0; facePart < numberPartPairs; facePart++)
for (auto partPair = 0; partPair < numberPartPairs; partPair++)
{
const auto bSqrt = sharedScaleF[person] * sharedScaleF[person] * stickwidth * stickwidth;
const auto partA = partPairsPtr[2*facePart];
const auto partB = partPairsPtr[2*facePart+1];
const auto partA = partPairsPtr[2*partPair];
const auto partB = partPairsPtr[2*partPair+1];
const auto indexA = person*numberParts*3 + partA*3;
const auto xA = facePtr[indexA];
const auto yA = facePtr[indexA + 1];
const auto scoreA = facePtr[indexA + 2];
const auto xA = keypointsPtr[indexA];
const auto yA = keypointsPtr[indexA + 1];
const auto scoreA = keypointsPtr[indexA + 2];
const auto indexB = person*numberParts*3 + partB*3;
const auto xB = facePtr[indexB];
const auto yB = facePtr[indexB + 1];
const auto scoreB = facePtr[indexB + 2];
const auto xB = keypointsPtr[indexB];
const auto yB = keypointsPtr[indexB + 1];
const auto scoreB = keypointsPtr[indexB + 2];
if (scoreA > threshold && scoreB > threshold)
{
......@@ -97,7 +97,7 @@ namespace op
const auto minV = 0.f;
const auto maxV = 1.f;
if (minV <= judge && judge <= maxV)
addColorWeighted(r, g, b, &rgbColorsPtr[(facePart%numberColors)*3], alphaColorToAdd);
addColorWeighted(r, g, b, &rgbColorsPtr[(partPair%numberColors)*3], alphaColorToAdd);
}
}
......@@ -105,17 +105,44 @@ namespace op
for (unsigned char i = 0; i < numberParts; i++)
{
const auto index = 3 * (person*numberParts + i);
const auto localX = facePtr[index];
const auto localY = facePtr[index + 1];
const auto score = facePtr[index + 2];
const auto localX = keypointsPtr[index];
const auto localY = keypointsPtr[index + 1];
const auto score = keypointsPtr[index + 2];
if (score > threshold)
{
const auto dist2 = (x - localX) * (x - localX) + (y - localY) * (y - localY);
const auto minr2 = 0.f;
const auto maxr2 = sharedScaleF[person]*sharedScaleF[person]*radius * radius;
if (minr2 <= dist2 && dist2 <= maxr2)
addColorWeighted(r, g, b, &rgbColorsPtr[(i%numberColors)*3], alphaColorToAdd);
// Googly eyes
if (googlyEye1 == i || googlyEye2 == i)
{
const auto ratio = 2.5f * radius;
const auto minr2 = sharedScaleF[person]*sharedScaleF[person] * (ratio - 2) * (ratio - 2);
const auto maxr2 = sharedScaleF[person]*sharedScaleF[person] * ratio * ratio;
if (dist2 <= maxr2)
{
float colorToAdd [3] = {0., 0., 0.};
if (dist2 <= minr2)
for (auto& color : colorToAdd)
color = {255.f};
if (dist2 <= minr2*0.6f)
{
const auto dist3 = (x-4 - localX) * (x-4 - localX) + (y - localY+4) * (y - localY+4);
if (dist3 > 3.75f*3.75f)
for (auto& color : colorToAdd)
color = {0.f};
}
const auto alphaColorToAdd = 0.9f;
addColorWeighted(r, g, b, colorToAdd, alphaColorToAdd);
}
}
// Other limbs
else
{
const auto minr2 = 0.f;
const auto maxr2 = sharedScaleF[person]*sharedScaleF[person]*radius * radius;
if (minr2 <= dist2 && dist2 <= maxr2)
addColorWeighted(r, g, b, &rgbColorsPtr[(i%numberColors)*3], alphaColorToAdd);
}
}
}
}
......
......@@ -32,16 +32,22 @@ namespace op
255.f, 0.f, 170.f,
255.f, 0.f, 85.f,
};
__constant__ const float MPI_RGB_COLORS[] = {
255.f, 0.f, 0.f,
255.f, 170.f, 0.f,
170.f, 255.f, 0.f,
0.f, 255.f, 0.f,
0.f, 255.f, 170.f,
170.f, 0.f, 255.f,
255.f, 0.f, 170.f,
0.f, 170.f, 255.f,
0.f, 0.f, 255.f,
__constant__ const float MPI_RGB_COLORS[] = { // MPI colors chosen such that they are closed to COCO colors
255.f, 0.f, 85.f,
255.f, 0.f, 0.f,
255.f, 85.f, 0.f,
255.f, 170.f, 0.f,
255.f, 255.f, 0.f,
170.f, 255.f, 0.f,
85.f, 255.f, 0.f,
43.f, 255.f, 0.f,
0.f, 255.f, 0.f,
0.f, 255.f, 85.f,
0.f, 255.f, 170.f,
0.f, 255.f, 255.f,
0.f, 170.f, 255.f,
0.f, 85.f, 255.f,
0.f, 0.f, 255.f,
};
__constant__ const float RGB_COLORS_BACKGROUND[] = {
255.f, 0.f, 0.f,
......@@ -165,87 +171,32 @@ namespace op
renderKeyPoints(targetPtr, sharedMaxs, sharedMins, sharedScaleF,
globalIdx, x, y, targetWidth, targetHeight, posePtr, COCO_PAIRS_GPU, numberPeople,
POSE_COCO_NUMBER_PARTS, numberPartPairs, COCO_RGB_COLORS, numberColors,
radius, stickwidth, threshold, alphaColorToAdd, blendOriginalFrame);
radius, stickwidth, threshold, alphaColorToAdd, blendOriginalFrame, (googlyEyes ? 14 : -1), (googlyEyes ? 15 : -1));
}
__global__ void renderPoseMpi29Parts(float* targetPtr, const int targetWidth, const int targetHeight, const float* const posePtr,
const int numberPeople, const float threshold, const bool blendOriginalFrame, const float alphaColorToAdd)
{
//posePtr has length 3 * 15 * numberPeople
const auto x = (blockIdx.x * blockDim.x) + threadIdx.x;
const auto y = (blockIdx.y * blockDim.y) + threadIdx.y;
const auto globalIdx = threadIdx.y * blockDim.x + threadIdx.x;
if (x < targetWidth && y < targetHeight)
{
const auto numberBodyParts = sizeof(MPI_PAIRS_GPU)/(2*sizeof(MPI_PAIRS_GPU[0]));
const auto radius = 3.f*targetHeight / 200.0f;
const auto stickwidth = targetHeight / 60.0f;
const auto blueIndex = y * targetWidth + x;
auto& b = targetPtr[ blueIndex];
auto& g = targetPtr[ targetWidth * targetHeight + blueIndex];
auto& r = targetPtr[2 * targetWidth * targetHeight + blueIndex];
if (!blendOriginalFrame)
{
b = 0.f;
g = 0.f;
r = 0.f;
}
// Shared parameters
__shared__ float2 sharedMins[POSE_MAX_PEOPLE];
__shared__ float2 sharedMaxs[POSE_MAX_PEOPLE];
__shared__ float sharedScaleF[POSE_MAX_PEOPLE];
for (auto person = 0; person < numberPeople; person++)
{
// Body part body part connections
for (auto bodyPart = 0; bodyPart < numberBodyParts; bodyPart++)
{
auto bSqrt = stickwidth * stickwidth; //fixed
const auto partA = MPI_PAIRS_GPU[2*bodyPart];
const auto partB = MPI_PAIRS_GPU[2*bodyPart+1];
const auto xA = posePtr[person*POSE_MPI_NUMBER_PARTS*3 + partA*3];
const auto yA = posePtr[person*POSE_MPI_NUMBER_PARTS*3 + partA*3 + 1];
const auto valueA = posePtr[person*POSE_MPI_NUMBER_PARTS*3 + partA*3 + 2];
const auto xB = posePtr[person*POSE_MPI_NUMBER_PARTS*3 + partB*3];
const auto yB = posePtr[person*POSE_MPI_NUMBER_PARTS*3 + partB*3 + 1];
const auto valueB = posePtr[person*POSE_MPI_NUMBER_PARTS*3 + partB*3 + 2];
if (valueA > threshold && valueB > threshold)
{
const auto xP = (xA + xB) / 2.f;
const auto yP = (yA + yB) / 2.f;
const auto angle = atan2f(yB - yA, xB - xA);
const auto sine = sinf(angle);
const auto cosine = cosf(angle);
auto aSqrt = (xA - xP) * (xA - xP) + (yA - yP) * (yA - yP);
if (bodyPart==0)
{
aSqrt *= 1.2f;
bSqrt = aSqrt;
}
const auto A = cosine * (x - xP) + sine * (y - yP);
const auto B = sine * (x - xP) - cosine * (y - yP);
const auto judge = A * A / aSqrt + B * B / bSqrt;
auto minV = 0.f;
if (bodyPart == 0)
minV = 0.8f;
if (judge>= minV && judge <= 1)
addColorWeighted(r, g, b, &MPI_RGB_COLORS[3*bodyPart], alphaColorToAdd);
}
}
// Other parameters
const auto numberPartPairs = sizeof(MPI_PAIRS_GPU) / (2*sizeof(MPI_PAIRS_GPU[0]));
const auto numberColors = sizeof(MPI_RGB_COLORS) / (3*sizeof(MPI_RGB_COLORS[0]));
const auto radius = fastMin(targetWidth, targetHeight) / 100.f;
const auto stickwidth = fastMin(targetWidth, targetHeight) / 120.f;
// Body part circles
for (unsigned char i = 0; i < POSE_MPI_NUMBER_PARTS; i++) //for every point
{
const auto index = 3 * (person*POSE_MPI_NUMBER_PARTS + i);
const auto localX = posePtr[index];
const auto localY = posePtr[index + 1];
const auto value = posePtr[index + 2];
if (value > threshold)
if ((x - localX) * (x - localX) + (y - localY) * (y - localY) <= radius * radius)
addColorWeighted(r, g, b, &MPI_RGB_COLORS[(i%9)*3], alphaColorToAdd);
}
}
}
// Render key points
renderKeyPoints(targetPtr, sharedMaxs, sharedMins, sharedScaleF,
globalIdx, x, y, targetWidth, targetHeight, posePtr, MPI_PAIRS_GPU, numberPeople,
POSE_MPI_NUMBER_PARTS, numberPartPairs, MPI_RGB_COLORS, numberColors,
radius, stickwidth, threshold, alphaColorToAdd, blendOriginalFrame);
}
__global__ void renderBodyPartHeatMaps(float* targetPtr, const int targetWidth, const int targetHeight, const float* const heatMapPtr, const int widthHeatMap,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册