usr/share/halcon/examples/phytec-halcon-examples/ 0000755 0000000 0000000 00000000000 14066545174 021137 5 ustar root root usr/share/halcon/examples/phytec-halcon-examples/start.sh 0000755 0000000 0000000 00000004247 14066563612 022637 0 ustar root root #!/bin/sh
# Run HALCON phyCAM scripts on your Arm-based Linux computer.
# Copyright (C) 2021 PHYTEC, Mainz, Germany
platform=$(uname -m)
case "$platform" in
aarch64)
arch="aarch64-linux"
;;
armv7l)
arch="armv7a-linux"
;;
x86_64)
echo "HPeek is available for Arm-based platforms only." >&2
echo "" >&2
exit 1
;;
*)
echo "Your platform $platform is not supported." >&2
echo "" >&2
exit 1
;;
esac
echo ""
echo " If the first start after reboot, an initialize of camera is necessary"
echo " ====================================================================="
echo " 1 = monochrome camera @ Cam_0 port"
echo " 2 = color camera @ CAM_0 port"
echo " 3 = initialize done"
read SET_MEDIA_CTL
echo " Your select = $SET_MEDIA_CTL"
case $SET_MEDIA_CTL in
"1") ./init_bw_phyCAM-M_v4l_device.sh ;;
"2") ./init_col_phyCAM-M_v4l_device.sh ;;
"3") ;;
*) ;;
esac
#if [ ! -f "camera_device.txt" ]; then
# echo " Could not find camera_device.txt." >&2
# echo " Please initialized you connected camera." >&2
# echo " Check if the connected camera is activated in the bootloader?" >&2
# echo "" >&2
# exit 1
#fi
echo " Choose the example script"
echo " ========================="
echo " 1 = show monochrome live stream"
echo " 2 = show color live stream"
echo " 3 = save a jpg monochrome image"
echo " 4 = save a jpg color image"
echo " 5 = optical flow, read from monochrome camera"
echo " 6 = optical flow, read from color camera"
read SET_MEDIA_CTL
echo " Your select = $SET_MEDIA_CTL"
case $SET_MEDIA_CTL in
"1") script=grabb_bw_and_show_phyCAM_via_gst.hdev ;;
"2") script=grabb_col_and_show_phyCAM_via_gst.hdev ;;
"3") script=grabb_bw_and_save-jpg_phyCAM_via_gst.hdev ;;
"4") script=grabb_col_and_save-jpg_phyCAM_via_gst.hdev ;;
"5") script=bw_optical_flow.hdev ;;
"6") script=col_optical_flow.hdev ;;
*) script=grabb_bw_and_show_phyCAM_via_gst.hdev ;;
esac
if [ ! -f $script ]; then
echo " Could not find '$script'." >&2
echo " Please change to the HALCON examples/phytec directory and run ./start.sh there." >&2
echo "" >&2
exit 1
fi
source ./init_display.sh
echo " Running '../../bin/$arch/hpeek $script'"
../../bin/$arch/hpeek $script
usr/share/halcon/examples/phytec-halcon-examples/bw_optical_flow.hdev 0000755 0000000 0000000 00000013600 14066565435 025166 0 ustar root root
* This example program shows how to use optical_flow_mg to compute the
* optical flow in an image sequence and how to segment the optical flow.
* This example program shows how to grab PHYTEC phyCAM streams
* Please run "source ./init_bw_phyCAM_v4l_device_halcon.sh" or
* "source ./init_col_phyCAM_v4l_device_halcon.sh" depend of camera typ befor first start
* for change the resolution, adapt the "init_xx_phyCAM_v4l_device_halcon.sh"
dev_update_off ()
dev_close_window ()
* pipeline for bayer-color camera
MyGstPipeStr := '#PIPE# v4l2src device=/dev/video0 ! video/x-bayer,width=1280,height=720,format=grbg ! bayer2rgbneon ! videoconvert ! video/x-raw,format=RGBA,width=1280,height=720 ! appsink'
* pipeline for monochrome camera
MyGstPipeStr := '#PIPE# v4l2src device=/dev/video0 ! video/x-raw,width=1280,height=720,format=GRAY8 ! videoconvert ! video/x-raw,format=RGBA,width=1280,height=720 ! appsink'
MyGstPipeStr := '#PIPE# v4l2src device=/dev/video0 ! appsink'
MyGstPipeStr := '#PIPE# v4l2src device=/dev/video0 ! video/x-bayer,width=1280,height=720,format=grbg ! appsink'
MyGstPipeStr := '#PIPE# v4l2src device=/dev/video0 ! video/x-raw,width=1280,height=720,format=GRAY8 ! appsink'
open_framegrabber ('Video4Linux2', 1, 1, 0, 0, 0, 0, 'default', -1, 'default', -1, 'default', 'default', 'video0', -1, -1, AcqHandle)
open_framegrabber ('GStreamer', 1, 1, 0, 0, 0, 0, 'default', -1, 'default', -1, 'false', 'default', MyGstPipeStr, 0, -1, AcqHandle)
* Get the current/default pipeline.
grab_image (Image1, AcqHandle)
get_image_size (Image1, Width, Height)
Runtimes := {}
ImgScale := 1.0
DisplayWidth := Width
DisplayHeight := Height
if (DisplayWidth != [])
WindowWidth := DisplayWidth * ImgScale
WindowHeight := DisplayHeight * ImgScale
else
WindowWidth := Width * ImgScale
WindowHeight := Height * ImgScale
endif
open_window (0, 0, WindowWidth, WindowHeight, 0, 'visible', '', WindowHandle)
set_part_style (WindowHandle, 1)
open_window (0, 0, WindowWidth, WindowHeight, 0, 'buffer', '', WindowHandleBuffer)
set_part_style (WindowHandle, 1)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
set_part (WindowHandle, 0, 0, WindowHeight-1, WindowWidth-1)
read_image (LogoImage, 'halcon_embedded_mvtec-logo-rgb_300px.jpg')
get_image_size (LogoImage, WidthLogo, HeightLogo)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, Height - HeightLogo, Width - WidthLogo, HomMat2DTranslate)
affine_trans_image (LogoImage, ImageAffineTrans, HomMat2DTranslate, 'constant', 'true')
* Set the display parameters for the vector field.
set_paint (WindowHandleBuffer, ['vector_field',6,1,2])
set_draw (WindowHandleBuffer, 'margin')
grab_image_async (Image2, AcqHandle, -1)
FactorZoom := 0.1
while (true)
grab_image_async (Image1, AcqHandle, -1)
mirror_image (Image1, Image1, 'column')
* Compute the optical flow.
count_seconds (Ts)
zoom_image_factor (Image1, Image1Zoomed, FactorZoom, FactorZoom, 'constant')
zoom_image_factor (Image2, Image2Zoomed, FactorZoom, FactorZoom, 'constant')
rgb1_to_gray (Image1Zoomed, GrayImage1)
rgb1_to_gray (Image2Zoomed, GrayImage2)
optical_flow_mg (GrayImage1, GrayImage2, VectorField, 'fdrig', 1.2, 1, 8, 5, 'default_parameters', 'accurate')
* Segment the optical flow vector field.
threshold (VectorField, Region, 2, 10)
connection (Region, ConnectedRegions)
shape_trans (ConnectedRegions, RegionTrans, 'rectangle1')
union1 (RegionTrans, RegionUnion)
connection (RegionUnion, ConnectedRegions1)
shape_trans (ConnectedRegions1, RegionTransFinal, 'rectangle1')
count_seconds (Te)
Runtimes := Runtimes.concat({(Te-Ts)*1000})
* Display the current image of the sequence. Note that this means that
* the optical flow vectors will also be displayed at the "end" of the movement
* of the objects in the image.
set_part (WindowHandleBuffer, 0, 0, Height-1, Width-1)
disp_obj (Image2, WindowHandleBuffer)
disp_obj (ImageAffineTrans, WindowHandleBuffer)
* Display the optical flow.
set_part (WindowHandleBuffer, 0, 0, (Height*FactorZoom)-1, (Width*FactorZoom)-1)
set_color (WindowHandleBuffer, 'yellow')
set_line_width (WindowHandleBuffer, 1)
disp_obj (VectorField, WindowHandleBuffer)
* Display the segmented optical flow.
set_color (WindowHandleBuffer, 'green')
set_line_width (WindowHandleBuffer, 3)
disp_obj (RegionTransFinal, WindowHandleBuffer)
set_part (WindowHandleBuffer, 0, 0, Height-1, Width-1)
dump_window_image (Image, WindowHandleBuffer)
* overpaint_gray (Image, ImageAffineTrans)
* copy_rectangle (WindowHandleBuffer, WindowHandle, 0, 0, WindowHeight, WindowWidth, 0, 0)
disp_obj (Image, WindowHandle)
* Copy the current image to the previous image of the sequence.
copy_obj (Image1, Image2, 1, 1)
* Simulate mouse click
set_system ('simulate_mouse_click',['left',[DisplayWidth,DisplayHeight]*1.2])
endwhile
convert_vector_to_tuple (Runtimes, Result)
* Image Acquisition 01: Do something
close_framegrabber (AcqHandle)
usr/share/halcon/examples/phytec-halcon-examples/grabb_bw_and_save-jpg_phyCAM_via_gst.hdev 0000755 0000000 0000000 00000002431 14066554403 031105 0 ustar root root
* This example program shows how to grab PHYTEC phyCAM streams
* Please run "source ./init_bw_phyCAM_v4l_device_halcon.sh" or
* "source ./init_col_phyCAM_v4l_device_halcon.sh" depend of camera typ befor first start
* for change the resolution, adapt the "init_xx_phyCAM_v4l_device_halcon.sh"
set_system('do_low_error','stderr')
*
MyGstPipeStr := '#PIPE# v4l2src device=/dev/video0 ! appsink'
MyGstPipeStr := '#PIPE# v4l2src device=/dev/video0 ! video/x-raw,width=1280,height=720,format=GRAY8 ! appsink'
* open the camera:
open_framegrabber ('GStreamer', 1, 1, 0, 0, 0, 0, 'default', -1, 'default', -1, 'false', 'default', MyGstPipeStr, 0, -1, AcqHandle)
grab_image_start (AcqHandle, -1)
*
* if use AEC, more then one image shot for rigth exposure
for i := 1 to 5 by 1
grab_image_async (Image, AcqHandle, -1)
endfor
* Save the current image of the sequence.
write_image (Image, 'jpeg', 0, 'phyCAM-image.jpg')
close_framegrabber (AcqHandle)