i want to use my camera instead of ipcam "import camerawrapperToF
from arena_sdk_helper import *
import ctypes
import numpy as np
import torch
import cv2
import sklearn
import torch.nn as nn
import torch.nn.functional as F

global scale_torch, offset_torch, device

def get_scale_and_offet_from_hlt(hlt):
    coordinates = ["CoordinateA", "CoordinateB", "CoordinateC"]
    scale = np.ones((hlt.nodemap["Height"].value, hlt.nodemap["Width"].value, 4))
    offset = np.zeros((hlt.nodemap["Height"].value, hlt.nodemap["Width"].value, 4))
    for c in range(len(coordinates)):
        hlt.nodemap["Scan3dCoordinateSelector"].value = coordinates[c]
        scale[:, :, c] = hlt.nodemap["Scan3dCoordinateScale"].value
        offset[:, :, c] = hlt.nodemap["Scan3dCoordinateOffset"].value
    global scale_torch, offset_torch
    scale_torch = torch.from_numpy(scale).float()
    offset_torch = torch.from_numpy(offset).float()
    return scale, offset

def convert_raw_buffer_to_xyz_i(buffer_hlt):
      global scale_torch, offset_torch
      pdata_16bit = ctypes.cast(buffer_hlt.pdata, ctypes.POINTER(ctypes.c_uint16))
      image = np.ctypeslib.as_array(pdata_16bit, shape=(480, 640, 4))
      image_torch = torch.from_numpy(image.astype(np.float32)).float()
      converted_image = image_torch * scale_torch + offset_torch
      image_xyz = converted_image[:, :, :3].numpy()
      image_i = (image_torch[:, :, 3] / image_torch[:, :, 3].max() * 255).numpy().astype(np.uint8)
      #cv2.imshow("Some Man",image_i)
      #cv2.waitKey(0)
      #print('image_xyz shape:', image_xyz.shape, " \ndata:", image_xyz[:, :, 2])
      #cv2.imshow("Some Man",image_xyz)
      #cv2.waitKey(0)
      return image_xyz, image_i


def convert_xy_to_depth(x, y):
    global device
    buffer = device.get_buffer()
    image_xyz, image_show = convert_raw_buffer_to_xyz_i(buffer)
    return image_xyz[y, x, 2]

def initialize():
    global device
    # identifier can be i.e. SN, MAC address, IP address, User Defined Name
    device = create_devices(["223400146"])
   
        #device = devices[i]
    device.nodemap["PtpEnable"].value = True
    device.nodemap["AcquisitionStartMode"].value = "PTPSync"
    device.nodemap["PTPSyncFrameRate"].value = 5.0
    device.nodemap["GevSCPD"].value = 800
    device.nodemap["GevSCFTD"].value = 1 * 50000000  # 50 ms in ns
    device.nodemap["Scan3dCommunicationChannel"].value = 1  
    device.nodemap["Scan3dConfidenceThresholdEnable"].value = False
     
    print('Scan3dOperatingMode:', device.nodemap['Scan3dOperatingMode'].value)
    
    get_scale_and_offet_from_hlt(device)
    device.start_stream()
    buffer = device.get_buffer()
    print('buffer:',buffer.width, buffer.height, buffer.bits_per_pixel)
    print(convert_raw_buffer_to_xyz_i(buffer))
    
    #if i < 2:
        # only available for Helios cameras:

    #free()  # this lets the cameras go again to make it available for other applications.
    
    
if "__main__" == __name__:
    initialize()
    while True:
        buffer = device.get_buffer()
        image_xyz, image_show = convert_raw_buffer_to_xyz_i(buffer)
        #cv2.imshow("Some Man",image_show)
        #cv2.waitKey(0)
        image_show = cv2.cvtColor(image_show, cv2.COLOR_GRAY2RGB)
        for y in range(3*0):
            for x in range(2):
            #line = ' '.join([str(image_xyz[(y+1)*100, (x+1)*100, 2]) for x in range(5)])
            #print(line)
                YY = (y+1) *100
                XX = (x+1) *200

                cv2.rectangle(image_show, (XX - 3, YY - 3), (XX + 3, YY + 3), (0, 255, 0), 2)
                cv2.putText(image_show, "{:.1f}".format(image_xyz[YY, XX, 2]/10, image_xyz[YY, XX, 0]/10, image_xyz[YY, XX, 1]/10),
                                (XX + 10, YY + 10),
                                cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)

        XX = 310
        YY = 100
        for XX, YY in [[310, 100], [295, 105]]:
                cv2.rectangle(image_show, (XX - 3, YY - 3), (XX + 3, YY + 3), (0, 255, 0), 2)
                cv2.putText(image_show, "{:.1f}".format(image_xyz[YY, XX, 2]/10, image_xyz[YY, XX, 0]/10, image_xyz[YY, XX, 1]/10),
                                (XX + 10, YY + 10),
                                cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)
                print(f"{XX}/{YY} -> {image_xyz[YY, XX, 0]/10, image_xyz[YY, XX, 1]/10, image_xyz[YY, XX, 2]/10}")
        device.requeue_buffer(buffer)
        cv2.imshow("Depth Distance",image_show)
        cv2.waitKey(1)
        
        time.sleep(0.1)

    free()