RaspberryP4에 raspicam_cv 설치
8399 단어 RaspberryPi4OpenCVraspicam_cv
raspicam_cv 설치
$ mkdir raspicam
$ cd raspicam
$ wget https://downloads.sourceforge.net/project/raspicam/raspicam-0.1.8.zip
$ unzip raspicam-0.1.8.zip
$ cd raspicam-0.1.8
$ mkdir build
$ cd build
$ cmake ..
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
--Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /usr/local (found version "3.4.10")
-- Adding cv library
--
-- -------------------------------------------------------------------------------
-- General configuration for raspicam 0.1.8
-- -------------------------------------------------------------------------------
--
Built as dynamic libs?:ON
Compiler:/usr/bin/c++
-- C++ flags (Release): -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=hard -O3 -g0 -DNDEBUG
-- C++ flags (Debug): -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=hard -O0 -g3 -DDEBUG -D_DEBUG -DPRINT_DEBUG_MESSAGES
-- CMAKE_CXX_FLAGS:
-- CMAKE_BINARY_DIR: /home/pi/raspicam/raspicam-0.1.8/build
--
-- TARGET_PROCESSOR = armv7l
-- BUILD_SHARED_LIBS = ON
-- BUILD_UTILS = ON
-- CMAKE_INSTALL_PREFIX = /usr/local
-- CMAKE_BUILD_TYPE = Release
-- CMAKE_MODULE_PATH = /usr/local/lib/cmake/;/usr/lib/cmake
-- CREATE OPENCV MODULE=1
-- CMAKE_INSTALL_PREFIX=/usr/local
-- REQUIRED_LIBRARIES=pthread
-- Change a value with: cmake -D<Variable>=<Value>
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/raspicam/raspicam-0.1.8/build
$ make
$ sudo make install
$ ls /usr/local/lib/libraspicam*
/usr/local/lib/libraspicam_cv.so /usr/local/lib/libraspicam.so
/usr/local/lib/libraspicam_cv.so.0.1 /usr/local/lib/libraspicam.so.0.1
/usr/local/lib/libraspicam_cv.so.0.1.8 /usr/local/lib/libraspicam.so.0.1.8
테스트 프로그램
/**
simpletest_raspicam.cpp
**/
#include <ctime>
#include <fstream>
#include <iostream>
#include <raspicam/raspicam.h>
#include <unistd.h>
using namespace std;
int main ( int argc,char **argv ) {
raspicam::RaspiCam Camera; //Cmaera object
//Open camera
cout<<"Opening Camera..."<<endl;
if ( !Camera.open()) {cerr<<"Error opening camera"<<endl;return -1;}
//wait a while until camera stabilizes
cout<<"Sleeping for 3 secs"<<endl;
sleep(3);
//capture
Camera.grab();
//allocate memory
unsigned char *data=new unsigned char[ Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB )];
//extract the image in rgb format
Camera.retrieve ( data,raspicam::RASPICAM_FORMAT_RGB );//get camera image
//save
std::ofstream outFile ( "raspicam_image.ppm",std::ios::binary );
outFile<<"P6\n"<<Camera.getWidth() <<" "<<Camera.getHeight() <<" 255\n";
outFile.write ( ( char* ) data, Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB ) );
cout<<"Image saved at raspicam_image.ppm"<<endl;
//free resrources
delete data;
return 0;
}
CMakeLists.txt
cmake_minimum_required (VERSION 2.8)
project (raspicam_test)
find_package(raspicam REQUIRED)
add_executable (simpletest_raspicam simpletest_raspicam.cpp)
target_link_libraries (simpletest_raspicam ${raspicam_LIBS})
빌드
$ mkdir build
$ cd build
cmake ..
make
실행
$ ./simpletest_raspicam
OpenCV 테스트 프로그램
/*
* simpletest_raspicam_cv.cpp
*/
#include <ctime>
#include <iostream>
#include <raspicam/raspicam_cv.h>
using namespace std;
int main ( int argc,char **argv ) {
time_t timer_begin,timer_end;
raspicam::RaspiCam_Cv Camera;
cv::Mat image;
int nCount=100;
//set camera params
Camera.set( CV_CAP_PROP_FORMAT, CV_8UC1 );
//Open camera
cout<<"Opening Camera..."<<endl;
if (!Camera.open()) {cerr<<"Error opening the camera"<<endl;return -1;}
//Start capture
cout<<"Capturing "<<nCount<<" frames ...."<<endl;
time ( &timer_begin );
for ( int i=0; i<nCount; i++ ) {
Camera.grab();
Camera.retrieve ( image);
if ( i%5==0 ) cout<<"\r captured "<<i<<" images"<<std::flush;
}
cout<<"Stop camera..."<<endl;
Camera.release();
//show time statistics
time ( &timer_end ); /* get current time; same as: timer = time(NULL) */
double secondsElapsed = difftime ( timer_end,timer_begin );
cout<< secondsElapsed<<" seconds for "<< nCount<<" frames : FPS = "<< ( float ) ( ( float ) ( nCount ) /secondsElapsed ) <<endl;
//save image
cv::imwrite("raspicam_cv_image.jpg",image);
cout<<"Image saved at raspicam_cv_image.jpg"<<endl;
}
CMakeLists.txt
cmake_minimum_required (VERSION 2.8)
project (raspicam_test)
find_package(raspicam REQUIRED)
find_package(OpenCV)
IF ( OpenCV_FOUND AND raspicam_CV_FOUND)
MESSAGE(STATUS "COMPILING OPENCV TESTS")
add_executable (simpletest_raspicam_cv simpletest_raspicam_cv.cpp)
target_link_libraries (simpletest_raspicam_cv ${raspicam_CV_LIBS})
ELSE()
MESSAGE(FATAL_ERROR "OPENCV NOT FOUND IN YOUR SYSTEM")
ENDIF()
빌드
$ mkdir build
$ cd build
$ cmake ..
$ make
실행
$./simpletest_raspicam_cv
github htps : // 기주 b. 코 m / 미소라고 d / 라 s 피카 m
갑자기 ld가 오류에.
얼마전에 아무 일도 없이 빌드할 수 있었는데 왜?
[100%] Linking CXX executable simpletest_raspicam_cv
/usr/bin/ld: /usr/local/lib/libraspicam_cv.so: invalid string offset 4619 >= 3963 for section `.strtab'
/usr/bin/ld: /usr/local/lib/libraspicam_cv.so: invalid string offset 4604 >= 3963 for section `.strtab'
/usr/bin/ld: /usr/local/lib/libraspicam_cv.so: invalid string offset 4592 >= 3963 for section `.strtab'
/usr/bin/ld: /usr/local/lib/libraspicam_cv.so: invalid string offset 4630 >= 3963 for section `.strtab'
/usr/bin/ld: /usr/local/lib/libraspicam_cv.so: invalid string offset 4638 >= 3963 for section `.strtab'
/usr/bin/ld: /usr/local/lib/libraspicam_cv.so: invalid string offset 4585 >= 3963 for section `.strtab'
/usr/bin/ld: /usr/local/lib/libraspicam_cv.so: invalid string offset 4618 >= 3963 for section `.strtab'
ELF의 헤더 정보가 이상해지고 있지만, 오브젝트는 완성되어 있어 실행도 할 수 있다.
ld 버전 확인
$ ld --version
GNU ld (GNU Binutils for Raspbian) 2.31.1
Copyright (C) 2018 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
g++ 버전 확인
$ g++ --version
g++ (Raspbian 8.3.0-6+rpi1) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Reference
이 문제에 관하여(RaspberryP4에 raspicam_cv 설치), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/misoragod/items/ba9a1223da4c223bdcde텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)