Skip to content

Commit

Permalink
getBase64Image now using blocking data
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Jun 29, 2024
1 parent ba77f29 commit b491462
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/myrobotlab/service/LLM.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,15 @@ public static void main(String[] args) {
webgui.autoStartBrowser(false);
webgui.startService();

boolean done = true;
if (done) {
return;
}

// llm.config.url = "http://fast:11434/v1/chat/completions";
// response = llm.getResponse("Hello, why is the sky blue?");
// System.out.println(response.msg);

for (int i = 0; i < 100; ++i) {

while (cv.getBase64Image() == null) {
Expand Down
39 changes: 24 additions & 15 deletions src/main/java/org/myrobotlab/service/OpenCV.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public class OpenCV extends AbstractComputerVision<OpenCVConfig> implements Imag
int vpId = 0;

transient CanvasFrame canvasFrame = null;

private final Set<String> removeFilters = new HashSet<>();

class VideoProcessor implements Runnable {
Expand Down Expand Up @@ -211,24 +211,24 @@ synchronized public void run() {
}

processVideo(data);

// process removal/release of filters
if (removeFilters.size()> 0) {
if (removeFilters.size() > 0) {
Map<String, OpenCVFilter> newFilters = new LinkedHashMap<>();
// create new filter set for thread safety
for (OpenCVFilter filter: filters.values()) {
for (OpenCVFilter filter : filters.values()) {
if (removeFilters.contains(filter.name)) {
continue;
}
newFilters.put(filter.name, filter);
}

// stop/release filters to be removed
for(String removeMe: removeFilters) {
for (String removeMe : removeFilters) {
log.warn("releasing {}", removeMe);
filters.get(removeMe).release();
}

// assign the new set of filters w/o the removed ones
filters = newFilters;
removeFilters.clear();
Expand Down Expand Up @@ -1094,12 +1094,20 @@ public String getGrabberType() {
public IplImage getImage() {
return lastImage;
}

public String getBase64Image() {
return getBase64Image(3500);
}

public String getBase64Image(int timeout) {
try {
final ByteArrayOutputStream os = new ByteArrayOutputStream();
String imgType = "jpg";
BufferedImage bi = getDisplay();
OpenCVData d = getOpenCVData(timeout);
if (d == null) {
return null;
}
BufferedImage bi = d.getDisplay();
if (bi != null) {
ImageIO.write(bi, imgType, os);
os.close();
Expand Down Expand Up @@ -1265,11 +1273,12 @@ private void processVideo(OpenCVData data) throws org.bytedeco.javacv.FrameGrabb
// latency use the original ts from before fetch image and the filters
// !
webImage.ts = data.getTs();
// try {
// FileIO.toFile(String.format("image-%s-%d-base64.txt", getName(), frameIndex), webImage.data);
// } catch(Exception e) {
// error(e);
// }
// try {
// FileIO.toFile(String.format("image-%s-%d-base64.txt", getName(),
// frameIndex), webImage.data);
// } catch(Exception e) {
// error(e);
// }
broadcast("publishWebDisplay", webImage);
}

Expand Down Expand Up @@ -1683,7 +1692,7 @@ public ImageData saveImage() {
invoke("publishImage", image);
return image;
}

/**
* @param name
* remove a filter by name
Expand Down

0 comments on commit b491462

Please sign in to comment.