problem with Snapshot on webcam

3 views (last 30 days)
muhammad faiz
muhammad faiz on 16 Aug 2017
Answered: ProblemSolver on 27 Jun 2023
Hi everyone, I have problem with the snapshot syntax. so, basically, i have this project which use laser distances and camera/webcam for detection. the process is something like this and it is in real time: when laser sensors detect the obstacles, it will instruct camera to get a snapshot of the scenes. Then, as the laser sensors move closer to the obstacles, it will take another snapshot of the scenes. so, the problem is, i always get similar image between snapshot scenes 2 and snapshot scenes 1. I do not know what happen, seems like the camera stuck in viewing the scenes. The snapshot scenes 2 and Snapshot scenes 1 supposed to be different image due to different distance detected. can somebody tell me what is going on? hope you guys understand the problem.
Thank you
  2 Comments
Image Analyst
Image Analyst on 16 Aug 2017
Understood, but there's no way we can fix it. We don't have your code or your laser/camera setup.
muhammad faiz
muhammad faiz on 16 Aug 2017
end
Radio = serial('COM3','BaudRate',9600); % from the distance sensor
fopen(Radio);
Nvalues=1000000000;
Mvalues=1000000000;
k=0;
w=0;
cam=webcam('ManyCam Virtual Webcam');
cam.Resolution='640x360';
while k<Nvalues
Lidar_distance = fscanf(Radio,'%f');
if (Lidar_distance<=8.1)
Image_Ref=snapshot(cam);
while w<Mvalues
second_distance=fscanf(Radio,'%f');
if (second_distance<=7.1)
Image_Current=snapshot(cam);
break;
end
display(second_distance)
w=w+1;
end
end
display(Lidar_distance)
k=k+1;
end
______________________ this is my code (simplified version)

Sign in to comment.

Answers (1)

ProblemSolver
ProblemSolver on 27 Jun 2023
Based on the snippet of the code that you provided:
1) Delay in capturing the second snapshot: It is possible that there is a delay in capturing the second snapshot, causing the camera to capture the same sense as the first snapshot. To address this you can introduce a delay before capturing the snapshot using 'pause' function. For example, you can add 'pause(1)' before capturing 'Image current' to introduce a 1-second delay (Something like this)
if (Lidar_distance <= 8.1)
Image_Ref = snapshot(cam);
while w < Mvalues
second_distance = fscanf(Radio, '%f');
if (second_distance <= 7.1)
pause(1); % Add a delay of 1 second
Image_Current = snapshot(cam);
break;
end
display(second_distance)
w = w + 1;
end
end
2) Camera settings or autofocus: The camera settings or autofocus functionality may be affecting the captured images. Ensure that the camera is properly focused and that the autofocus is disabled if it's causing any issues.
3) Image processing issues: If the captured images still appear similar, it could be due to image processing issues. Make sure you are correctly displaying the captured images (Image_Ref and Image_Current) and not accidentally displaying the same image twice.
Additionally, you can print out the image dimensions (size(Image_Ref) and size(Image_Current)) to verify if the images have different dimensions. If they have the same dimensions, it would suggest that the camera is capturing the same scene for both snapshots.
I hope this helps!

Categories

Find more on Labeling, Segmentation, and Detection in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!