Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Gamborg · Nov 23, 2017 at 08:46 AM · cameracrashesfor loop

for loop crashes unity

I intend to catch the camera, turn it to HSV and use this to do threshold for hand gesture tracking. But my for loop seems to crash Unity. I want to use a for loop since this shows the actions behind an image processing method, instead of using a library to do it for me. In the end i want to do convex hull detection and convex hull defects detection to return a number between 0 to 5 depending on the number of fingers showing, this 0 to 5 will then tell our game to use a spell or not depending on the number. This was just a bit of context tho, just need to get this for loop to work for now.

using Emgu.CV; using Emgu.CV.CvEnum; using Emgu.CV.Structure; using Emgu.CV.Features2D; using Emgu.CV.Util; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEngine.UI; using Emgu.CV.Aruco;

public class GestureTrackingScript : MonoBehaviour {

 public VideoCapture cap;
 public RawImage camImage;
 int iteration = 0;

 // Use this for initialization
 void Start()
 {
     Debug.Log("Startup initiated...");
     cap = new VideoCapture(0); // instantiate a webcamera
     cap.SetCaptureProperty(CapProp.Fps, 30); // The FPS of the camera
     
     Debug.Log("Startup finished. Running...");
 }

 // Update is called once per frame
 void Update()
 {
     Image<Hsv, byte> frame = cap.QueryFrame().ToImage<Hsv, byte>(); // the input image (frame from camera)
    
     for (int j = 0; j < frame.Height; j++){
         for (int i = 0; i < frame.Width; i++){
             //lower
             frame = frame.ThresholdToZero(new Hsv(10.0, 22.0, 10.0));
             //upper
             frame = frame.ThresholdToZeroInv(new Hsv(100.0, 29.0, 100.0));
         }
     }

     MemoryStream _memory = new MemoryStream();
     frame.Bitmap.Save(_memory, frame.Bitmap.RawFormat);
     Texture2D camera = new Texture2D(400, 400);
     camera.LoadImage(_memory.ToArray());
     camImage.texture = camera;
     camImage.material.mainTexture = camera;
     Debug.Log("Ping Number " + iteration);
     iteration++;

 }

}

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gamborg · Nov 23, 2017 at 10:59 AM 0
Share

Can update, that removing one axies of the for loop, shows that the program does in fact work, just very very laggy with even one axies, so i believe with two axies the program simply crashes ? What could cause this?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Gamborg · Nov 24, 2017 at 08:34 AM

Problem was that emguCV functions by default goes over all pixels, if i then put that into a for loop that also goes over all pixels, it because too big a load for the system :) So simply removing the for loops fixed it.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

158 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity editor crash with Camera,Unity editor crashes with Camera 0 Answers

How to make a camera follow a ball from behind? c# 3 Answers

Camera Script remove a part. 0 Answers

Focus Camera on object to use GUI Interface. 0 Answers

OnMouseDown raycast doesnt match UI crosshair 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges