Asked — Edited

Camera Control From My Plugin

Hello , I want to control the JD camera from my visual studio plugin , I've try the following code but it doesn't work EZ_B.Camera.GetVideoCaptureDevices();

plz I need ur help as soon as possible .


ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

PRO
Synthiam
#1  

All of my plugins are open source, so you can look to see how to do various things.

Look at the source code of this plugin: https://synthiam.com/redirect/legacy?table=plugin&id=50

In order to get the current active camera device, you need to get the current active camera control. The code in that example plugin will scan all controls and get the first instance of a camera control. The "attach" button will attach to the first camera control and use its video frame event.

Make sure you unregister the video frame event when your control disposes or closes.

PRO
USA
#2  

sample code to connect to an EZB Camera, save the picture in the desktop.

don't forget to change ezbAddress variable to your EZB IP address.


namespace EZConsoleApplication1
{
    using System;
    using System.IO;
    using System.Threading;
    using EZ_B;

    internal class Program
    {
        private static string ezbAddress = "192.168.18.85";
        private static EZB ezb;
        private static EventWaitHandle startEvent;
        private static Camera camera;

        private static void Main(string[] args)
        {
            using (ezb = new EZB())
            {
                Console.WriteLine("Connecting to EZ-B");
                ezb.Connect(ezbAddress);

                if (!ezb.IsConnected)
                {
                    Console.WriteLine("Unable to connect to EZ-B");
                    return;
                }

                using (camera = new EZ_B.Camera(ezb))
                {
                    startEvent = new EventWaitHandle(false, EventResetMode.AutoReset);

                    camera.OnNewFrame += CameraOnNewFrame;
                    camera.StartCamera(new ValuePair("EZB://" + ezbAddress), 160, 120);

                    //wait 10 seconds for the first camera frame
                    if (startEvent.WaitOne(10000))
                    {
                        //Save an image on the desktop
                        camera.SaveImageAsJPEG(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "capture1.jpg"));
                        camera.StopCamera();
                    }
                    else
                    {
                        Console.WriteLine("Unable to connect to camera");
                    }
                }

                Console.WriteLine("Done!");
                ezb.Disconnect();
            }
        }

        private static void CameraOnNewFrame()
        {
            startEvent.Set();
        }
    }
}

PRO
Synthiam
#3  

ptp, that is for creating a standalone application. The OP is asking about creating a plugin. A plugin runs in the ARC environment, which will have a project with an existing camera control.

The plugin will search and locate an existing camera control and attach itself to it.

PRO
USA
#4  

you are right, my bad!

PRO
Synthiam
#5  

No problem:) Here's a tutorial step i created for the plugin to use the existing camera control: https://synthiam.com/Tutorials/UserTutorials/146/17

#6  

thanks ptp you give my what I need ,that's to control the JD camera from visual studio but i need to control it from my form . would you help me to do that ?

#7  

DJ Sures you didn't get what I mean . I need to control the camera from my plugin . I mean ,I want to display what the robot see from my own windows form ,Did you get it ?

PRO
USA
#8  

you have both examples, standalone application and ARC skill plugin.

There are more advantages if you migrate to an ARC skill plugin: you will have more robust ecosystem, you can mix custom scripting (EZ-Script) you can communicate with other plugins you have more API's, and you have a modular approach, for example breaking a complex problem in multiple plugins.

Also DJ's plugins are open source, so it's easy to improve an existing idea.

Whatever road you choose, it's ok.

If you are using a Form, the standalone code still works, let us know if you need more help.

#9  

ptp

yup , i still need ur help . I've run ur code but it gave me the following error in the image , User-inserted image for that i asked u to control the camera from my windows form . for example i try to put ur code in a button in my form but unfortunately , it didn't work

PRO
Synthiam
#11  

Are you sure that you're creating a plugin? Or a standalone application?

Also, do not use ptp's code. Use the tutorial that i posted.

In the tutorial, to draw on a Panel, for example...


void Camera_OnNewFrame() {

  if (_cameraControl == null)
    return;

  using (Graphics pnlG = panel2.CreateGraphics())
    pnlG.DrawImage(_cameraControl.Camera.GetOutputBitmap.ToManagedImage(false), 0, 0, panel2.Width, panel2.Height);
}

#12  

DJ. He is not building an ARC plugin. Needs SDK instructions (I would provide but answering from phone).

PRO
Synthiam
#13  

If you're not building a plugin, then read the README.TXT that is included in the SDK. You're not following the instructions. All files from the SDK package must be copied into your output folder. Read the instructions.

If you are making a plugin, then read the tutorial and use the code i presented.

PRO
USA
#14  

Windows Form Application Example code:

https://github.com/ppedro74/ez-robot-form-application

It takes a Picture, displays in the form and it saves to the desktop.

User-inserted image

Cheers,

PRO
USA
#15  

Attention to:

DJ wrote:

Quote:

read the README.TXT that is included in the SDK. You're not following the instructions. All files from the SDK package must be copied into your output folder. Read the instructions.

User-inserted image

Platform target: must be x86 (32 bits)

Some dlls are needed in the application folder you have two options:

  1. copy the dlls "packages/EZ_B.dll.2015.05.20.00" to the application folder i.e. (bin/debug or bin/release)

  2. add application references to the missing dlls: e.g. VS>Project>Add Existing Item>(look for the missing DLL)>ADD VS>Project>dll properties>"Copy to Output Directory" Change to "Copy if newer"

personally i like the option 2, you are aware of the dlls needed, but the safest option is the 1).

#16  

thanks ptp for your help ,I appreciate you effort ^_^

#17  

hello DJ Sures , plz I need ur code that display what robot see as in the picture User-inserted image

plz send it to me as soon as possible.

PRO
Synthiam
#18  

It's a jpg file... here it is:

User-inserted image

#19  

DJ Sures , I need the code that display what robot see not the jpg file sick sick I need the visual studio code

#20  

There are samples in the SDK. http://synthiam.com/Products/ARC or http://synthiam.com/Products/ARC

Alan

PRO
Synthiam
#21  

Or, if it's a plugin as the title says, view any of the examples or the code example that I had already provided to you.

You have more than you need - as there's even code written for you and pasted in this thread. There is literally nothing else anyone can do outside of flying to your city and sitting in front of your keyboard to physically type it. Please use the information provided to you.

You have been very unclear if this is an sdk program or a plugin. The title is misleading to the type of application that you are making. Either way, information for both those has been provided.

PRO
Synthiam
#22  

*warning: this is your final warning or your account will be banned. You have created second accounts and immaturely created numerous threads on the same topic with multiple accounts. If this behavior continues, your account and ip will be banned. You have a history of doing this on ezrobot forum. Including demanding posts and even posts with pages of emojis. You will be banned from any further simular behavior.

I have removed your other threads from duplicate accounts.

#23  

okay DJ Sures but they aren't two account for the same person we're one team in a graduation project & when I failed to get my needs , my team leader ahmed logged in with his account. u can check my LinkedIn account to see that I'm an IT student. thanks for being so aggressive.

note :- we connect our jd robot from this lap & our whole project is on it so, the same IP is normal.

PRO
Synthiam
#24  

You and your team lead need to work on maturity and respect. Absolutely more assistance than is necessary has been provided to you. There is nothing more humanly possible that can be given to you.

  1. You still have yet to respond to whether the project is sdk or plugin.

  2. sdk code has been presented to you in this thread

  3. sdk package contains nearly 50 examples, most of which contain camera

  4. plugin code has been provided to you in this thread AND the plugin tutorial has been updated to include an entire new section of how to access the camera

  5. plugin and sdk code to draw the camera image to a panel has been provided to you in this thread

PRO
USA
#25  

@shaimaabes,

Most of us have been students too (in my time it was much more difficult) limited internet, and no money to buy IT books, we hang out in public book stores, reading, copying code & information from store's books until a clerk pointed the exit door.

Windows Form Application Example code post #15: the initial code have everything you need to handle the EZB camera video frames.

i took a small brake to improve the code, please check the github repository.

the code shows video feed in the form application, is not rocket science, but if you have doubts before, i really hope they will be gone.

i had also some extra concurrency code to prevent future issues.

User-inserted image

PRO
Synthiam
#26  

@ptp i should add that the OnNewFrame event will never execute twice. The event is indeed executed on a worker thread (not ui), however it will never execute concurrent or require locks.

If your OnNewFrame event runs for a lengthy time, any new frames that arrive will be skipped. The OnNewFrame event will only be raised when a new frame arrives and there is no current instance of the OnNewFrame event running.

#27  

Eng ,@ptp :)

thanks verrrrrrrrrryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy muchhhhhhhhhhhhhhhhhhhh for ur kindness & ur smart behavior when u answering me , u are an excellent man , & no words would give u ur value .

yeah nw is mush better for students to learn but u know that sometimes our minds get stopped .

anyway I appreciate ur words , kindness & ur effort :)

User-inserted image

PRO
USA
#28  

yep, i assumed that

this is a good advice (re quote, to enforce the importance):

Quote:

If your OnNewFrame event runs for a lengthy time, any new frames that arrive will be skipped. The OnNewFrame event will only be raised when a new frame arrives and there is no current instance of the OnNewFrame event running.

the concurrency issues are: OneSecondTimer_Tick (measuring) the fps counter, is a Windows Form Timer so the execution is in the UI thread and changing a counter variable same used for OnFrame event, minor detail to enforce two threads using the same variable.

OnNewFrame, Invoke to the UI/Control/Thread (i assumed it wasn't the ui thread, and you confirmed).

like i said no "rocket science code", but if you follow the good practices (even with simple code) it will save your neck later if you keep adding code :)

@DJ: One little detail, the camera's close event is being called twice, i double checked the code... not a big deal, i noticed due the output debug.