Announcement

Collapse
No announcement yet.

DogeCV Front Camera

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DogeCV Front Camera

    Currently DogeCV utilizes the back camera. Is there a way to adjust it so it will use the front facing camera?

  • #2
    CoachZM We didn't try the front camera, however (in case you're looking for options) we did get DogeCV working well with the USB webcam/hub option and some tips from Wizards.exe
    Michael P Clark
    Founding Mentor, FTC 9958
    http://www.redfishrobotics.com
    "We're Hooked on FIRST"

    Comment


    • #3
      See lie 87 of this: https://github.com/MechanicalMemes/D...neTesting.java

      Change BACK to FRONT

      Comment


      • #4
        Cheer4FTC is line 87 something you added in? In the goldalignexample from DogeCV or in their other code from the DogeCV folder I am not seeing any files that reference the word BACK in them.

        Comment


        • #5
          LIne 87 is in the original code for the VuforiaPhoneTesting class.

          If you want to run the GoldAlignExample instead, I think you need to replace line 54 of https://github.com/MechanicalMemes/D...gnExample.java
          Code:
          detector.init(hardwareMap.appContext, CameraViewDisplay.getInstance()); // Initialize it with the app context and camera
          with this
          Code:
          detector.init(hardwareMap.appContext, CameraViewDisplay.getInstance(), 1, false); // Initialize it with the app context and camera
          That's based on the GoldAlignDetector class extending DogeCVDetector extending OpenCVPipeline which is here: https://github.com/MechanicalMemes/D...VPipeline.java

          OpenCVPipeline has an init with two parameters which defaults to back camera and no Vuforia and another init with four parameters which allows you to pick your camera and turn on Vuforia if you want. If you want to use Vuforia, it looks like you'd change the last parameter in the call to be true.

          See lines 67-103 of the OpenCVPipeline class to see the code behind both init options.

          Comment


          • #6
            Cheer4FTC thanks for the help. That did the trick. Now I just need to figure out how to rotate the image 180 degrees as everything is upside down! 1 step closer!

            Comment


            • #7
              We have been trying some different pieces of code but nothing successful yet in getting the image to be rotated the correct direction once we use the front camera. Does anyone have a suggestion as to how to rotate the image 180 degrees?

              Comment


              • #8
                Originally posted by CoachZM View Post
                We have been trying some different pieces of code but nothing successful yet in getting the image to be rotated the correct direction once we use the front camera. Does anyone have a suggestion as to how to rotate the image 180 degrees?
                Code:
                 
                 Core.rotate(Mat src, Mat dst, Core.ROTATE_180);

                Comment


                • #9
                  Thanks 4634 Programmer . I put that code in and import the core information but it does not like the Mat src or Mat dst. Those both show up in red.

                  Comment


                  • #10
                    Originally posted by CoachZM View Post
                    Thanks 4634 Programmer . I put that code in and import the core information but it does not like the Mat src or Mat dst. Those both show up in red.
                    Well, I was just posting the method signature with the last parameter already defined. You'll need to do:

                    Code:
                     
                     Core.rotate(frame, rotatedFrame, Core.ROTATE_180);
                    Somewhere inside the DogeCV code. (Obviously you'll need to create the "rotatedFrame" object yourself and change the DogeCV code accordingly.)

                    Comment


                    • #11
                      ok I got gold align example to work with front and back camera, but VuforiaPhoneTesting.java I can't get to work with front camera. Any tips. I have the code below set to use the front camera.
                      Code:
                        
                       /* Copyright (c) 2017 FIRST. All rights reserved.  *  * Redistribution and use in source and binary forms, with or without modification,  * are permitted (subject to the limitations in the disclaimer below) provided that  * the following conditions are met:  *  * Redistributions of source code must retain the above copyright notice, this list  * of conditions and the following disclaimer.  *  * Redistributions in binary form must reproduce the above copyright notice, this  * list of conditions and the following disclaimer in the documentation and/or  * other materials provided with the distribution.  *  * Neither the name of FIRST nor the names of its contributors may be used to endorse or  * promote products derived from this software without specific prior written permission.  *  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS  * LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */  package org.firstinspires.ftc.teamcode;   import com.disnodeteam.dogecv.CameraViewDisplay; import com.disnodeteam.dogecv.DogeCV; import com.disnodeteam.dogecv.Dogeforia; import com.disnodeteam.dogecv.detectors.roverrukus.GoldAlignDetector; import com.disnodeteam.dogecv.filters.LeviColorFilter; import com.disnodeteam.dogecv.scoring.MaxAreaScorer; import com.disnodeteam.dogecv.scoring.RatioScorer; import com.qualcomm.robotcore.eventloop.opmode.OpMode; import com.qualcomm.robotcore.eventloop.opmode.TeleOp; import com.qualcomm.robotcore.util.ElapsedTime;  import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName; import org.firstinspires.ftc.robotcore.external.matrices.OpenGLMatrix; import org.firstinspires.ftc.robotcore.external.matrices.VectorF; import org.firstinspires.ftc.robotcore.external.navigation.Orientation; import org.firstinspires.ftc.robotcore.external.navigation.VuforiaLocalizer; import org.firstinspires.ftc.robotcore.external.navigation.VuforiaTrackable; import org.firstinspires.ftc.robotcore.external.navigation.VuforiaTrackableDefaultListener; import org.firstinspires.ftc.robotcore.external.navigation.VuforiaTrackables;  import java.util.ArrayList; import java.util.List;  import static org.firstinspires.ftc.robotcore.external.navigation.AngleUnit.DEGREES; import static org.firstinspires.ftc.robotcore.external.navigation.AxesOrder.XYZ; import static org.firstinspires.ftc.robotcore.external.navigation.AxesOrder.YZX; import static org.firstinspires.ftc.robotcore.external.navigation.AxesReference.EXTRINSIC; import static org.firstinspires.ftc.robotcore.external.navigation.VuforiaLocalizer.CameraDirection.BACK; import static org.firstinspires.ftc.robotcore.external.navigation.VuforiaLocalizer.CameraDirection.FRONT;  /**  * This file contains an example of an iterative (Non-Linear) "OpMode".  * An OpMode is a 'program' that runs in either the autonomous or the teleop period of an FTC match.  * The names of OpModes appear on the menu of the FTC Driver Station.  * When an selection is made from the menu, the corresponding OpMode  * class is instantiated on the Robot Controller and executed.  *  * This particular OpMode just executes a basic Tank Drive Teleop for a two wheeled robot  * It includes all the skeletal structure that all iterative OpModes contain.  *  * Use Android Studios to Copy this Class, and Paste it into your team's code folder with a new name.  * Remove or comment out the @Disabled line to add this opmode to the Driver Station OpMode list  */  @TeleOp(name="Vuforia Phone Testing", group="DogeCV")  public class VuforiaPhoneTesting extends OpMode {     //Elapsed time and measurement constants     private ElapsedTime runtime = new ElapsedTime();     private static final float mmPerInch        = 25.4f;     private static final float mmFTCFieldWidth  = (12*6) * mmPerInch;       // the width of the FTC field (from the center point to the outer panels)     private static final float mmTargetHeight   = (6) * mmPerInch;          // the height of the center of the target image above the floor      // Select which camera you want use.  The FRONT camera is the one on the same side as the screen.     // Valid choices are:  BACK or FRONT     private static final VuforiaLocalizer.CameraDirection CAMERA_CHOICE = FRONT;      //Vuforia variables     private OpenGLMatrix lastLocation = null;     boolean targetVisible;     Dogeforia vuforia;     WebcamName webcamName;     List<VuforiaTrackable> allTrackables = new ArrayList<VuforiaTrackable>();      //Detector object     GoldAlignDetector detector;      @Override     public void init() {         // Setup camera and Vuforia parameters         int cameraMonitorViewId = hardwareMap.appContext.getResources().getIdentifier("cameraMonitorViewId", "id", hardwareMap.appContext.getPackageName());         VuforiaLocalizer.Parameters parameters = new VuforiaLocalizer.Parameters();          // Set Vuforia parameters         parameters.vuforiaLicenseKey = "AWbfTmn/////AAABmY0xuIe3C0RHvL3XuzRxyEmOT2OekXBSbqN2jot1si3OGBObwWadfitJR/D6Vk8VEBiW0HG2Q8UAEd0//OliF9aWCRmyDJ1mMqKCJZxpZemfT5ELFuWnJIZWUkKyjQfDNe2RIaAh0ermSxF4Bq77IDFirgggdYJoRIyi2Ys7Gl9lD/tSonV8OnldIN/Ove4/MtEBJTKHqjUEjC5U2khV+26AqkeqbxhFTNiIMl0LcmSSfugGhmWFGFtuPtp/+flPBRGoBO+tSl9P2sV4mSUBE/WrpHqB0Jd/tAmeNvbtgQXtZEGYc/9NszwRLVNl9k13vrBcgsiNxs2UY5xAvA4Wb6LN7Yu+tChwc+qBiVKAQe09\n";         parameters.fillCameraMonitorViewParent = true;          // Init Dogeforia         vuforia = new Dogeforia(parameters);         vuforia.enableConvertFrameToBitmap();          // Set target names         VuforiaTrackables targetsRoverRuckus = this.vuforia.loadTrackablesFromAsset("RoverRuckus");         VuforiaTrackable blueRover = targetsRoverRuckus.get(0);         blueRover.setName("Blue-Rover");         VuforiaTrackable redFootprint = targetsRoverRuckus.get(1);         redFootprint.setName("Red-Footprint");         VuforiaTrackable frontCraters = targetsRoverRuckus.get(2);         frontCraters.setName("Front-Craters");         VuforiaTrackable backSpace = targetsRoverRuckus.get(3);         backSpace.setName("Back-Space");          // For convenience, gather together all the trackable objects in one easily-iterable collection */         allTrackables.addAll(targetsRoverRuckus);          // Set trackables' location on field         OpenGLMatrix blueRoverLocationOnField = OpenGLMatrix                 .translation(0, mmFTCFieldWidth, mmTargetHeight)                 .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 90, 0, 0));         blueRover.setLocation(blueRoverLocationOnField);          OpenGLMatrix redFootprintLocationOnField = OpenGLMatrix                 .translation(0, -mmFTCFieldWidth, mmTargetHeight)                 .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 90, 0, 180));         redFootprint.setLocation(redFootprintLocationOnField);          OpenGLMatrix frontCratersLocationOnField = OpenGLMatrix                 .translation(-mmFTCFieldWidth, 0, mmTargetHeight)                 .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 90, 0 , 90));         frontCraters.setLocation(frontCratersLocationOnField);          OpenGLMatrix backSpaceLocationOnField = OpenGLMatrix                 .translation(mmFTCFieldWidth, 0, mmTargetHeight)                 .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 90, 0, -90));         backSpace.setLocation(backSpaceLocationOnField);           //Set camera displacement         final int CAMERA_FORWARD_DISPLACEMENT  = 110;   // eg: Camera is 110 mm in front of robot center         final int CAMERA_VERTICAL_DISPLACEMENT = 200;   // eg: Camera is 200 mm above ground         final int CAMERA_LEFT_DISPLACEMENT     = 0;     // eg: Camera is ON the robot's center line          // Set phone location on robot         OpenGLMatrix phoneLocationOnRobot = OpenGLMatrix                 .translation(CAMERA_FORWARD_DISPLACEMENT, CAMERA_LEFT_DISPLACEMENT, CAMERA_VERTICAL_DISPLACEMENT)                 .multiplied(Orientation.getRotationMatrix(EXTRINSIC, YZX, DEGREES,                         CAMERA_CHOICE == FRONT ? 90 : -90, 0, 0));          //Set info for the trackables         for (VuforiaTrackable trackable : allTrackables) {             ((VuforiaTrackableDefaultListener)trackable.getListener()).setPhoneInformation(phoneLocationOnRobot, parameters.cameraDirection);         }          //Activate targets         targetsRoverRuckus.activate();          detector = new GoldAlignDetector(); // Create a gold aligndetector         detector.init(hardwareMap.appContext,CameraViewDisplay.getInstance(), 1, true);          detector.yellowFilter = new LeviColorFilter(LeviColorFilter.ColorPreset.YELLOW, 100); // Create new filter         detector.useDefaults(); // Use default settings         detector.areaScoringMethod = DogeCV.AreaScoringMethod.MAX_AREA; // Can also be PERFECT_AREA         //detector.perfectAreaScorer.perfectArea = 10000; // Uncomment if using PERFECT_AREA scoring          //Setup Vuforia         vuforia.setDogeCVDetector(detector); // Set the Vuforia detector         vuforia.enableDogeCV(); //Enable the DogeCV-Vuforia combo         vuforia.showDebug(); // Show debug info         vuforia.start(); // Start the detector     }      /*      * Code to run REPEATEDLY when the driver hits INIT      */     @Override     public void init_loop() {     }      /*      * Code to run ONCE when the driver hits PLAY      */     @Override     public void start() {         //Reset timer         runtime.reset();     }      /*      * Code to run REPEATEDLY when the driver hits PLAY      */     @Override     public void loop() {         //Assume we can't find a target         targetVisible = false;          //Loop through trackables - if we find one, get the location         for (VuforiaTrackable trackable : allTrackables) {             if (((VuforiaTrackableDefaultListener)trackable.getListener()).isVisible()) {                 //We found a target! Print data to telemetry                 telemetry.addData("Visible Target", trackable.getName());                 targetVisible = true;                  // getUpdatedRobotLocation() will return null if no new information is available since the last time that call was made, or if the trackable is not currently visible.                 OpenGLMatrix robotLocationTransform = ((VuforiaTrackableDefaultListener)trackable.getListener()).getUpdatedRobotLocation();                 if (robotLocationTransform != null) {                     lastLocation = robotLocationTransform;                 }                 break;             }         }          // Provide feedback as to where the robot is located (if we know).         if (targetVisible) {             // Express position (translation) of robot in inches.             VectorF translation = lastLocation.getTranslation();             telemetry.addData("Pos (in)", "{X, Y, Z} = %.1f, %.1f, %.1f",                     translation.get(0) / mmPerInch, translation.get(1) / mmPerInch, translation.get(2) / mmPerInch);              // Express the rotation of the robot in degrees.             Orientation rotation = Orientation.getOrientation(lastLocation, EXTRINSIC, XYZ, DEGREES);             telemetry.addData("Rot (deg)", "{Roll, Pitch, Heading} = %.0f, %.0f, %.0f", rotation.firstAngle, rotation.secondAngle, rotation.thirdAngle);         }         else {             //No visible target             telemetry.addData("Visible Target", "none");         }         // Update telemetry         telemetry.update();     }      /*      * Code to run ONCE after the driver hits STOP      */     @Override     public void stop() {         vuforia.stop();      }  }

                      thanks
                      Larry

                      Comment

                      Working...
                      X