Navigation

    CreatiCode Scratch Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode

    The Video Sensing Extension

    2D Blocks
    1
    1
    467
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • info-creaticode
      CreatiCode last edited by admin

       

      Introduction

       

      The Video Sensing Extension lets your project detect motion using your device’s camera. This means your program can respond when something moves in front of the camera!


       

       

      How to detect motion in the camera video?

       

      Think of a video as a bunch of pictures shown very quickly — like a flipbook. Each picture is called a frame. When something moves in front of the camera, it looks different in each frame.

      For example, when you move an apple slowly across the camera, the frames will show it shifting positions:

      2e530080-acc2-41be-8283-9ba261656506.gif

       

      We can compare two frames to see which parts of the image have changed. In the two frames below, the apple has moved slightly to the bottom right:

      c4c731af-73f3-4ac7-9e7b-27357c793b36.gif
       
      Each image is made up of tiny squares called pixels. The apple is just a group of pixels with red and brown colors.

      14a86a5d-cd9a-4049-9a1c-9a9ec2c8e0d9.gif

      By checking how many pixels have changed between two frames, we can measure how much motion has occurred.

       

      How to add the Video Sensing Extension?

       

      To add the video extension to a project, you click the “Add Extension” button below the blocks categories and then select “Video Sensing” from the extension library. Make sure you give permission to our playground to use your camera.

      6cb65098-2a5f-4b48-9fde-db25edc30a0d.gif

       

      🚫 Can’t See the Camera Video?

       

      If you do not see the camera video, then you should check if the camera is blocked. Try to find this camera icon in the top navigation bar on the right:

      ad2cb49e-d79b-4f77-bc84-9a7b8e69a7b0.png

      Once the extension is added and the camera is working, a live video feed should appear on the stage.

       

      Fix Camera Permission Issue

       

      If the camera is somehow blocked, you can fix it by changing the permission settings and then reloading the page:

      f6ff0367-94c4-42a5-8b60-388c0c9a1bd1.gif

       
       

      The Video Sensing Blocks

       

      The video sensing extension includes:

      • 1 hat block (which triggers scripts),
      • 1 reporter block (which gives a value).
      • 2 stack blocks (blocks you can attach to other blocks),

      Let’s look at each of them below.


       

       
       

      “Turn video (On/Off/On Flipped)”

       

      9b7e6df6-94a9-44a9-9b97-03d08a3cdb15.png

      This block lets you control whether the camera video appears on the stage:

      • On: shows the live video.
      • Off: hides the video.
      • On flipped: shows the video, but flips it horizontally (like a mirror).

       
      baede7ac-4a5b-4719-a543-1d1ea220878d.gif

       
       

      Set Video Transparency

       

      When the camera video is shown, it appears behind your sprites but in front of the backdrop. Use this block to change how see-through the video is:

      ca68020b-6bed-470d-a475-47f60d7a9c77.png

      • 100 = fully transparent (only the backdrop shows),
      • 0 = fully solid (the video hides the backdrop),
      • 1–99 = a mix—you can see the backdrop through the video.

      55eac469-b815-4c56-bbbe-2350120ef7ca.gif

       
       

      “Video (motion/direction) on (sprite/stage)”

       

      This reporter block gives back a number based on what the camera sees:

      26ed9eee-bc64-435e-a9d4-da825a56c546.png

      The first input allows you to select if you want to know the value of motion or direction.

      • Motion: this block will report a number that represents how many pixels (tiny boxes that compose the image) in the camera video have moved between the last frame and the current frame. Note that this is not about the distance or speed of the movement, but the size of the area where some motion is detected.

      • Direction: this block will tell us the average direction of the detected movement. For example, when most of the pixels are moving to the right, the direction would be around 90 degrees.

       
      The second input allows you to select the current sprite or the entire stage.

      • Sprite: checks for motion only under that sprite. Motion outside this sprite will be ignored.

      ![be1ac278-7f0b-43b7-b0b6-49fc7ef6ab06.gif](https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/be1ac278-7f0b-43b7-b0b6-49fc7ef6ab06.gif

       

      • Stage: check for motion anywhere in the camera video.

      ![c8635f66-5854-4b66-97ba-e10f72bce77b.gif](https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/c8635f66-5854-4b66-97ba-e10f72bce77b.gif

       
       

      When Motion > (threshold)

       

      This block runs only if enough motion is detected.

      126bcffb-9702-4e1b-8e90-5a8737e48a98.png

      It takes one input: a threshold number. If the amount of motion under the sprite is greater than this number, the block runs.

      • Use something like 10 as the threshold.
      • Don’t use 0, because the camera always sees a little bit of “noise” or tiny changes.

       

      Example Program

       
      In this example, the apple only moves up when your hand moves under it. If your hand isn’t near it, nothing happens.

      6b27dd5c-37c5-40c1-ad37-cd297200af5c.gif

      1 Reply Last reply Reply Quote 0
      • First post
        Last post