Go to Post Although you will see lot's of people complain about parts (sometimes that includes me) all of us are held to the same constraints. That's what makes this so much fun. - Al Skierkiewicz [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Spotlight this post!  
Unread 30-01-2017, 01:36
Noam Noam is offline
Registered User
None #3034 (galileo)
Team Role: Programmer
 
Join Date: Jan 2017
Rookie Year: 2015
Location: Israel
Posts: 14
Noam is an unknown quantity at this point
Re: image processing using opencv - how to draw on the video

Quote:
Originally Posted by YairZiv View Post
Have you looked at the Intermediate Vision sample in the example projects? It does exactly that (though it draws a rectangle instead).
I didnt saw this example, thanks

but if im trying to do more things - and not just a rectangle, so the robot crash after a few seconds (about 2-3 seconds) and the program starts again, and crash..

this is the code

Code:
	Thread visionThread;

	@Override
	public void robotInit() {
		visionThread = new Thread(() -> {
			UsbCamera camera = CameraServer.getInstance().startAutomaticCapture();
			camera.setResolution(640, 480);
			CvSink cvSink = CameraServer.getInstance().getVideo();
			CvSource outputStream = CameraServer.getInstance().putVideo("Rectangle", 640, 480);
			Mat mat = new Mat();
			while (!Thread.interrupted()) {
				if (cvSink.grabFrame(mat) == 0) {
					outputStream.notifyError(cvSink.getError());
					continue;
				}
				Mat hsv = new Mat();
				Mat thres = new Mat();
				Imgproc.cvtColor(mat, hsv, Imgproc.COLOR_RGB2HSV);
				Core.inRange(hsv,
						new Scalar(0, 0, 240),
						new Scalar(255, 255, 255),
						thres);
				Imgproc.rectangle(mat, new Point(100, 100), new Point(400, 400),
						new Scalar(255, 255, 255), 5);
				// outputStream.putFrame(mat);
				outputStream.putFrame(thres);
			}
		});
		visionThread.setDaemon(true);
		visionThread.start();
    }

and this is the error

Code:
 OpenCV Error: Insufficient memory (Failed to allocate 921600 bytes) in OutOfMemoryError, file /var/lib/jenkins/workspace/OpenCV-roborio/modules/core/src/alloc.cpp, line 52 
 OpenCV Error: Assertion failed (u != 0) in create, file /var/lib/jenkins/workspace/OpenCV-roborio/modules/core/src/matrix.cpp, line 424 
 Exception in thread "Thread-0" CvException [org.opencv.core.CvException: cv::Exception: /var/lib/jenkins/workspace/OpenCV-roborio/modules/core/src/matrix.cpp:424: error: (-215) u != 0 in function create 
 ] 
 	at org.opencv.imgproc.Imgproc.cvtColor_1(Native Method) 
 	at org.opencv.imgproc.Imgproc.cvtColor(Unknown Source) 
 	at org.usfirst.frc.team3034.robot.Robot.lambda$robotInit$0(Robot.java:89) 
 	at org.usfirst.frc.team3034.robot.Robot$$Lambda$1/13402185.run(Unknown Source) 
 	at java.lang.Thread.run(Thread.java:745) 
 terminate called after throwing an instance of 'std::system_error' 
   what():  Resource temporarily unavailable 
 ➔ Launching «'/usr/local/frc/JRE/bin/java' '-Djava.library.path=/usr/local/frc/lib/' '-jar' '/home/lvuser/FRCUserProgram.jar'» 
 ********** Robot program starting ********** 
 NT: server: client CONNECTED: 10.30.34.17 port 55027 
 Default IterativeRobot.disabledInit() method... Overload me! 
Warning  44003  FRC:  No robot code is currently running.  Driver Station 
 Default IterativeRobot.disabledPeriodic() method... Overload me! 
 Default IterativeRobot.robotPeriodic() method... Overload me! 
 CS: USB Camera 0: Connecting to USB camera on /dev/video0 
 CS: USB Camera 0: set format 1 res 160x120 
 CS: USB Camera 0: Connecting to USB camera on /dev/video0 
 CS: USB Camera 0: set format 1 res 640x480 
 CS: USB Camera 0: set FPS to 7

and line 879 is this

Code:
Imgproc.cvtColor(mat, hsv, Imgproc.COLOR_RGB2HSV);

you know why its happening and how to fix that ?
I thought that it maybe because its "too much" for the roborio, so the code is crashing (and starts again) - because thats happened to me a few days ago, when i tried to take a lot of photos, but i dont think that its the problem now..
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 04:05.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi