Go to Post ...many different kinds of students join our team. Some only have an interest in media, or others in cheering. What is important is that they are having fun while working in an engineering environment. - Bharat Nain [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

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 31-03-2016, 10:10
richtop richtop is offline
Registered User
AKA: Richard Topolewski
FRC #5053 (Laker Robotics)
Team Role: Mentor
 
Join Date: Nov 2014
Rookie Year: 2013
Location: Waterford, Michigan
Posts: 16
richtop is an unknown quantity at this point
How to lower image pixels in straight NIVision code.

Okay we have had camera working at our tournaments, and have added laptop side processing in the Labview dashboard of the image to get the alignment to the goal, which is sent back to the roborio.

At first we were using the following code to send the image.
camera = CameraServer.getInstance();
camera.setSize(2/*camera.kSize320x240*/);
camera.setImage(Image.SCALE_FAST);
camera.setQuality(100);
camera.startAutomaticCapture("cam0");


But we were running 90% to 100% pegged CPU.

By changing to the following code it now is running a more reasonable 40% to 60% CPU. But we are only getting 1.9 frame per second. I would like to lower the pixels in the picture, but don't know the how to in straight NIVision code. Any pointers in the right direction would be appreciated.


public class Robot extends IterativeRobot {
...
...
int countToTakePicture = 20;
int currentCountToTakePicture = 0;
...
...
public void teleopPeriodic() {
Scheduler.getInstance().run();
boolean takePicture = false;
if(currentCountToTakePicture == countToTakePicture){
takePicture = true;
}
else if(currentCountToTakePicture <= countToTakePicture){
currentCountToTakePicture++;
} else {
currentCountToTakePicture = 0;
}

if (takePicture){
int session;
session = NIVision.IMAQdxOpenCamera("cam0",NIVision.IMAQdxCa meraControlMode.CameraControlModeController);
NIVision.IMAQdxStartAcquisition(session);
Image frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_ RGB, 0);
NIVision.IMAQdxGrab(session, frame, 10);
cameraServer.getInstance().setImage(frame);
NIVision.IMAQdxStopAcquisition(session);
NIVision.IMAQdxCloseCamera(session);

// from cheifdelphi Program crashes with out of memory issue if we remove this line
frame.free();
}



Lower priority items:
Also should probably do a more controlled way on when to take the picture.

Also thinking about copying it into auton so can autoalign for our low goal, I dont anticipate any problems but, my lack of full understanding of NIVision makes me worry, should I?
Reply With Quote
  #2   Spotlight this post!  
Unread 03-04-2016, 20:03
UnknownFactor's Avatar
UnknownFactor UnknownFactor is offline
The name's Ray.
FRC #0020 (Team 20 Rocketeers)
Team Role: Programmer
 
Join Date: Feb 2015
Rookie Year: 2014
Location: New York
Posts: 4
UnknownFactor is an unknown quantity at this point
Re: How to lower image pixels in straight NIVision code.

What I would recommend is decreasing camera.setQuality(100) to camera.setQuality(50). In my opinion, 100 is too much for the CPU to handle, plus, this is what our team's code has in terms of the quality.
Reply With Quote
  #3   Spotlight this post!  
Unread 04-04-2016, 08:40
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 298
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: How to lower image pixels in straight NIVision code.

You can use imaqScale or imaqResize. imaqScale will change your image width and height to a factor or multiple of the original width and height, while imaqResize will change it to any arbitrary size. I would recommend imaqScale because I'd assume it's faster.

Also, you don't need to keep deleting and recreating Image objects (as in your second code snippet). You can use the same image object multiple times for camera capture with IMAQdx

Last edited by euhlmann : 04-04-2016 at 08:51.
Reply With Quote
Reply


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 08:21.

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