🚧 wip: messing around with getting webcam data into egui
							parent
							
								
									6436ac5ceb
								
							
						
					
					
						commit
						53017cefa1
					
				|  | @ -23,7 +23,7 @@ impl Capture | ||||||
|     { |     { | ||||||
|         let x = Device::open ("/dev/video0")?; |         let x = Device::open ("/dev/video0")?; | ||||||
|         dbg! (x.formats (linuxvideo::BufType::VIDEO_CAPTURE).collect::<Vec <_>> ()); |         dbg! (x.formats (linuxvideo::BufType::VIDEO_CAPTURE).collect::<Vec <_>> ()); | ||||||
|         let x = x.video_capture (PixFormat::new (u32::MAX, u32::MAX, PixelFormat::MJPG))?; |         let x = x.video_capture (PixFormat::new (u32::MAX, u32::MAX, PixelFormat::YUYV))?; | ||||||
|         dbg! (x.format ()); |         dbg! (x.format ()); | ||||||
|         let size_image = usize::try_from (x.format ().size_image ()).unwrap (); |         let size_image = usize::try_from (x.format ().size_image ()).unwrap (); | ||||||
|         let stream = x.into_stream ()?; |         let stream = x.into_stream ()?; | ||||||
|  | @ -57,6 +57,11 @@ impl Capture | ||||||
|             Ok (input.len ()) |             Ok (input.len ()) | ||||||
|         })?) |         })?) | ||||||
|     } |     } | ||||||
|  |     
 | ||||||
|  |     pub fn will_block (&self) -> std::io::Result <bool> | ||||||
|  |     { | ||||||
|  |         self.stream.will_block () | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive (Debug, thiserror::Error)] | #[derive (Debug, thiserror::Error)] | ||||||
|  |  | ||||||
							
								
								
									
										49
									
								
								src/main.rs
								
								
								
								
							
							
						
						
									
										49
									
								
								src/main.rs
								
								
								
								
							|  | @ -127,31 +127,60 @@ fn main() -> Result <(), Error> | ||||||
|     Ok (()) |     Ok (()) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Default)] | struct MyEguiApp { | ||||||
| struct MyEguiApp {} |     img: egui::ColorImage, | ||||||
|  |     texture: Option <egui::TextureHandle>, | ||||||
|  |     capture: capture::Capture, | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| impl MyEguiApp { | impl MyEguiApp { | ||||||
|     fn new(cc: &eframe::CreationContext<'_>) -> Self { |     fn new(_cc: &eframe::CreationContext<'_>) -> Self { | ||||||
|         // Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals.
 |         // Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals.
 | ||||||
|         // Restore app state using cc.storage (requires the "persistence" feature).
 |         // Restore app state using cc.storage (requires the "persistence" feature).
 | ||||||
|         // Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use
 |         // Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use
 | ||||||
|         // for e.g. egui::PaintCallback.
 |         // for e.g. egui::PaintCallback.
 | ||||||
|         Self::default() |         
 | ||||||
|  |         let img = egui::ColorImage::new ([1920,1080], egui::Color32::TEMPORARY_COLOR); | ||||||
|  |         
 | ||||||
|  |         Self 
 | ||||||
|  |         { | ||||||
|  |             img, | ||||||
|  |             texture: None, | ||||||
|  |             capture: capture::Capture::new ().unwrap (), | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl eframe::App for MyEguiApp { | impl eframe::App for MyEguiApp { | ||||||
|    fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { |     fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { | ||||||
|        egui::CentralPanel::default().show(ctx, |ui| { |         egui::CentralPanel::default().show(ctx, |ui| { | ||||||
|            ui.heading("Hello World!"); |             let texture = self.texture.get_or_insert_with(|| | ||||||
|        }); |             { | ||||||
|    } |                 ui.ctx ().load_texture ("my_image", self.img.clone (), Default::default()) | ||||||
|  |             }); | ||||||
|  |             
 | ||||||
|  |             match self.capture.will_block () | ||||||
|  |             { | ||||||
|  |                 Ok (false) => 
 | ||||||
|  |                 { | ||||||
|  |                     self.capture.wait_for_frame(self.img.as_raw_mut()).unwrap (); | ||||||
|  |                     texture.set (self.img.clone (), Default::default ()); | ||||||
|  |                 }, | ||||||
|  |                 _ => (), | ||||||
|  |             } | ||||||
|  |             
 | ||||||
|  |             let texture: &egui::TextureHandle = texture; | ||||||
|  |             
 | ||||||
|  |             ui.heading("Hello World!"); | ||||||
|  |             ui.image (texture, texture.size_vec2()); | ||||||
|  |         }); | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn main_egui () | fn main_egui () | ||||||
| { | { | ||||||
|     let native_options = eframe::NativeOptions::default(); |     let native_options = eframe::NativeOptions::default(); | ||||||
|     eframe::run_native("My egui App", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc)))); |     eframe::run_native("My egui App", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc)))).unwrap (); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| struct ThreadSystem <'a> | struct ThreadSystem <'a> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 _
						_