Giter Site home page Giter Site logo

Comments (13)

IamSierraCharlie avatar IamSierraCharlie commented on July 28, 2024

Hi,
Yeah definitely a way to do it.
It will involve some code change. I'd theorised as to how it might work, but never implemented it because I had no need for it. I'm on the road until the following weekend, I'll look at it when I get home.

It's difficult to look at the code on my phone, but I expect you'll need to create a list of possible cameras then create an instance of each camera. There is not currently any code that does this. I'll write something shortly. If you can't wait and were looking for where to start, I'd review the camsApi file.

from contrastech_python_api_for_linux_and_windows.

IamSierraCharlie avatar IamSierraCharlie commented on July 28, 2024

After taking a bit more time to review my code, its definitely possible to use the code for multiple cameras, but there is a fair bit of work to get it to work. By design, i only made it to work with a single camera.
looking at camsAPI.py, the first camera in the list is assigned to self.campointer after creating a camera instance.

As I write this, I think the best thing to do is either to create a new fork or perhaps a new class that specifically addresses your needs as changes to this code will add more complexity for those that only need an instance for a single camera.

The best way I can see to move forward with multiple cameras would be to:

  1. Create an instance of the camsApi initially
  2. Return a list of possible cameras based around the enumerate_cameras function
  3. Change the existing code or implement a new class so each function takes a new variable which is in fact the pointer of the camera that you wish to control.

I'll have a think about this tonight.

from contrastech_python_api_for_linux_and_windows.

IamSierraCharlie avatar IamSierraCharlie commented on July 28, 2024

Iva added some new code that may help to address multiple cameras - Ive tested it with one camera, but I dont have a second for testing. Please try run GrabDemoMultiCam.py as it stands right now and let me know if you report any errors.
From there assuming it works okay, you should be able to replicate much of that code - for example, where you see this:

api.create_camera_instance(0) 
api.open_camera(0)
api.set_camera_resolution(0, img_width, img_height, img_channels=3, centre_resolution=False) 

and you have more than 1 camera, replicate that code and insert a 1 where the 0 is and that should access the second camera if you have one available.

from contrastech_python_api_for_linux_and_windows.

s91-maker avatar s91-maker commented on July 28, 2024

Hi Steve, I appreciate your effort a lot. Thanks for all the help.
As per your instruction, i tried to test the script(GrabDemoMultiCam.py ), but when cam_id is 0, it's working fine. But when i changed the cam_id to 1 (from 0), it's not working. I tried with connecting 2 cameras and 3 cameras.
error_multicam

I believe working of create_camera_instance function in multicamsApi.py needs to be changed.
If you need any info(as you don't have a 2nd camera to test) in checking script output or any logs..etc, please let me know.
Thanks again for the help.

from contrastech_python_api_for_linux_and_windows.

IamSierraCharlie avatar IamSierraCharlie commented on July 28, 2024

Are you seeing an error?

from contrastech_python_api_for_linux_and_windows.

IamSierraCharlie avatar IamSierraCharlie commented on July 28, 2024

try this code and let me know the result

import cv2
import multicamsApi
import numpy as np

img_width = 640
img_height = 480
channels = 3
target_framerate = 50
framerate_cv2_window = int(1000/target_framerate)
api = multicamsApi.CameraApi(debug=True)
# next, set the list of camera pointers - this will set a count of cameras plus a list of the camera pointers
api.get_camera_list()
''' 
api.camera_count represents a list of cameras that were found when getting the camera list 
api.camera_pointer_list represents a list of the camera pointers - instead of just one camera
'''
print(f'The number of cameras was {api.camera_count}')
# essentially, here, you could loop through a range to set up each camera
# next, create the camera instance
''' repeat these lines below for each camera 0, for the first camera, 1 for the second and so on'''
api.create_camera_instance(0)
api.create_camera_instance(1)

api.open_camera(0)
api.open_camera(1)

api.set_camera_resolution(0, img_width, img_height, img_channels=3, centre_resolution=False)
api.set_camera_resolution(1, img_width, img_height, img_channels=3, centre_resolution=False)

print("setting some properties")
api.property(0, "AcquisitionFrameRate", target_framerate)
api.property(1, "AcquisitionFrameRate", target_framerate)


api.property(0, "DeviceTemperatureSelector", "Sensor")
api.property(1, "DeviceTemperatureSelector", "Sensor")

api.property(0, "TriggerSource", "Software")
api.property(1, "TriggerSource", "Software")

api.property(0, "TriggerSelector", "FrameStart")
api.property(1, "TriggerSelector", "FrameStart")

api.property(0, "AcquisitionMode", "Continuous")
api.property(1, "AcquisitionMode", "Continuous")

api.property(0, "TriggerMode", "On")
api.property(1, "TriggerMode", "On")

api.activate(0)
api.activate(1)

api.property(0, "ExposureAuto", "Off")
api.property(1, "ExposureAuto", "Off")

api.property(0, "ExposureTime", 15000)
api.property(1, "ExposureTime", 15000)

api.property(0, "Brightness", 50)
api.property(1, "Brightness", 50)

print("done!")
brand_name0 = api.property(0, "DeviceVendorName")
brand_name1 = api.property(1, "DeviceVendorName")

model_name0 = api.property(0, "DeviceModelName")
model_name1 = api.property(1, "DeviceModelName")

temp0 = api.property(0, "DeviceTemperature")
temp1 = api.property(1, "DeviceTemperature")

color = list(np.random.random(size=3) * 256)
camera_name = api.property(0, "DeviceUserID")
counter = 0
print('Get sensor width, height')
# where do I get this info from??
# Check in iCentral under "Features" - dont forget to select Guru
sensor_width = api.property(0, "SensorWidth")
sensor_height = api.property(0, "SensorHeight")
print('poop')

while True:
    if counter > target_framerate * 5:
        temp0 = api.property(0, "DeviceTemperature")  # dont grab temp every frame
        temp1 = api.property(1, "DeviceTemperature")  # dont grab temp every frame
        color = list(np.random.random(size=3) * 256)
        counter = 0

    image0 = api.grab_image(0)
    image1 = api.grab_image(1)

    cv2.putText(image0, f'{target_framerate}fps', (img_width - 125, 30), cv2.FONT_HERSHEY_DUPLEX, 1, color)
    cv2.putText(image0, f'Temp {temp0}c', (30, 30), cv2.FONT_HERSHEY_DUPLEX, 1, color)
    cv2.imshow(f'{brand_name0} {model_name0} USB3 Vision Camera => {camera_name}', image0)

    cv2.putText(image1, f'{target_framerate}fps', (img_width - 125, 30), cv2.FONT_HERSHEY_DUPLEX, 1, color)
    cv2.putText(image1, f'Temp {temp1}c', (30, 30), cv2.FONT_HERSHEY_DUPLEX, 1, color)
    cv2.imshow(f'{brand_name1} {model_name1} USB3 Vision Camera => {camera_name}', image1)
    k = cv2.waitKey(framerate_cv2_window)
    counter += 1
    if k == 27:  # Esc key to stop
        break

api.deactivate(0)
api.deactivate(1)

from contrastech_python_api_for_linux_and_windows.

s91-maker avatar s91-maker commented on July 28, 2024

Hi Steve, No, it's not showing any error. It's just shows camera opened and nothing happening after that for next 1-2 secs, and then script exiting.
Capture_3

from contrastech_python_api_for_linux_and_windows.

s91-maker avatar s91-maker commented on July 28, 2024

My guess- when camera id is anything other than 1, the API is not returning the camera instance.
May be we need to write 'create_camera_instance' in separate class or function. I am trying that, will update you.

from contrastech_python_api_for_linux_and_windows.

IamSierraCharlie avatar IamSierraCharlie commented on July 28, 2024

In looking at my code, I can see there are a few issues, but I cant test without that extra camera. I might have one next week. I do have 2, but the second one is on a job. I'll have to borrow it when I'm at the site next week.
Let me know how you go

from contrastech_python_api_for_linux_and_windows.

IamSierraCharlie avatar IamSierraCharlie commented on July 28, 2024

Righto, I managed to get a second camera today. I'll plug it in and see if i can get this s/w working with 2 cameras. Watch this space....

from contrastech_python_api_for_linux_and_windows.

IamSierraCharlie avatar IamSierraCharlie commented on July 28, 2024

After messing around with this - it turns out it is far more complex than I anticipated. When I review MVSDK.py against the SDK.h file, there appears to be quite a few functions missing.

I've have however found the following in the SDK.h file:
/// \~english /// \brief get the pointer of camera object according to camera key /// \param [in] thiz this pointer /// \param [in] pCameraKey camera key /// \return Success:camera pointer, Failure:NULL GENICAM_Camera* (*getCamera)(struct GENICAM_System *thiz,const char * pCameraKey);

From what I can see, this will allow you to get a camera using the camera key.
What is the camera key?
I have managed to call the getKey function on both cameras I have and it returns:

b'ContrasTech:CameraSerial'

By rights, you should then be able to call getCamera and use these keys.
I've not yet been able to get this to work as yet.

from contrastech_python_api_for_linux_and_windows.

IamSierraCharlie avatar IamSierraCharlie commented on July 28, 2024

Okay, finally worked out the problem here - it was an issue with MVSDK.py.
I didn't really look into the actual issue, but after reviewing code shared by Contrastech I was able to determine that their file was different to the one I was using so I just did a copy / paste - how lazy of me.....I should be better than than and tried to understand the issue, but I don't have time.

At least now, when you iterate through the camera list, it is working as advertised. Additionally, each cameras XML file is downloaded which is positive - I added the camera serial number to the XML to differentiate between each camera.

Further more, if you go to the camsApi.py file - take a look at lines, 400 thru 404. Essentially, all you need to do is select the camera index from camera_list for the coinciding camera.

This is the limit of the scope of this issue for me.
It will be up to you to create your own instance for each camera and then call it to take images, etc.

Please give it a try to ensure you can call each camera from your camera list.
If I don't hear anything negative in the next 2 weeks, I'll close this out as I need to return the second camera I borrowed to its rightful owner.

EDIT: I realise that this probably doesn't show you how to do "multiple camera connections", but the underlying issue of not being able to access each camera from the list is now solved.

from contrastech_python_api_for_linux_and_windows.

IamSierraCharlie avatar IamSierraCharlie commented on July 28, 2024

Fundamentally working
Refer to the following files:
GrabDemoMultiCam.py
multicamsApi.py

image

This will need some more work, but there you can grab from multiple cameras.
Perhaps you may need to take this code and work out a way to run each camera in its own thread or process so that there is no blocking of image grabbing. Each camera currently needs to wait its turn to grab an image so I think that as you ask for more images in more cameras, you will eventually hit a bottle neck? More testing is definitely needed

from contrastech_python_api_for_linux_and_windows.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.