Ask Your Question

JR_'s profile - activity

2020-10-18 08:30:20 -0600 received badge  Famous Question (source)
2016-05-21 00:23:21 -0600 received badge  Notable Question (source)
2015-05-28 03:16:33 -0600 received badge  Popular Question (source)
2013-08-07 19:06:02 -0600 asked a question Convert imencode output buffer to string or byte array

Hello,

I've encoded an webcam image using the following Python code:

result,encimg=cv2.imencode('.jpg', img, [1,95])

In order to send the image over the network it has to be converted into a string or byte array (and vice versa on the receiving end). Any idea's on how to do this?

Thanks in advance and with best regards.

2013-08-07 17:35:56 -0600 commented question Error during image decoding (imdecode) using python

Problem solved!! I removed everything related to open cv and reinstalled it..... It seemed to be using opencv from simplecv....

2013-08-01 18:22:48 -0600 received badge  Student (source)
2013-08-01 14:59:38 -0600 asked a question Select "Video Source" dialog when running code on seperate thread

Hello,

When I run the following code on python the main thread the pictures are displayed correctly:

def picture(self):

    self.capture = cv2.VideoCapture(0)
    cv2.namedWindow("camera")

    framecount = 30
    imagecounter = 0
    bytescounter = 0

    starttime = time.time()

    while self.picturerunning:

        result, img = self.capture.read()

        if result == True:
            cv2.imshow("camera", img)
            cv2.imwrite('temp.jpg', img, [1, 95])
            cv2.waitKey(1)

            read_bytes = open('temp.jpg', 'rb').read()

            bytescounter = bytescounter + len(read_bytes)
            imagecounter = imagecounter + 1

        if imagecounter >= framecount:
            elapsedtime = (time.time() - starttime)

            fps = (framecount / elapsedtime)
            transferspeed = (((bytescounter / 1000) / elapsedtime))

            self.logger.debug('average fps: ' + str(round(fps, 2)))
            self.logger.debug(
                'elapsed time: ' + str(round(elapsedtime, 2)))
            self.logger.debug(
                'average transfer speed (KB/s): ' + str(round(transferspeed, 2)))
            self.logger.debug('----------------------------------------')

            bytescounter = 0
            imagecounter = 0

            starttime = time.time()

However, when I run the same code running on a separate thread the Select "Video Source" dialog is displayed. When I select the correct webcam a black screen is displayed.

I use win7 and have tried following webcams but without success.

2013-07-31 08:15:07 -0600 commented question Error during image decoding (imdecode) using python

I've also tried another system (also Win 7) and here it also doesn't work... Ik can try XP and Ubuntu? Can it be an OS dependent problem?

2013-07-30 14:32:49 -0600 commented question Error during image decoding (imdecode) using python

Hi berak,

Then I get :

TypeError: Required argument 'buf' (pos 3) not found

2013-07-30 13:31:18 -0600 commented question Error during image decoding (imdecode) using python

As an additional note: First I had problems with the following piece of code:

encode_param=[int(cv2.IMWRITE_JPEG_QUALITY), 90] AttributeError: 'module' object has no attribute 'IMWRITE_JPEG_QUALITY'

I fixed this using the following code:

result, encimg = cv2.imencode('.jpg', img, [1, 90])

2013-07-30 10:52:29 -0600 received badge  Editor (source)
2013-07-30 10:49:59 -0600 asked a question Error during image decoding (imdecode) using python

I use puthon 2.7, windows 7 and opencv 2.4.6. and I try to run the following code:

https://github.com/kyatou/python-opencv_tutorial/blob/master/08_image_encode_decode.py

#import opencv library
import cv2
import sys
import numpy

argvs=sys.argv
if (len(argvs) != 2):
 print 'Usage: # python %s imagefilename' % argvs[0]
 quit()

imagefilename = argvs[1]
try:
  img=cv2.imread(imagefilename, 1)
except:
  print 'faild to load %s' % imagefilename
  quit()

#encode to jpeg format
#encode param image quality 0 to 100. default:95
#if you want to shrink data size, choose low image quality.
encode_param=[1, 90]
result,encimg=cv2.imencode('.jpg',img,encode_param)
if False==result:
  print 'could not encode image!'
  quit()

#decode from jpeg format
decimg=cv2.imdecode(encimg,1)

cv2.imshow('Source Image',img)
cv2.imshow('Decoded image',decimg)
cv2.waitKey(0)
cv2.destroyAllWindows()

I keep getting the following error:

result, encimg = cv2.imencode('.jpg', img, [1, 90]) 
TypeError: 'bool' object is not iterable

I have tried a lot of things: reinstall opencv, convert cv2 to cv code and searched different forums but I keep getting this error. Am I missing something? Is there someone who can run this code without getting the error?

BTW: Other opencv code (taking pictures from webcam) runs without problems....

At the moment I save the image to a temp JPG file. Using the imencode function I want to create the jpg file in the memory.

Thanks in advance and with best regards.