View Single Post
  #1   Spotlight this post!  
Unread 10-01-2017, 06:46
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 212
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
MJPG Streamer input from opencv in C++

Hello!

I am setting up a vision co-processor with a raspberry pi 3 and I am having a trouble getting image data from opencv to mjpg-streamer. The reason I want to do this is so I can see the output of the opencv processing right on the smart dashboard.

The specific issue is that there is no image showing up in the web server for mjpg-streamer. The page is continuously loading so I think its just not displaying the stream.

I can even watch the avi file if I run omxplayer on the file.

Here is my opencv code:
Code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
#include <ntcore.h>
#include <cscore.h>
#include <networktables/NetworkTable.h>

void VisionThread() {

	cv::VideoCapture vidCap(0);
	
	cv::Mat frame;
	cv::Mat output;

	cv::namedWindow("Display Window", cv::WINDOW_AUTOSIZE);
	
	if(!vidCap.isOpened()) {
		std::cout << "Can't open video stream!" << "\n";
	}
	else {
		vidCap.set(CV_CAP_PROP_FRAME_WIDTH,640);
		vidCap.set(CV_CAP_PROP_FRAME_HEIGHT,480);
	}

	vidCap >> frame; 
		
	cv::VideoWriter outStream("output/out.avi", CV_FOURCC('M','J','P','G'), 30, frame.size(), true);

	while(true) {
		vidCap >> frame;
		cv::circle(frame, cv::Point(320, 240), 5, cv::Scalar(255, 0, 0));
		
		if(outStream.isOpened()) {
			outStream.write(frame);
		} 
		else {
			std::cout<<"Can't write to file!" << "\n";
		}
		
		cv::imshow("Display Window", frame);
		if(cv::waitKey(30) >= 0) break;
	}	
}

int main(int argc, const char** argv) {
	
	VisionThread();
	
    return 0;
}
Here is the command I am running to start mjpg streamer:
Code:
mjpg_streamer -i "input_file.so -f /home/pi/vision_code/output"  -o "output_http.so -w /usr/local/www"
Any help is appreciated!

Thanks,
Drew
Reply With Quote