- Error-prone mistakes:
- Do never use std::mutex.lock and/or std::mutex.unlock. Use std::unique_lockstd::mutex if unlock required or std::lock_guardstd::mutex otherwise.
- Do never use the new keyword with std::shared_ptr, but rather: std::make_shared<>.
- Naming:
- Class parameters should start with
m
, class pointers withp
, shared_ptrs withsp
, unique_ptrs withup
, static parameters withs
. - Function and class parameters coding style is the same other than the previous point.
- Any parameters should not contain special characters, simply letters and numbers (preferred only letters) separated with upper case. E.g.,
mThisIsAParameter
,thisIsAParameter
. - In addition, the names should be self-explanatory and not abbreviated. Good examples:
counter
,thisIs
. Bad examples:ctr
,var
.
- Class parameters should start with
- Length:
- Lines should contain up to 120 characters.
- Comments:
- Only
//
comments are allowed in the code,/* */
should not be used. - There should be a (at least) 1-line comment for each block of code inside each function.
- Only
- Loops and statements:
- There should be a space between the keyword (
if
,for
, etc) and the parenthesis, e.g.,if (true)
. Wrong:if(true)
. Note: So they can be easily located with Ctrl + F. - Braces should be added in the following line with respect to the loop/statement keyword. See example in point 3.
- 1-line loops/statements should not contain braces. E.g.,
- There should be a space between the keyword (
if (booleanParameter)
anotherParameter = 25;
else
{
anotherParameter = 2;
differentParameter = 3;
}
- Includes:
- There cannot be any include to a 3rd party in the headers (other than OpenCV core:
opencv2/core/core.hpp
).- PImpl idiom can be checked (e.g., in
include/openpose/pose/poseExtractorCaffe.hpp
) for an idea of how to avoid it. - Otherwise the defining class examples in
include/openpose/core/macros.hpp
(point 1 is highly preferred).
- PImpl idiom can be checked (e.g., in
- They should be sorted in this order:
- Std libraries.
- OS libraries.
- 3rd party libraries (e.g., Caffe, OpenCV).
- OpenPose libraries.
- If it is a cpp file, the last one should be its own hpp.
- Inside each of the previous groups, it should be sorted alphabetically.
- There cannot be any include to a 3rd party in the headers (other than OpenCV core:
- Functions arguments:
- It should first include the variables to be edited, and secondly the const variables.
- Any variable that is not gonna be modified must be added with
const
.
- Pointers:
- Pointers must be avoided if possible.
- If a pointer must be used, std::unique_ptr must be always be used.
- If the pointer must be shared, then std::shared_ptr.
- No
delete
keyword is allowed in OpenPose.
This is the faster method to debug a segmentation fault problem. Usual scenario: You are editing OpenPose source code and suddenly OpenPose returns segmentation fault when executed. In order to find where it occurs:
1. Select one of the 2 options:
1. Switch to debug mode.
2. Go to `openpose/utilities/errorAndLog.hpp` and modify `dLog`:
1. Comment `#ifndef NDEBUG` and its else and endif.
2. Call OpenPose with `--logging_level 0 --disable_multi_thread`.
3. At this point you have an idea of in which file class the segmentation fault is coming from. Now you can further isolate the error by iteratively adding the following line all over the code until you find the exact position of the segmentation fault: `opLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);`
4. After you have found the segmentation fault, remember to remove all the extra `opLog()` calls that you temporarily added.
- Enable
PROFILER_ENABLED
with CMake or in theMakefile.config
file. - By default, it should print out average runtime info after 1000 frames. You can change this number with
--profile_speed
, e.g.,--profile_speed 100
.
- Download OpenPose training code: https://github.com/CMU-Perceptual-Computing-Lab/openpose_train
- Download val2017 set from COCO: http://images.cocodataset.org/zips/val2017.zip
- Get JSONs in OpenPose: examples/tests/pose_accuracy_coco_val.sh
- Get accuracy (Matlab): validation/f_getValidations.m
From the COCO dataset:
- Download 2014 or 2017 Train/Val annotations.
- Download the COCO API.
- With the COCO API (either Python, Matlab, or LUA ones), you can check any image with the image ID (equivalent to the number in the image name).