• AVR Freaks

Hot!Reading an image/video in pic32

Author
salyMal
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2017/02/21 10:12:31
  • Location: 0
  • Status: offline
2020/02/26 06:29:26 (permalink)
5 (1)

Reading an image/video in pic32

Hello
 
I have a project which consists in reading an image (to realize simple image processing) in order to be transformed into another microcontroller.
 
I already worked on mplab x ide and I am using two pic32mz2048efh100 
 
My questions:
how to import an image into the micro-controller 1
how to transfer the new image from micro-controller 1 to the second micro-controller 
 
 
PS: the main goal is to transfer a video but I am starting with a simple 'image' for simplicity
please help me first on how to read an image using a micro-controller
Thank you for your time
#1

13 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 18678
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Reading an image/video in pic32 2020/02/26 06:44:12 (permalink)
    4 (1)
    USB memory stick? Other USB? Ethernet? Serial? Bluetooth? parallel? There are many ways.
    #2
    salyMal
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2017/02/21 10:12:31
    • Location: 0
    • Status: offline
    Re: Reading an image/video in pic32 2020/02/26 07:05:34 (permalink)
    0
    hello thank you for your question
     
    if you mean the communication between the two micro-controller, i imagine it's gonna be through GPIO:
    -Sending a bit from port A0 of the first micro-controller (for example) and read this bit in port A1 of the second micro-controller (for example)
     
    - i believe there will be an array of the image and in a for loop equal to the size of the array the first micro-controller sends the elements of the array (binary) and the second micro-controller reads this bit to reconstruct the image
     
    I'm not sure about that idea, but that's what I have in mind till now.
     
     
    #3
    KTrenholm
    Super Member
    • Total Posts : 783
    • Reward points : 0
    • Joined: 2012/08/08 14:04:23
    • Location: Connecticut, USA
    • Status: online
    Re: Reading an image/video in pic32 2020/02/26 09:21:45 (permalink)
    4 (2)
    How do you plan on getting the image onto a microcontroller to begin with?
     
    I recently did a Harmony v3 project reading 24-bit bitmaps from a FAT32 USB Mass Storage Device into DDR RAM on a PIC32MZ and it wasn't too terrible to implement with the File System and USB Host libraries.
     
    A bitmap would be a decent place to start, since they have all the image size and formatting information in a pretty easy to parse header.  Once you have the image data it's just bytes in memory.  You can do whatever you want with it, including sending it over to another microcontroller.
    post edited by KTrenholm - 2020/02/26 09:23:26
    #4
    salyMal
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2017/02/21 10:12:31
    • Location: 0
    • Status: offline
    Re: Reading an image/video in pic32 2020/02/26 09:54:50 (permalink)
    0
    Indeed i dont know how to reat an image yet
    I know it get can be converted to a binary or hexa file but i don't know how yet
    #5
    WaltR
    Super Member
    • Total Posts : 3807
    • Reward points : 0
    • Joined: 2003/11/07 12:38:21
    • Status: offline
    Re: Reading an image/video in pic32 2020/02/26 10:42:46 (permalink)
    5 (2)
    salyMal
    Indeed i dont know how to reat an image yet
    I know it get can be converted to a binary or hexa file but i don't know how yet



    WHERE is this "image" coming from?????????
    This is the big question.
    #6
    ric
    Super Member
    • Total Posts : 27071
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Reading an image/video in pic32 2020/02/26 14:44:14 (permalink)
    5 (2)
    salyMal
    if you mean the communication between the two micro-controller, i imagine it's gonna be through GPIO:
    -Sending a bit from port A0 of the first micro-controller (for example) and read this bit in port A1 of the second micro-controller (for example)

    Are you serious?
    If this is really your programming level, I think you are jumping in way above your knowledge level.
    You need to become adept at handling simple tasks before you start something complex like video processing.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    pippo18
    Junior Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2018/08/16 13:02:07
    • Location: FCUK
    • Status: offline
    Re: Reading an image/video in pic32 2020/02/27 03:31:10 (permalink)
    #8
    salyMal
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2017/02/21 10:12:31
    • Location: 0
    • Status: offline
    Re: Reading an image/video in pic32 2020/02/27 03:56:38 (permalink)
    0
    @WaltR the image is in a folder on my computer and I want to include it in the mplab code to be able to read and send it.
     
     
    Ric yes I'm serious and I worked previously with spi, output compare, timers, interrupts and ADC of a pic and I have been working for 3 years in programming mplab codes so I'm not a bigenner. I suggest GPIO because I have an electronic circuit between the two microcontrollers (one pin of the electronic circuit is connected to the first micro-controller and dedicated to receive the data of the image and a second pin is dedicated to send the received image to the second micro-controller). If you have a better idea, feel free to share it. I know that video processing is more difficult than image processing, that's why I start working on reading and sending an image.
     
    Best regards
    #9
    moser
    Super Member
    • Total Posts : 557
    • Reward points : 0
    • Joined: 2015/06/16 02:53:47
    • Location: Germany
    • Status: offline
    Re: Reading an image/video in pic32 2020/02/27 04:16:59 (permalink)
    5 (1)
    An image is just data. You just need to send data to the other micro-controller. Start with sending a "hello world". As soon as this works, then you can do the next steps.
     
    Some questions you should ask yourself first are:
     
    1) What do you want to do with that video?
    1a) What speed do you need? Do you need realtime? How many bytes/second do you need to transmit a video of what size in realtime?
    1b) Do you need to send only one way, or will there be some data in both directions? Does the sender need a confirmation, that the receiver has correctly received the data?
    2) What is the nature of the hardware and connection?
    2a) Centimeters away on the same board? Or through 100 meter unshielded cable?
    2b) How many lines can you have to connect the two micro-controllers?
    2c) How fast are both micro-controllers? 
    2d) Which communication techniques have some hardware support available at both micro-controllers?
     
    And in particular, the last question means, you should learn about what kind of communication ways are even existing.
     
    If your goal is nothing in particular, but just getting used to PIC32 and video handling, then let the people know, because then they could probably point you to some sources which help you to start.
     
    Ric is right, it seems you have never done anything with micro-controllers. * Controlling single pins manually is of course one way to do it, but usually a pretty bad one. The first problem you will run into with your approach is: When does the first bit end, and the second bit start? When you understand that problem, you might have probably arrived at simple approaches similar or equal like I²C and SPI. The next thing is serial or parallel? And then what about confirmations, or changing the direction of the data flow? Is the speed enough? And what about the big communication solutions like Ethernet or even all the solutions which are actually made for video, ranging from VGA and DVI cables over DisplayPort and HDMI to whatever. And between those extremely simple and complex solutions there is a lot in between, which might also work for you. 
     
    But you haven't told us anything about your goals. Would you also be happy with a solution which takes 5 years to transmit a 10 second long black and white video with 1 frame/second, and 40x30 pixel size within from one micro-controller to the other one? Because so far, that's a completely sufficient solution to your task description.
     
     
    PS: * I saw your last answer after submitting this post. Anyway, this post is not meant to question your skills, but to make you aware, that you are far much to vague about what you want to achieve.
    post edited by moser - 2020/02/27 04:36:43
    #10
    salyMal
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2017/02/21 10:12:31
    • Location: 0
    • Status: offline
    Re: Reading an image/video in pic32 2020/03/01 13:07:46 (permalink)
    1 (1)
    In fact my project is to do laser communication using two micro-controllers. The first micro-controller is conntect to the driver of the laser through one digital data pin (bit 1: laser is on , bit 0: laser is off) and a ground pin. The second micro-controller is connected to the photodiode
    I dont know yet how to configure the digital data pin to transmit the data from the laser towards the photodiode, which module of the micro-controller should i use ?
    ( the image and video are just an example of the transmitted data)
     

    #11
    WaltR
    Super Member
    • Total Posts : 3807
    • Reward points : 0
    • Joined: 2003/11/07 12:38:21
    • Status: offline
    Re: Reading an image/video in pic32 2020/03/02 10:32:00 (permalink)
    5 (1)
    For Optical communication look into a few modulation methods.
    1- use same as used for TV, etc remote controls. Data on the higher frequency carrier.
    2- PSK and recovery to data clock in RX
    3- Manchester encoding. Commonly used on simple OOK RX and optical.
     
    DO Check Microchip's App Notes for info.
     
     
    #12
    GinAli
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2008/09/01 19:01:35
    • Location: Turkiye
    • Status: offline
    Re: Reading an image/video in pic32 2020/03/05 01:28:03 (permalink)
    5 (1)
    KTrenholm
    I recently did a Harmony v3 project reading 24-bit bitmaps from a FAT32 USB Mass Storage Device into DDR RAM on a PIC32MZ and it wasn't too terrible to implement with the File System and USB Host libraries.
     

     
    Hello KTrenholm,
     
    I have posts here https://www.microchip.com/forums/m1067562.aspx #8 and #10
     
    My problem is; however internal images are extremely fast with GFXU_PreprocessImage(...)
    I suppose GFXU_PreprocessImage has no support for externals.
    Harmony(2.06) is terrible to print external RAWs 470*272pix takes around 7seconds. (I am using app_externalMediaRead() from aria_external_resources) 
    Is it possible to give me some more detail? how did you manage copy externals to DDR ?
     
    Thanks in advance
    Oz
    #13
    KTrenholm
    Super Member
    • Total Posts : 783
    • Reward points : 0
    • Joined: 2012/08/08 14:04:23
    • Location: Connecticut, USA
    • Status: online
    Re: Reading an image/video in pic32 2020/03/05 07:55:57 (permalink)
    5 (1)
    ozgurali
    My problem is; however internal images are extremely fast with GFXU_PreprocessImage(...)
    I suppose GFXU_PreprocessImage has no support for externals.
    Harmony(2.06) is terrible to print external RAWs 470*272pix takes around 7seconds. (I am using app_externalMediaRead() from aria_external_resources) 
    Is it possible to give me some more detail? how did you manage copy externals to DDR ?
     
    Thanks in advance
    Oz



    I did it to internal DDR by reading the image from the USB Mass Storage Device manually, creating a GFXU_ImageAsset and filling out the information for my image format.
     
    For a Raw Bitmap:

     
    typedef struct
    {
        /*File System handle of bitmap file*/
        SYS_FS_HANDLE fs_handle;
        uint16_t width;     //image width (pixels)
        uint16_t height;    //image height (pixels)
        uint32_t size;    //total file size as reported by filesystem
        uint32_t px_index;   //starting index of pixel data
    } BITMAP_DATA;
     
        GFXU_ImageAsset ImageAsset;
        uint32_t * ptrImageData = 0xA837E800;  //Image Data location in DDR
        uint32_t * ptrImageTemp = 0xA817E000  //Image Data Staging Location
     
    void PreProcessToDDR(BITMAP_DATA * bmp_info){
     
        /*Reads in entire bitmap file, including the header*/
        uint32_t size = SYS_FS_FileSize(bmp_info->fs_handle);
        size = CLAMP_HIGH(size,MAX_IMAGE_SIZE);    //Constrain to the size of our image buffer
        SYS_FS_FileRead(bmp_info->fs_handle, ptrImageTemp, size);    //Read image from USB_MSD
     
        ImageAsset.header.type = GFXU_ASSET_TYPE_IMAGE;
        ImageAsset.header.dataLocation = GFXU_ASSET_LOCATION_ID_INTERNAL;    //Internal DDR Memory
        ImageAsset.header.dataAddress = (void *)ptrImageTemp;    //pointer to image location in DDR
        ImageAsset.header.dataSize = size;    //Size (in bytes) of image
        
        ImageAsset.format = GFXU_IMAGE_FORMAT_RAW;    //bitmap - raw pixel data
        ImageAsset.width = bmp_info->width;    //read from bitmap header
        ImageAsset.height = bmp_info->height;    //read from bitmap header
        ImageAsset.bufferWidth = DISPLAY_WIDTH;
        ImageAsset.bufferHeight = DISPLAY_HEIGHT;
        ImageAsset.colorMode = GFX_COLOR_MODE_RGB_888;
        ImageAsset.compType = GFXU_IMAGE_COMPRESSION_NONE;
        ImageAsset.flags = GFXU_IMAGE_SUPPORTS_CLIPPING;
        ImageAsset.mask = 0x0;
        ImageAsset.palette = GFX_NULL;
     
        /*Process image to ptrImageData in DDR as RGB88*/
        laUtils_PreprocessImage(&ImageAsset, ptrImageData, GFX_COLOR_MODE_RGB_888, GFX_FALSE, NULL);
    }

     
    PreprocessImage does support processing an image into external memory, but it must be configured to use the interface to the external memory properly.  I think it uses the GFXU_ExternalAssetReader_t type for interfacing.  I have not done that so I can't really be of much help into how that works, but perhaps Harmony has already generated this for you.
     
    Harmony 3 came with an example for external image resources:
    aria_quickstart_ext_res.  Maybe you can find a similar one for H2?
     
    post edited by KTrenholm - 2020/03/05 10:25:31
    #14
    Jump to:
    © 2020 APG vNext Commercial Version 4.5