Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
12 Jun 22 - 14 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 /
avatar image
0
Question by jw950310 · Jan 17, 2019 at 02:30 PM · webcamtexturewebcamrecognition

How to recognize movement in webcam?

I used webcamtexture.GetPixel(x,y). But it always returned different values every time, even though I covered webcam with paper. I just want to return true if there is any movement in webcam, and return false vice versa. I don't have any other devices such as Leapmotion controller or Kinect. I can't buy them. Then, how can i recognize any movement in Unity webcam? It doesn't matter whether it would be Unity 2D or 3D. Thank you in advance!

Comment
Add comment · Show 3
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 TreyH · Jan 17, 2019 at 02:53 PM 0
Share

Since GetPixel returns a Color instance, you've probably noticed that RGB values can be a bit tedious to compare with one another. You're probably also dealing with electronic gain and general camera stuff which will change your pixel values slightly between frames.

Pixel comparisons are a bit simpler with an HSV format, so you might want to try that:

 [Range(0, 1)] public float dh = 0.1f;
 [Range(0, 1)] public float ds = 0.1f;
 [Range(0, 1)] public float dv = 0.1f;
 
 float h, s, v, hp, sp, vp;
 
 void Update()
 {
     Color.RGBToHSV(
         webcamtexture.GetPixel(x,y), 
         out h, 
         out s,
         out v
     );
 
     var hueChanged = $$anonymous$$athf.Abs(h - hp) > dh;
     var satChanged = $$anonymous$$athf.Abs(s - sp) > ds;
     var valChanged = $$anonymous$$athf.Abs(v - vp) > dv;
 
     if (hueChanged || satChanged || valChanged)
         Debug.LogFormat("Pixel {0},{1} changed!");
 
     hp = h;
     sp = s;
     vp = v;
 }

avatar image TreyH TreyH · Jan 17, 2019 at 02:56 PM 0
Share

Note that Hue needs to account for wrapping. This was just a quick and dirty block to help you move in the right direction, but you'll need to make sure things like 0.95 and 0.04 are correctly evaluated as being within 0.1 of each other.

avatar image TreyH TreyH · Jan 17, 2019 at 03:12 PM 0
Share

Converting to comment, didn't see that you wanted to detect movement in general. That is a bit different than pixel comparison.

What problem are you trying to solve? What does your ideal outcome look like here?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sh_code · Jan 17, 2019 at 02:48 PM

this is a very difficult problem even when you're using libraries. don't attempt to implement something like this for yourself, use a CV (computer-vision) or AR (augmented-reality) library, such as OpenCV, or Vuforia (comes built-in unity), or metaio, or something like that.

the pixel(s) always change value even if covered with a sheet of paper because of signal noise.

in general, whatever are you trying to do with the webcam image, and recognizing anything meaningful from it, is going to be hard even using the libraries I mentioned above.

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
avatar image
0

Answer by xxmariofer · Jan 17, 2019 at 02:50 PM

They are returning true cause even if it black it will probably be a bit darker some times, try the code but using a float and discard if the difference between old and new texture are lower than those

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

101 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

Related Questions

WebCameTexture.Play() Could not connect pins - RenderStream() 5 Answers

Take photo from webcam (not grab frame from video stream) 0 Answers

WebCam Texture scaling on iPhoneX 1 Answer

Webcamtexture at 1080p 50fps produces black image 1 Answer

WebCamTexture.device on the Kindle Fire returning a camera 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