orgicus / ofxCvPiCam

ofxCvPiCam is a minimal grabber for the Raspberry Pi Camera module. It uses the MMAL interface to grab frames and convert them the cv::Mat type which can be processed using the typical opencv calls.
Other
49 stars 10 forks source link

C::Mat link back to Video Grabber #10

Open awilkie1 opened 7 years ago

awilkie1 commented 7 years ago

Im trying to use the C::mat for as a source for a video grabber as I want to detect objects such as ArCuo. Can this be done on the pi using the native camera??

orgicus commented 6 years ago

If :

Then the answer is yes :)

Have a look at example-ofxCvPiCamSimple It should be possible to simply grab the frame from the ofxCvPiCam instance and pass it to ArUco:


//in update
cv::Mat frame = cam.grab();
if(!frame.empty()){
//pass the frame to ArUco here
}
owenplanchart commented 3 years ago

Hi,

by the same logic,

would it be possible to pass an ofxAruco object using ofxCvPiCam. How does one get the pixels from ofxCvPiCam?

orgicus commented 3 years ago

Hi @owenplanchart

It would be possible, but bare in my mind my basic addon fetches PiCamera data in cv::Mat format while ofxAruco::detectBoards takes ofPixels & pixels as an argument. You can use ofxCv to easily wrap cv::Mat to ofPixels (for example using toOf(cv::Mat mat, ofPixels_<T>& pixels))

Hope this helps, George

owenplanchart commented 3 years ago

Thank you,

I will give this a try

owenplanchart commented 3 years ago

Is this the right implementation?

void ofApp::update(){
    cv::Mat frame = cam.grab();
    ofPixels arPixels;
    toOf(frame, arPixels);
    if(!frame.empty()){
       aruco.detectBoards(arPixels);
    }
}
orgicus commented 3 years ago

@owenplanchart That looks good ! You should test it when you get a chance. The other thing I'd recommend is maybe holding on two the frame and arPixels references and maybe doing the the empty() check before attempting to convert toOf(), something along these lines:

// in your ofApp.h for example
cv::Mat frame;
ofPixels arPixels;
// in your ofApp.cpp:
void ofApp::update(){
    frame = cam.grab();
    if(!frame.empty()){
       toOf(frame, arPixels);
       aruco.detectBoards(arPixels);
    }
}
owenplanchart commented 3 years ago

It's really strange because now I'm getting this error when I try to compile:

obj/linuxarmv6l/Release/src/ofApp.o: file not recognized: file truncated
collect2: error: ld returned 1 exit status
make[1]: *** [/home/pi/openFrameworks/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk:405: bin/cvPiCamChand] Error 1
make[1]: Leaving directory '/home/pi/openFrameworks/apps/myApps/cvPiCamChand'
make: *** [/home/pi/openFrameworks/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk:129: Release] Error 2
owenplanchart commented 3 years ago

@orgicus Not sure what happened there, so I re-downloaded the addon and wrote the sketch from scratch and managed to get the aruco markers working (yay!). This was on the RP3b (buster) with the Pi cam v2.1. Does this addon work with the pI4? Thanks so much for your work and help on this.