Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatible with opencv 4.2.0 #568

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# IAI Kinect2
# IAI Kinect2 for OpenCV 4

## Maintainer
### Maintainer of this fork
- [Shuvo Kumar Paul](https://github.com/paul-shuvo)
Email: [email protected]

### Maintainer of IAI Kinect2

- [Thiemo Wiedemeyer](https://ai.uni-bremen.de/team/thiemo_wiedemeyer) <<[email protected]>>, [Institute for Artificial Intelligence](http://ai.uni-bremen.de/), University of Bremen

## Read this first
## :warning: Read this first

> __This repository contains some minor changes from the original [iai_kinect2](https://github.com/code-iai/iai_kinect2) repo. Building from the original repo throws errors if you are using opencv4. This repo fixes those issues; also, if you're using any opencv version other than 4, please build from the original [repo](https://github.com/code-iai/iai_kinect2). For any difficulties open an [issue](https://github.com/paul-shuvo/iai_kinect2_opencv4/issues).__

Please read this README and the ones of the individual components throughly before asking questions. We get a lot of repeated questions, so when you have a problem, we urge everyone to check the [github issues (including closed ones)](https://github.com/code-iai/iai_kinect2/issues?utf8=%E2%9C%93&q=is%3Aissue). Your issue is very likely discussed there already.

Expand Down Expand Up @@ -121,16 +127,21 @@ If you found no solution in the issues, feel free to open a new issue for your p

## Dependencies

- ROS Hydro/Indigo
- OpenCV (2.4.x, using the one from the official Ubuntu repositories is recommended)
- ROS Indigo/Jade/Melodic/Noetic
- OpenCV (4.x.x, using the one from the official Ubuntu repositories is recommended)
- PCL (1.7.x, using the one from the official Ubuntu repositories is recommended)
- Eigen (optional, but recommended)
- OpenCL (optional, but recommended)
- [libfreenect2](https://github.com/OpenKinect/libfreenect2) (>= v0.2.0, for stability checkout the latest stable release)


## Install

1. Install the ROS. [Instructions for Ubuntu 14.04](http://wiki.ros.org/indigo/Installation/Ubuntu)
1. Install the ROS.
- [Instructions for Ubuntu 14.04](http://wiki.ros.org/indigo/Installation/Ubuntu)
- [Instructions for Ubuntu 16.04](http://wiki.ros.org/lunar/Installation/Ubuntu)
- [Instructions for Ubuntu 18.04](http://wiki.ros.org/melodic/Installation/Ubuntu)
- [Instructions for Ubuntu 20.04](http://wiki.ros.org/noetic/Installation/Ubuntu)
2. [Setup your ROS environment](http://wiki.ros.org/ROS/Tutorials/InstallingandConfiguringROSEnvironment)
3. Install [libfreenect2](https://github.com/OpenKinect/libfreenect2):

Expand All @@ -142,13 +153,16 @@ If you found no solution in the issues, feel free to open a new issue for your p

```bash
cd ~/catkin_ws/src/
git clone https://github.com/code-iai/iai_kinect2.git
git clone https://github.com/paul-shuvo/iai_kinect2_opencv4.git
cd iai_kinect2
rosdep install -r --from-paths .
cd ~/catkin_ws
catkin_make -DCMAKE_BUILD_TYPE="Release"
```

> If you get the following error `pcl_conversions build error: PCL requires C++14 or above`, go to your `CMakeLists.txt` in the `src` folder and add the line `set( CMAKE_CXX_STANDARD 14)`
on the very top and rebuild.

*Note: `rosdep` will output errors on not being able to locate `[kinect2_bridge]` and `[depth_registration]`.
That is fine because they are all part of the iai_kinect2 package and `rosdep` does not know these packages.*

Expand Down
24 changes: 12 additions & 12 deletions kinect2_bridge/src/kinect2_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,12 @@ class Kinect2Bridge
void initCompression(const int32_t jpegQuality, const int32_t pngLevel, const bool use_png)
{
compressionParams.resize(7, 0);
compressionParams[0] = CV_IMWRITE_JPEG_QUALITY;
compressionParams[0] = cv::IMWRITE_JPEG_QUALITY;
compressionParams[1] = jpegQuality;
compressionParams[2] = CV_IMWRITE_PNG_COMPRESSION;
compressionParams[2] = cv::IMWRITE_PNG_COMPRESSION;
compressionParams[3] = pngLevel;
compressionParams[4] = CV_IMWRITE_PNG_STRATEGY;
compressionParams[5] = CV_IMWRITE_PNG_STRATEGY_RLE;
compressionParams[4] = cv::IMWRITE_PNG_STRATEGY;
compressionParams[5] = cv::IMWRITE_PNG_STRATEGY_RLE;
compressionParams[6] = 0;

if(use_png)
Expand Down Expand Up @@ -1100,11 +1100,11 @@ class Kinect2Bridge
cv::flip(color, tmp, 1);
if(colorFrame->format == libfreenect2::Frame::BGRX)
{
cv::cvtColor(tmp, images[COLOR_HD], CV_BGRA2BGR);
cv::cvtColor(tmp, images[COLOR_HD], cv::COLOR_BGRA2BGR);
}
else
{
cv::cvtColor(tmp, images[COLOR_HD], CV_RGBA2BGR);
cv::cvtColor(tmp, images[COLOR_HD], cv::COLOR_RGBA2BGR);
}
}

Expand Down Expand Up @@ -1180,11 +1180,11 @@ class Kinect2Bridge
cv::flip(cv::Mat(sizeIr, CV_8UC4, registered.data), tmp, 1);
if(color.format == libfreenect2::Frame::BGRX)
{
cv::cvtColor(tmp, images[COLOR_SD_RECT], CV_BGRA2BGR);
cv::cvtColor(tmp, images[COLOR_SD_RECT], cv::COLOR_BGRA2BGR);
}
else
{
cv::cvtColor(tmp, images[COLOR_SD_RECT], CV_RGBA2BGR);
cv::cvtColor(tmp, images[COLOR_SD_RECT], cv::COLOR_RGBA2BGR);
}
}

Expand Down Expand Up @@ -1247,19 +1247,19 @@ class Kinect2Bridge
// MONO
if(status[MONO_HD])
{
cv::cvtColor(images[COLOR_HD], images[MONO_HD], CV_BGR2GRAY);
cv::cvtColor(images[COLOR_HD], images[MONO_HD], cv::COLOR_BGR2GRAY);
}
if(status[MONO_HD_RECT])
{
cv::cvtColor(images[COLOR_HD_RECT], images[MONO_HD_RECT], CV_BGR2GRAY);
cv::cvtColor(images[COLOR_HD_RECT], images[MONO_HD_RECT], cv::COLOR_BGR2GRAY);
}
if(status[MONO_QHD])
{
cv::cvtColor(images[COLOR_QHD], images[MONO_QHD], CV_BGR2GRAY);
cv::cvtColor(images[COLOR_QHD], images[MONO_QHD], cv::COLOR_BGR2GRAY);
}
if(status[MONO_QHD_RECT])
{
cv::cvtColor(images[COLOR_QHD_RECT], images[MONO_QHD_RECT], CV_BGR2GRAY);
cv::cvtColor(images[COLOR_QHD_RECT], images[MONO_QHD_RECT], cv::COLOR_BGR2GRAY);
}
}

Expand Down
6 changes: 3 additions & 3 deletions kinect2_calibration/src/kinect2_calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Recorder
circleFlags = cv::CALIB_CB_ASYMMETRIC_GRID + cv::CALIB_CB_CLUSTERING;
}

params.push_back(CV_IMWRITE_PNG_COMPRESSION);
params.push_back(cv::IMWRITE_PNG_COMPRESSION);
params.push_back(9);

board.resize(boardDims.width * boardDims.height);
Expand Down Expand Up @@ -743,7 +743,7 @@ class CameraCalibration
#if CV_MAJOR_VERSION == 2
error = cv::stereoCalibrate(pointsBoard, pointsIr, pointsColor, cameraMatrixIr, distortionIr, cameraMatrixColor, distortionColor, sizeColor,
rotation, translation, essential, fundamental, termCriteria, cv::CALIB_FIX_INTRINSIC);
#elif CV_MAJOR_VERSION == 3
#elif CV_MAJOR_VERSION == 3 || CV_MAJOR_VERSION == 4
error = cv::stereoCalibrate(pointsBoard, pointsIr, pointsColor, cameraMatrixIr, distortionIr, cameraMatrixColor, distortionColor, sizeColor,
rotation, translation, essential, fundamental, cv::CALIB_FIX_INTRINSIC, termCriteria);
#endif
Expand Down Expand Up @@ -1091,7 +1091,7 @@ class DepthCalibration
//cv::solvePnP(board, points[index], cameraMatrix, distortion, rvec, translation, false, cv::EPNP);
#if CV_MAJOR_VERSION == 2
cv::solvePnPRansac(board, points[index], cameraMatrix, distortion, rvec, translation, false, 300, 0.05, board.size(), cv::noArray(), cv::ITERATIVE);
#elif CV_MAJOR_VERSION == 3
#elif CV_MAJOR_VERSION == 3 || CV_MAJOR_VERSION == 4
cv::solvePnPRansac(board, points[index], cameraMatrix, distortion, rvec, translation, false, 300, 0.05, 0.99, cv::noArray(), cv::SOLVEPNP_ITERATIVE);
#endif
cv::Rodrigues(rvec, rotation);
Expand Down
2 changes: 1 addition & 1 deletion kinect2_viewer/src/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class Receiver
combine(color, depthDisp, combined);
//combined = color;

cv::putText(combined, oss.str(), pos, font, sizeText, colorText, lineText, CV_AA);
cv::putText(combined, oss.str(), pos, font, sizeText, colorText, lineText, cv::LINE_AA);
cv::imshow("Image Viewer", combined);
}

Expand Down