Skip to content

Commit

Permalink
Merge pull request #1308 from gergondet/topic/FixUtilFocalBuild
Browse files Browse the repository at this point in the history
Fix util build on Ubuntu 20.04
  • Loading branch information
fkanehiro authored Nov 16, 2021
2 parents 606108c + c4453f5 commit bdbc4c8
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 70 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ pkg_check_modules(OpenCV opencv)
if (NOT OpenCV_FOUND)
pkg_check_modules(OpenCV opencv-2.3.1)
if (NOT OpenCV_FOUND)
message(WARNING "opencv not found")
pkg_check_modules(OpenCV opencv4)
if (NOT OpenCV_FOUND)
message(WARNING "opencv not found")
endif()
endif()
endif()
pkg_check_modules(GLEW glew)
Expand Down
9 changes: 7 additions & 2 deletions lib/util/GLsceneBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
#include <map>
#include <sys/time.h>
//Open CV header
#include <cv.h>
#include <highgui.h>
#include <opencv2/core/core_c.h>
#include <opencv2/highgui/highgui_c.h>
#ifndef CV_VERSION_EPOCH
#if CV_VERSION_MAJOR > 3
#include <opencv2/videoio/videoio_c.h>
#endif
#endif
#include <SDL/SDL_thread.h>
#include <hrpCorba/ModelLoader.hh>
#include <hrpModel/ConstraintForceSolver.h>
Expand Down
34 changes: 19 additions & 15 deletions rtc/CameraImageLoader/CameraImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
* $Id$
*/

#include <cv.h>
#include <highgui.h>
#ifndef CV_VERSION_EPOCH
#define CV_VERSION_EPOCH CV_VERSION_MAJOR
#endif
#if CV_VERSION_EPOCH > 3
#include <opencv2/imgcodecs/imgcodecs.hpp>
#else
#include <opencv2/highgui/highgui.hpp>
#endif
#include "CameraImageLoader.h"

// Module specification
Expand Down Expand Up @@ -116,26 +122,26 @@ RTC::ReturnCode_t CameraImageLoader::onExecute(RTC::UniqueId ec_id)
std::string filename;
std::cin >> filename;

IplImage *image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_COLOR);
if (!image) {
cv::Mat image = cv::imread(filename.c_str(), cv::IMREAD_COLOR);
if (image.empty()) {
std::cerr << m_profile.instance_name << ": failed to load("
<< filename << ")" << std::endl;
return RTC::RTC_OK;
}

m_image.data.image.width = image->width;
m_image.data.image.height = image->height;
m_image.data.image.raw_data.length(image->imageSize);
switch(image->nChannels){
m_image.data.image.width = image.size().width;
m_image.data.image.height = image.size().height;
m_image.data.image.raw_data.length(image.size().area());
switch(image.channels()){
case 3:
m_image.data.image.format = Img::CF_RGB;
{
// BGR -> RGB
char *src;
unsigned char *src;
unsigned char *dst = m_image.data.image.raw_data.get_buffer();
for (int i=0; i<image->height; i++){
for (int j=0; j<image->width; j++){
src = image->imageData + image->widthStep*i + j*3;
for (int i=0; i<image.size().height; i++){
for (int j=0; j<image.size().width; j++){
src = image.data + image.step * i + j * 3;
dst[2] = src[0];
dst[1] = src[1];
dst[0] = src[2];
Expand All @@ -147,15 +153,13 @@ RTC::ReturnCode_t CameraImageLoader::onExecute(RTC::UniqueId ec_id)
case 1:
m_image.data.image.format = Img::CF_GRAY;
memcpy(m_image.data.image.raw_data.get_buffer(),
image->imageData,
image.data,
m_image.data.image.raw_data.length());
break;
default:
break;
}

cvReleaseImage (&image);

m_imageOut.write();

return RTC::RTC_OK;
Expand Down
15 changes: 12 additions & 3 deletions rtc/CameraImageSaver/CameraImageSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
* $Id$
*/

#include <cv.h>
#include <highgui.h>
#include <opencv2/core/core_c.h>
#include <opencv2/highgui/highgui_c.h>
#ifndef CV_VERSION_EPOCH
#define CV_VERSION_EPOCH CV_VERSION_MAJOR
#endif
#if CV_VERSION_EPOCH > 3
#include <opencv2/imgcodecs/imgcodecs.hpp>
#else
#include <opencv2/highgui/highgui.hpp>
#endif
#include "CameraImageSaver.h"

// Module specification
Expand Down Expand Up @@ -158,7 +166,8 @@ RTC::ReturnCode_t CameraImageSaver::onExecute(RTC::UniqueId ec_id)

char fname[256];
sprintf(fname, "%s%04d.png", m_basename.c_str(), m_count++);
cvSaveImage(fname, cvImage);
cv::Mat image = cv::cvarrToMat(cvImage);
cv::imwrite(fname, image);

cvReleaseImage(&cvImage);
}
Expand Down
4 changes: 2 additions & 2 deletions rtc/CameraImageViewer/CameraImageViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include <rtm/DataOutPort.h>
#include <rtm/idl/BasicDataTypeSkel.h>
#include <rtm/idl/InterfaceDataTypesSkel.h>
#include <cv.h>
#include <highgui.h>
#include <opencv2/core/core_c.h>
#include <opencv2/highgui/highgui_c.h>

// Service implementation headers
// <rtc-template block="service_impl_h">
Expand Down
6 changes: 5 additions & 1 deletion rtc/ColorExtractor/ColorExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
* $Id$
*/

#include <highgui.h>
#include <opencv2/highgui/highgui_c.h>
#include <opencv2/imgproc/imgproc_c.h>
#ifndef CV_RGB
#define CV_RGB( r, g, b ) cvScalar( (b), (g), (r), 0 )
#endif
#include "ColorExtractor.h"
#include "hrpsys/util/VectorConvert.h"

Expand Down
2 changes: 1 addition & 1 deletion rtc/ColorExtractor/ColorExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <rtm/DataInPort.h>
#include <rtm/DataOutPort.h>
#include <rtm/idl/BasicDataTypeSkel.h>
#include <cv.h>
#include <opencv2/core/core_c.h>

// Service implementation headers
// <rtc-template block="service_impl_h">
Expand Down
6 changes: 6 additions & 0 deletions rtc/JpegDecoder/JpegDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#ifndef CV_VERSION_EPOCH
#define CV_VERSION_EPOCH CV_VERSION_MAJOR
#endif
#if CV_VERSION_EPOCH > 3
#include <opencv2/imgcodecs/legacy/constants_c.h>
#endif
#include "JpegDecoder.h"

// Module specification
Expand Down
6 changes: 6 additions & 0 deletions rtc/JpegEncoder/JpegEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#ifndef CV_VERSION_EPOCH
#define CV_VERSION_EPOCH CV_VERSION_MAJOR
#endif
#if CV_VERSION_EPOCH > 3
#include <opencv2/imgcodecs/legacy/constants_c.h>
#endif
#include "JpegEncoder.h"

// Module specification
Expand Down
1 change: 1 addition & 0 deletions rtc/RGB2Gray/RGB2Gray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/types_c.h>
#include "RGB2Gray.h"

// Module specification
Expand Down
4 changes: 2 additions & 2 deletions rtc/RangeDataViewer/RangeDataViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include <rtm/DataOutPort.h>
#include <rtm/idl/BasicDataTypeSkel.h>
#include <rtm/idl/InterfaceDataTypesSkel.h>
#include <cv.h>
#include <highgui.h>
#include <opencv2/core/core_c.h>
#include <opencv2/highgui/highgui_c.h>

// Service implementation headers
// <rtc-template block="service_impl_h">
Expand Down
3 changes: 2 additions & 1 deletion rtc/ResizeImage/ResizeImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* $Id$
*/

#include <highgui.h>
#include <opencv2/highgui/highgui_c.h>
#include <opencv2/imgproc/imgproc_c.h>
#include "ResizeImage.h"

// Module specification
Expand Down
2 changes: 1 addition & 1 deletion rtc/ResizeImage/ResizeImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <rtm/DataInPort.h>
#include <rtm/DataOutPort.h>
#include <rtm/idl/BasicDataTypeSkel.h>
#include <cv.h>
#include <opencv2/core/core_c.h>

// Service implementation headers
// <rtc-template block="service_impl_h">
Expand Down
3 changes: 2 additions & 1 deletion rtc/RotateImage/RotateImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* $Id$
*/

#include <highgui.h>
#include <opencv2/highgui/highgui_c.h>
#include <opencv2/imgproc/imgproc_c.h>
#include "RotateImage.h"

// Module specification
Expand Down
2 changes: 1 addition & 1 deletion rtc/RotateImage/RotateImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <rtm/DataInPort.h>
#include <rtm/DataOutPort.h>
#include <rtm/idl/BasicDataTypeSkel.h>
#include <cv.h>
#include <opencv2/core/core_c.h>

// Service implementation headers
// <rtc-template block="service_impl_h">
Expand Down
36 changes: 17 additions & 19 deletions rtc/UndistortImage/UndistortImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

#include "UndistortImage.h"

#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/core/types_c.h>
#include <opencv2/imgproc/imgproc.hpp>

// Module specification
// <rtc-template block="module_spec">
static const char* cameraimageviewercomponent_spec[] =
Expand Down Expand Up @@ -37,8 +41,6 @@ UndistortImage::UndistortImage(RTC::Manager* manager)
m_imageOut("imageOut", m_image),
// </rtc-template>
m_cvImage(NULL),
m_intrinsic(NULL),
m_distortion(NULL),
dummy(0)
{
}
Expand Down Expand Up @@ -106,18 +108,16 @@ RTC::ReturnCode_t UndistortImage::onActivated(RTC::UniqueId ec_id)
{
std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;

CvFileStorage *fs
= cvOpenFileStorage (m_calibFile.c_str(), 0, CV_STORAGE_READ);
if (!fs){
cv::FileStorage fs(m_calibFile.c_str(), cv::FileStorage::READ);
if (!fs.isOpened()){
std::cerr << m_profile.instance_name << ": can't open "
<< m_calibFile << std::endl;
return RTC::RTC_ERROR;
}
CvFileNode *param = cvGetFileNodeByName (fs, NULL, "intrinsic");
m_intrinsic = (CvMat *) cvRead (fs, param);
param = cvGetFileNodeByName (fs, NULL, "distortion");
m_distortion = (CvMat *) cvRead (fs, param);
cvReleaseFileStorage (&fs);
cv::FileNode param = fs["intrinsic"];
param >> m_intrinsic;
param = fs["distortion"];
param >> m_distortion;

return RTC::RTC_OK;
}
Expand All @@ -129,9 +129,7 @@ RTC::ReturnCode_t UndistortImage::onDeactivated(RTC::UniqueId ec_id)
cvReleaseImage(&m_cvImage);
m_cvImage = NULL;
}
if (m_intrinsic) cvReleaseMat (&m_intrinsic);
if (m_distortion) cvReleaseMat (&m_distortion);


return RTC::RTC_OK;
}

Expand Down Expand Up @@ -189,14 +187,16 @@ RTC::ReturnCode_t UndistortImage::onExecute(RTC::UniqueId ec_id)
}


IplImage *dst_img = cvCloneImage (m_cvImage);
cvUndistort2 (m_cvImage, dst_img, m_intrinsic, m_distortion);
cv::Mat src_img = cv::cvarrToMat(m_cvImage);
cv::Mat dst_img;
src_img.copyTo(dst_img);
cv::undistort (src_img, dst_img, m_intrinsic, m_distortion);

switch(m_image.data.image.format){
case Img::CF_RGB:
{
// BGR -> RGB
char *src = dst_img->imageData;
unsigned char *src = dst_img.data;
for (unsigned int i=0; i<m_image.data.image.raw_data.length(); i+=3){
m_image.data.image.raw_data[i+2] = src[i ];
m_image.data.image.raw_data[i+1] = src[i+1];
Expand All @@ -206,15 +206,13 @@ RTC::ReturnCode_t UndistortImage::onExecute(RTC::UniqueId ec_id)
}
case Img::CF_GRAY:
memcpy(m_image.data.image.raw_data.get_buffer(),
dst_img->imageData,
dst_img.data,
m_image.data.image.raw_data.length());
break;
default:
break;
}

cvReleaseImage (&dst_img);

m_imageOut.write();

return RTC::RTC_OK;
Expand Down
7 changes: 4 additions & 3 deletions rtc/UndistortImage/UndistortImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#include <rtm/DataInPort.h>
#include <rtm/DataOutPort.h>
#include <rtm/idl/BasicDataTypeSkel.h>
#include <cv.h>
#include <highgui.h>
#include <opencv2/core/core.hpp>
#include <opencv2/core/core_c.h>
#include <opencv2/highgui/highgui_c.h>

// Service implementation headers
// <rtc-template block="service_impl_h">
Expand Down Expand Up @@ -137,7 +138,7 @@ class UndistortImage
private:
IplImage* m_cvImage;
std::string m_calibFile;
CvMat *m_intrinsic, *m_distortion;
cv::Mat m_intrinsic, m_distortion;
int dummy;
};

Expand Down
3 changes: 1 addition & 2 deletions rtc/VideoCapture/camera.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

/* Most of capture.cpp and capture.h are copied from http://jsk-enshu.svn.sourceforge.net/viewvc/jsk-enshu/trunk/keisanki/2009/ */
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv2/core/core.hpp>
#include <linux/videodev2.h>
#include <fcntl.h>
#include <errno.h>
Expand Down
4 changes: 2 additions & 2 deletions rtc/VirtualCamera/VirtualCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <rtm/DataOutPort.h>
#include <rtm/idl/BasicDataTypeSkel.h>
//Open CV headder
#include <cv.h>
#include <highgui.h>
#include <opencv2/core/core_c.h>
#include <opencv2/highgui/highgui_c.h>
//
#include "hrpsys/util/LogManager.h"
#include "hrpsys/util/SDLUtil.h"
Expand Down
Loading

0 comments on commit bdbc4c8

Please sign in to comment.