UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Participant nittax
Participant
1,167 Views
Registered: ‎11-10-2017

can't get image from PCam 5C on Ubuntu running on ZYBO-Z7-20

Jump to solution

Hi, 

I want to get image from PCam 5C on Ubuntu running on ZYBO-Z7-20.

I refer to this repository, and it works fine when I use pre-built image and rootfs.

I changed the setting of petalinux project.

- I Changed rootfs setting from initramfs to SD boot

 

When I use kernel and rootfs which I built on petalinux, I could get image from pcam.

But I want to use Ubuntu OS, so I changed rootfs to ubuntu rootfs, which can be donwloaded from here.

On Ubuntu, I could not get image, and got errors from yavta, which is V4L2 camera utility.

Error opening device /dev/video0: neither video capture nor video output supported.

Looking at the implementation of yavta, it seemed that an error occurred when acquiring device attributes using ioctl.

I also checked at the loaded kernel modules (driver?) by "ls /sys/module" command, but it seemed that there were no modules that failed to load.

 

 

do not know why cameras can not be used due to differences in rootfs
The content of the error is abstract and I do not know where the problem is (driver? library?)

 

The result of "ls /sys/module" command is the following.

 

adv7604
block
brd
cadence_wdt
can
can_gw
configfs
cpufreq
cpuidle
cryptomgr
drm
drm_kms_helper
e1000e
edac_core
ehci_hcd
fb
firmware_class
hid
i2c_algo_bit
input_polldev
ipv6
ir_kbd_i2c
kernel
keyboard
lockd
loop
mmcblk
module
nfs
ov5640
printk
psmouse
r8169
rc_core
rcupdate
rcutree
scsi_mod
sdhci
sg
sit
sparse_keymap
spurious
srcutree
sunrpc
tcp_cubic
usbcore
usbhid
usb_storage
videobuf2_core
videobuf2_v4l2
vt
watchdog
workqueue
xilinx_drm
xilinx_drm_dp
xilinx_uartps
xilinx_video
xz_dec

Any ideas to solve this problem?

Thanks in advance.

 

 

0 Kudos
1 Solution

Accepted Solutions
Explorer
Explorer
1,051 Views
Registered: ‎10-21-2015

Re: can't get image from PCam 5C on Ubuntu running on ZYBO-Z7-20

Jump to solution

Hi,

 

Have you tried it using v4l2-ctl?

 

There is no such problem in my Ubuntu OS.

root@localhost:~# v4l2-ctl --all         
Driver Info (not using libv4l2):
	Driver name   : xilinx-vipp
	Card type     : video_cap output 0
	Bus info      : platform:video_cap:0
	Driver version: 4.9.0
	Capabilities  : 0x84201000
		Video Capture Multiplanar
		Streaming
		Extended Pix Format
		Device Capabilities
	Device Caps   : 0x04201000
		Video Capture Multiplanar
		Streaming
		Extended Pix Format
Priority: 2
Format Video Capture Multiplanar:
	Width/Height      : 1920/1080
	Pixel Format      : 'YUYV'
	Field             : None
	Number of planes  : 0
	Flags             : 
	Colorspace        : sRGB
	Transfer Function : Default
	YCbCr Encoding    : Default
	Quantization      : Default
root@localhost:~# 
root@localhost:~# v4l2-ctl --list-formats
ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture Multiplanar
	Pixel Format: 'YUYV'
	Name        : YUYV 4:2:2

	Index       : 1
	Type        : Video Capture Multiplanar
	Pixel Format: 'UYVY'
	Name        : UYVY 4:2:2

	Index       : 2
	Type        : Video Capture Multiplanar
	Pixel Format: 'NM16'
	Name        : Y/CbCr 4:2:2 (N-C)

	Index       : 3
	Type        : Video Capture Multiplanar
	Pixel Format: 'NV16'
	Name        : Y/CbCr 4:2:2

root@zynq:~# media-ctl -d /dev/media0 -V '"ov5640 2-003c":0 [fmt:UYVY/'1920x1080'@1/'15' field:none]'
root@zynq:~# media-ctl -d /dev/media0 -V '"43c60000.mipi_csi2_rx_subsystem":0 [fmt:UYVY/'1920x1080' field:none]'
root@zynq:~# v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=YUYV --stream-mmap --stream-count=1 --stream-to=test.raw
<

By the way, there is some problem in digilent prebuilt image

(https://github.com/Digilent/Petalinux-Zybo-Z7-20/releases/tag/v2017.4-2)

After kernel booting, ethernet connection crash linux system in both petalinux and ubuntu.

 

I attach the script making my Ubuntu OS.

7 Replies
Explorer
Explorer
1,100 Views
Registered: ‎10-21-2015

Re: can't get image from PCam 5C on Ubuntu running on ZYBO-Z7-20

Jump to solution

Hi,

Can you compare dmesg outputs between petalinux and ubuntu os ?

When you change petalinux to ubuntu, you should copy /lib/modules/$(uname -r)

0 Kudos
Participant nittax
Participant
1,076 Views
Registered: ‎11-10-2017

Re: can't get image from PCam 5C on Ubuntu running on ZYBO-Z7-20

Jump to solution

Thank you for reply.

 

I attach dmesg of petalinux and ubuntu os.

I compare them, but I could not find big difference.

And I copied loadable modules located at /lib/modules/$(uname -r) from petalinux rootfs to ubuntu rootfs. 

 

So, what is wrong..?

 

 

0 Kudos
Explorer
Explorer
1,045 Views
Registered: ‎10-21-2015

Re: can't get image from PCam 5C on Ubuntu running on ZYBO-Z7-20

Jump to solution

Hi,

 

Have you tried it using v4l2-ctl?

 

There is no such problem in my Ubuntu OS.

root@localhost:~# v4l2-ctl --all         
Driver Info (not using libv4l2):
	Driver name   : xilinx-vipp
	Card type     : video_cap output 0
	Bus info      : platform:video_cap:0
	Driver version: 4.9.0
	Capabilities  : 0x84201000
		Video Capture Multiplanar
		Streaming
		Extended Pix Format
		Device Capabilities
	Device Caps   : 0x04201000
		Video Capture Multiplanar
		Streaming
		Extended Pix Format
Priority: 2
Format Video Capture Multiplanar:
	Width/Height      : 1920/1080
	Pixel Format      : 'YUYV'
	Field             : None
	Number of planes  : 0
	Flags             : 
	Colorspace        : sRGB
	Transfer Function : Default
	YCbCr Encoding    : Default
	Quantization      : Default
root@localhost:~# 
root@localhost:~# v4l2-ctl --list-formats
ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture Multiplanar
	Pixel Format: 'YUYV'
	Name        : YUYV 4:2:2

	Index       : 1
	Type        : Video Capture Multiplanar
	Pixel Format: 'UYVY'
	Name        : UYVY 4:2:2

	Index       : 2
	Type        : Video Capture Multiplanar
	Pixel Format: 'NM16'
	Name        : Y/CbCr 4:2:2 (N-C)

	Index       : 3
	Type        : Video Capture Multiplanar
	Pixel Format: 'NV16'
	Name        : Y/CbCr 4:2:2

root@zynq:~# media-ctl -d /dev/media0 -V '"ov5640 2-003c":0 [fmt:UYVY/'1920x1080'@1/'15' field:none]'
root@zynq:~# media-ctl -d /dev/media0 -V '"43c60000.mipi_csi2_rx_subsystem":0 [fmt:UYVY/'1920x1080' field:none]'
root@zynq:~# v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=YUYV --stream-mmap --stream-count=1 --stream-to=test.raw
<

(https://github.com/Digilent/Petalinux-Zybo-Z7-20/releases/tag/v2017.4-2)

After kernel booting, ethernet connection crash linux system in both petalinux and ubuntu.

I attach the script making my Ubuntu OS.

 

 

0 Kudos
Explorer
Explorer
1,052 Views
Registered: ‎10-21-2015

Re: can't get image from PCam 5C on Ubuntu running on ZYBO-Z7-20

Jump to solution

Hi,

 

Have you tried it using v4l2-ctl?

 

There is no such problem in my Ubuntu OS.

root@localhost:~# v4l2-ctl --all         
Driver Info (not using libv4l2):
	Driver name   : xilinx-vipp
	Card type     : video_cap output 0
	Bus info      : platform:video_cap:0
	Driver version: 4.9.0
	Capabilities  : 0x84201000
		Video Capture Multiplanar
		Streaming
		Extended Pix Format
		Device Capabilities
	Device Caps   : 0x04201000
		Video Capture Multiplanar
		Streaming
		Extended Pix Format
Priority: 2
Format Video Capture Multiplanar:
	Width/Height      : 1920/1080
	Pixel Format      : 'YUYV'
	Field             : None
	Number of planes  : 0
	Flags             : 
	Colorspace        : sRGB
	Transfer Function : Default
	YCbCr Encoding    : Default
	Quantization      : Default
root@localhost:~# 
root@localhost:~# v4l2-ctl --list-formats
ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture Multiplanar
	Pixel Format: 'YUYV'
	Name        : YUYV 4:2:2

	Index       : 1
	Type        : Video Capture Multiplanar
	Pixel Format: 'UYVY'
	Name        : UYVY 4:2:2

	Index       : 2
	Type        : Video Capture Multiplanar
	Pixel Format: 'NM16'
	Name        : Y/CbCr 4:2:2 (N-C)

	Index       : 3
	Type        : Video Capture Multiplanar
	Pixel Format: 'NV16'
	Name        : Y/CbCr 4:2:2

root@zynq:~# media-ctl -d /dev/media0 -V '"ov5640 2-003c":0 [fmt:UYVY/'1920x1080'@1/'15' field:none]'
root@zynq:~# media-ctl -d /dev/media0 -V '"43c60000.mipi_csi2_rx_subsystem":0 [fmt:UYVY/'1920x1080' field:none]'
root@zynq:~# v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=YUYV --stream-mmap --stream-count=1 --stream-to=test.raw
<

By the way, there is some problem in digilent prebuilt image

(https://github.com/Digilent/Petalinux-Zybo-Z7-20/releases/tag/v2017.4-2)

After kernel booting, ethernet connection crash linux system in both petalinux and ubuntu.

 

I attach the script making my Ubuntu OS.

Participant nittax
Participant
1,026 Views
Registered: ‎11-10-2017

Re: can't get image from PCam 5C on Ubuntu running on ZYBO-Z7-20

Jump to solution

@hokim Thank you very much! I could get image by the command you told me!!

v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=YUYV --stream-mmap --stream-count=1 --stream-to=test.raw

But why I couldn't get image using yavta? Do you have any ideas? 

I wrote some codes using ioctl() to get image, but it also didn't work. I'm going to refer to the implementation of v4l2-ctl...

 

And I use Ubuntu16.04 and have no problem related to ethernet connection.

0 Kudos
Explorer
Explorer
1,001 Views
Registered: ‎10-21-2015

Re: can't get image from PCam 5C on Ubuntu running on ZYBO-Z7-20

Jump to solution

Hi,

 

Write your code referring to https://gist.github.com/maxlapshin/1253534

Participant nittax
Participant
900 Views
Registered: ‎11-10-2017

Re: can't get image from PCam 5C on Ubuntu running on ZYBO-Z7-20

Jump to solution

@hokim Sorry for late reply.

I still don't understand the reason why I can't get image from yavta command on Ubuntu.

 

But you taught me the way to get image using v4l2-ctl command, So I finally get image from my own code by referring to v4l2-ctl command implementation!!!

 

This is my code.

I hope this code will help someone.

 

/*
Target board: ZYBO Z7-20
Kernel&Circuit:https://github.com/Digilent/Petalinux-Zybo-Z7-20
Distribution: Ubuntu 16.04
https://rcn-ee.com/rootfs/eewiki/minfs/ubuntu-16.04.3-minimal-armhf-2017-10-07.tar.xz

Thanks to @hokim.
Xilinx Form: https://forums.xilinx.com/t5/Embedded-Linux/can-t-get-image-from-PCam-5C-on-Ubuntu-running-on-ZYBO-Z7-20/m-p/882879#M28057

Before run this code, you must run the following commands.
sudo media-ctl -d /dev/media0 -V '"ov5640 2-003c":0 [fmt:UYVY/'1920x1080'@1/'15' field:none]'
sudo media-ctl -d /dev/media0 -V '"43c60000.mipi_csi2_rx_subsystem":0 [fmt:UYVY/'1920x1080' field:none]'
*/
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <iostream>
#include <fstream>
#include <linux/videodev2.h>

#define FMT_NUM_PLANES 3
#define WIDTH 1920
#define HEIGHT 1080

struct buffer_addr_struct{
  void *start[FMT_NUM_PLANES];
  size_t length[FMT_NUM_PLANES];
} *buffers;

static int xioctl(int fd, int request, void *arg){
	int r;
	do {
		r = ioctl (fd, request, arg);
		if (request == VIDIOC_DQBUF) {
			std::cout << "r : " << r << std::endl;
		}
	} while (-1 == r && EINTR == errno);
	return r;
}

int main() {

	unsigned char *buffer;

	// 1. Open Video Device.
	int fd;
	fd = open("/dev/video0", O_RDWR, 0);
	if (fd == -1){
	    std::cout << "Failed to open video device." << std::endl;
	    return 1;
	}

	// 2. Querying video capabilities.
	struct v4l2_capability caps;
	memset(&caps, 0, sizeof(caps));
	if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &caps)){
		std::cout << "Failed to query capabilities." << std::endl;
	    return 1;
	}
	std::cout << "bus_info	: " << caps.bus_info << std::endl;
	std::cout << "card		: " << caps.card << std::endl;
	std::cout << "driver	: " << caps.driver << std::endl;
	std::cout << "version	: " << caps.version << std::endl;

	// 3. Format Specification.
	{
		struct v4l2_format fmt;
		memset(&(fmt), 0, sizeof(fmt));

		fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
		fmt.fmt.pix_mp.width = WIDTH;
		fmt.fmt.pix_mp.height = HEIGHT;
		fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_YUYV;
		fmt.fmt.pix_mp.field = V4L2_FIELD_NONE;
		
		if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt)){
			std::cout << "Failed to set pixel format." << std::endl;
			return 1;
		}
	}

	int num_planes;
	struct v4l2_requestbuffers reqbuf;
	const int MAX_BUF_COUNT = 3;/*we want at least 3 buffers*/
	
	// 4. Request Buffer
	{
		memset(&(reqbuf), 0, sizeof(reqbuf));
		reqbuf.count = FMT_NUM_PLANES;
		reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
		reqbuf.memory = V4L2_MEMORY_MMAP;

		if (-1 == xioctl(fd, VIDIOC_REQBUFS, &reqbuf)){
			std::cout << "Failed to request buffer." << std::endl;
			return 1;
		}
		if (reqbuf.count < MAX_BUF_COUNT){
			std::cout << "Not enought buffer memory." << std::endl;
			return 1;
		}
		std::cout << "reqbuf.count : " << reqbuf.count << std::endl;

		buffers = (buffer_addr_struct*) calloc(reqbuf.count, sizeof(*buffers));
		assert(buffers != NULL);
				  
	}

	// 5. Query Buffer
	{
		for(int i = 0; i < reqbuf.count; i++){ 

		struct  v4l2_plane planes[FMT_NUM_PLANES];
		struct  v4l2_buffer buf;
		memset(&(buf), 0, sizeof(buf));
		memset(planes, 0, sizeof(planes));
		buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
		buf.memory = V4L2_MEMORY_MMAP;
		buf.m.planes = planes;
		buf.length = FMT_NUM_PLANES;
		buf.index = i;
		if(-1 == xioctl(fd, VIDIOC_QUERYBUF, &buf)){
			std::cout << "Failed to query buffer." << std::endl;
			return 1;
		}
		num_planes = buf.length;
		std::cout << "buf.length : " << buf.length << std::endl;
		std::cout << "buf.m.offset : " << buf.m.offset << std::endl;

		for(int j = 0; j < num_planes; j++){
			buffers[i].length[j] = buf.m.planes[j].length;
			std::cout << "buf.m.planes[j].length : " << buf.m.planes[j].length << std::endl;
			buffers[i].start[j] = mmap(NULL, buf.m.planes[j].length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, buf.m.planes[j].m.mem_offset);
			if(MAP_FAILED == buffers[i].start[j]){
				std::cout << "mmap error" << std::endl;
			}
			std::cout << "buffers[i].start[j] : " << buffers[i].start[j] << std::endl; 
		
		}
	}

	// 6. Start Streaming
	{
		struct 	v4l2_buffer buf;
		memset(&(buf), 0, sizeof(buf));
		buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
		if(-1 == xioctl(fd, VIDIOC_STREAMON, &buf.type))
		{
			std::cout << "Fail to start Capture" << std::endl;
			return 1;
		}
	}
	char camdata[WIDTH*HEIGHT*2];
	
	struct 	v4l2_buffer buf;
	buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
	buf.memory = V4L2_MEMORY_MMAP;
	buf.index = 0;
	struct v4l2_plane planes[FMT_NUM_PLANES];
	buf.m.planes = planes;
	buf.length = FMT_NUM_PLANES;

	//You can get image repeatedly by this loop
	//while (true) {
		// 7. Capture Image
		{
			// Connect buffer to queue for next capture.
			if (-1 == xioctl(fd, VIDIOC_QBUF, &buf)) {
				std::cout << "VIDIOC_QBUF" << std::endl;
			}

			fd_set fds;
			FD_ZERO(&fds);
			FD_SET(fd, &fds);
			struct timeval tv = {0};
			tv.tv_sec = 2;
			int r = select(fd+1, &fds, NULL, NULL, &tv);

			if(-1 == r){
				std::cout << "Waiting for Frame" << std::endl;
				return 1;
			}
	
			if(-1 == xioctl(fd, VIDIOC_DQBUF, &buf)){
				std::cout << "Retrieving Frame" << std::endl;
				return 1;
			}

		}

		// 8. Store Image in Array
		{
		  for(int j = 0; j < num_planes; j++){
		    memcpy(camdata, buffers[0].start[j], WIDTH*HEIGHT*2);
		  }
		}

		// 9. Save YUYV raw Image
		// You can convert raw image to png by this code.
		// https://gist.github.com/lp6m/209ab987e2bc25261d8b1c6ef1f3777d
		{
		  FILE* fp = fopen("./camdata.dat", "wb");
		  fwrite(camdata, sizeof(camdata), 1, fp);
		  fclose(fp);
		}

	//}
	
	// 10. Turn off streaming.
	if (-1 == xioctl(fd, VIDIOC_STREAMOFF, &buf.type)) {
		std::cout << "VIDIOC_STREAMOFF" << std::endl;
	}

	return 0;
}

 

0 Kudos