Giter Site home page Giter Site logo

Error for savepath about compose-uvc-camera HOT 15 OPEN

davewest2 avatar davewest2 commented on June 27, 2024
Error for savepath

from compose-uvc-camera.

Comments (15)

shanerodrigues avatar shanerodrigues commented on June 27, 2024 1

@ColtonIdle Sorry, I don't really know the intricacies of the library itself. The library maintainer would definitely be able to assist you with that.

from compose-uvc-camera.

ColtonIdle avatar ColtonIdle commented on June 27, 2024

I was able to write to apps internal storage via

  cameraClient.captureImage(
      object : ICaptureCallBack {
          override fun onBegin() {
              TODO("Not yet implemented")
          }

          override fun onComplete(path: String?) {
              TODO("Not yet implemented")
          }

          override fun onError(error: String?) {
              TODO("Not yet implemented")
          }
      },
      path = context.filesDir.path.plus("/myimage.jpg"))

from compose-uvc-camera.

davewest2 avatar davewest2 commented on June 27, 2024

Thanks ColtonIdle! Image saved and accessible, great stuff. I have now found, however, that the captureImage function seems to fire automatically when the app starts up. The capture image button does not appear to trigger the captureImage function so the image captured on start up is never overwritten. I don't actually need this function so it's usable as is, but it would be useful to understand why this is happening and to correct it, perhaps for future purposes.

from compose-uvc-camera.

ColtonIdle avatar ColtonIdle commented on June 27, 2024

weird. i didn't see that problem. im away on holiday right now, but i would just comment out that function and make sure that it indeed isn't triggered and more and then trace through the code to make sure that callback is only called on button press. let me know after you try that and i can try to debug, but it might just be something simple.

from compose-uvc-camera.

shanerodrigues avatar shanerodrigues commented on June 27, 2024

hey @davewest2 sorry for getting back to you so late, I'm glad to hear that Colton was able to help you out. Are you still facing the captureImage issue?

from compose-uvc-camera.

davewest2 avatar davewest2 commented on June 27, 2024

from compose-uvc-camera.

shanerodrigues avatar shanerodrigues commented on June 27, 2024

I'd suggest trying to mimic the structure that's implemented in this demo. I believe the button only worked when it was within that function with the cameraPreview or otherwise, the onClick wouldn't fire.

from compose-uvc-camera.

ColtonIdle avatar ColtonIdle commented on June 27, 2024

@davewest2 I forgot about this actually, but if you can post some code maybe we can take a look. Without that its shooting in the dark

from compose-uvc-camera.

davewest2 avatar davewest2 commented on June 27, 2024

Absolutely. I don't think the world is ready for my code, but here goes! I've taken the code in the repo and made the following changes in addition to the path as suggested by Shane. I'm using the Coil library to asynchronously get the image from the captureImage function and place it on the screen (I haven't concerned myself with positioning at the moment as ultimately I don't want to see anything in the app):

Change to the myApp composable:

@Composable
fun MyApp(){
    val context = LocalContext.current
    Box(modifier = Modifier
        .fillMaxWidth(0.5f)
    ) {
        UVCCameraPreview(rememberCameraClient(context))
    }
    Box(modifier = Modifier.fillMaxWidth(0.5f)) {
        DisplayImage()
    }
}

And added this composable to retrieve and display the image from the captureImage function.

@Composable
fun DisplayImage() {
    Column(
        Modifier
            .fillMaxSize()
            .fillMaxHeight()
            .fillMaxWidth(),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {

        val file = File(LocalContext.current.filesDir, "myimage.jpg")
        val contents = file.absolutePath
        val imgFile = File(contents)
        var imgBitmap: Bitmap? = null
        if (imgFile.exists()) {
            imgBitmap = BitmapFactory.decodeFile(imgFile.absolutePath)
        }

        AsyncImage(
            model = ImageRequest.Builder(LocalContext.current)
                .data(imgBitmap)
                .build(),
            placeholder = painterResource(id = R.drawable.library_image),
            contentDescription = "Image",
            modifier = Modifier
                .fillMaxWidth()
                .height(200.dp)
                .padding(10.dp)
        )
    }
}

from compose-uvc-camera.

ColtonIdle avatar ColtonIdle commented on June 27, 2024

@davewest2 what's the current error/exception that you're getting? I wonder if it has to do with your target sdk level in your build.gradle

I'm playing around in my app and noticed if I went from target 30 down to 29, then it crashes on the save function as well. not sure why.

from compose-uvc-camera.

ColtonIdle avatar ColtonIdle commented on June 27, 2024

@shanerodrigues can you confirm which android version you tested on? really dumbfounded why downgrading my target api level breaks this. lol

from compose-uvc-camera.

shanerodrigues avatar shanerodrigues commented on June 27, 2024

@shanerodrigues can you confirm which android version you tested on? really dumbfounded why downgrading my target api level breaks this. lol

I've only tested it on Android 9 and in the demo, the targetSDK is set to 28. Unfortunately, I do not have access to an external USB camera, so I'm unable to test out the application myself.

from compose-uvc-camera.

ColtonIdle avatar ColtonIdle commented on June 27, 2024

Okay, seems like android 9 with 3.2.8 of the usblib work. but if you want android 12+ you need the 3.3.3 lib.

@shanerodrigues do you happen to know how i can get this to work without writing to disk? id love a callback of just a byte[]. not sure if that's something more appropriate to ask of the libusb maintainer.

from compose-uvc-camera.

ColtonIdle avatar ColtonIdle commented on June 27, 2024

all good. cheers. this repo is a great starting off point w/ compose

from compose-uvc-camera.

davewest2 avatar davewest2 commented on June 27, 2024

Apologies both, have been off cycling in Belgium! So I'll need to put in some more debug tags to more easily see the sequence of events but there are warnings and information lines regarding the save path but no error as such that I can discern. I've uploaded an Excel file of the logcat - first mention of the UVCCameraTest package is at 14:56:59.747 (line 331) with captureImage at 14.57.18.154 and onBegin called at 14:57:18:206. Apologies for the formatting - I need to work on exporting logcat data!
logcat UVCCameraTest .xlsx

from compose-uvc-camera.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.