Skip to content

Commit

Permalink
added smart resizing for input blob
Browse files Browse the repository at this point in the history
  • Loading branch information
vikasgupta-github committed Sep 27, 2018
1 parent 8b8496f commit 93b809d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
8 changes: 6 additions & 2 deletions HandPose/handPoseImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@ int main(int argc, char **argv)
imageFile = argv[1];
}

int inWidth = 368;
int inHeight = 368;
float thresh = 0.01;

Mat frame = imread(imageFile);
Mat frameCopy = frame.clone();
int frameWidth = frame.cols;
int frameHeight = frame.rows;

float aspect_ratio = frameWidth/(float)frameHeight;
int inHeight = 368;
int inWidth = (int(aspect_ratio*inHeight) * 8) / 8;

cout << "inWidth = " << inWidth << " ; inHeight = " << inHeight << endl;

double t = (double) cv::getTickCount();
Net net = readNetFromCaffe(protoFile, weightsFile);

Expand Down
12 changes: 5 additions & 7 deletions HandPose/handPoseImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
weightsFile = "hand/pose_iter_102000.caffemodel"
nPoints = 22
POSE_PAIRS = [ [0,1],[1,2],[2,3],[3,4],[0,5],[5,6],[6,7],[7,8],[0,9],[9,10],[10,11],[11,12],[0,13],[13,14],[14,15],[15,16],[0,17],[17,18],[18,19],[19,20] ]

net = cv2.dnn.readNetFromCaffe(protoFile, weightsFile)

frame = cv2.imread("hand.jpg")
frameCopy = np.copy(frame)
frameWidth = frame.shape[1]
frameHeight = frame.shape[0]
threshold = 0.1
aspect_ratio = frameWidth/frameHeight

net = cv2.dnn.readNetFromCaffe(protoFile, weightsFile)
threshold = 0.1

t = time.time()
# input image dimensions for the network
inWidth = 368
inHeight = 368
inWidth = int(((aspect_ratio*inHeight)*8)//8)

inpBlob = cv2.dnn.blobFromImage(frame, 1.0 / 255, (inWidth, inHeight),
(0, 0, 0), swapRB=False, crop=False)

Expand All @@ -28,9 +29,6 @@
output = net.forward()
print("time taken by network : {:.3f}".format(time.time() - t))

H = output.shape[2]
W = output.shape[3]

# Empty list to store the detected keypoints
points = []

Expand Down
7 changes: 5 additions & 2 deletions HandPose/handPoseVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ int nPoints = 22;

int main(int argc, char **argv)
{
int inWidth = 368;
int inHeight = 368;
float thresh = 0.01;

cv::VideoCapture cap(0);
Expand All @@ -38,6 +36,11 @@ int main(int argc, char **argv)
Mat frame, frameCopy;
int frameWidth = cap.get(CAP_PROP_FRAME_WIDTH);
int frameHeight = cap.get(CAP_PROP_FRAME_HEIGHT);
float aspect_ratio = frameWidth/(float)frameHeight;
int inHeight = 368;
int inWidth = (int(aspect_ratio*inHeight) * 8) / 8;

cout << "inWidth = " << inWidth << " ; inHeight = " << inHeight << endl;

VideoWriter video("Output-Skeleton.avi",VideoWriter::fourcc('M','J','P','G'), 10, Size(frameWidth,frameHeight));

Expand Down
13 changes: 8 additions & 5 deletions HandPose/handPoseVideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@
nPoints = 22
POSE_PAIRS = [ [0,1],[1,2],[2,3],[3,4],[0,5],[5,6],[6,7],[7,8],[0,9],[9,10],[10,11],[11,12],[0,13],[13,14],[14,15],[15,16],[0,17],[17,18],[18,19],[19,20] ]

inWidth = 368
inHeight = 368
threshold = 0.1


input_source = 0
cap = cv2.VideoCapture(input_source)
hasFrame, frame = cap.read()

frameWidth = frame.shape[1]
frameHeight = frame.shape[0]

aspect_ratio = frameWidth/frameHeight

inHeight = 368
inWidth = int(((aspect_ratio*inHeight)*8)//8)

vid_writer = cv2.VideoWriter('output.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 15, (frame.shape[1],frame.shape[0]))

net = cv2.dnn.readNetFromCaffe(protoFile, weightsFile)
Expand All @@ -32,9 +38,6 @@

print("imread = {}".format(time.time() - t))

frameWidth = frame.shape[1]
frameHeight = frame.shape[0]

inpBlob = cv2.dnn.blobFromImage(frame, 1.0 / 255, (inWidth, inHeight),
(0, 0, 0), swapRB=False, crop=False)

Expand Down

0 comments on commit 93b809d

Please sign in to comment.