Unsupported image object while using Tesseract - python-3.7

When I run this code I'm getting the following error:
pytesseract.pytesseract.tessaract_cmd = r'F:\Tesseract-OCR\tesseract.exe'
video_capture = cv2.VideoCapture(0)
while True:
frame = video_capture.read()
if frame is None:
break
text = pytesseract.image_to_string(frame, lang="eng_fast", config="--psm 7")
print(int(len("len of text is: ", text)))
print(text)
cv2.imshow('Video', frame)
if waitKey(1) & 0xff == ord('q'):
break
video_capture.release()
cv2.destroyAllwindows()
TypeError: "Unsupported image object".
Error is in the "text" line.
Can someone help

video_capture.read method return two variables, as stated here:
ret if the current captures frame read correctly
frame: Current frame
By saying:
frame = video_capture.read()
Your frame variables containes: ret and frame
If you are sure all frames return correctly, use
_, frame = video_capture.read()
Otherwise:
ret, frame = video_capture.read()
Partial-Code:
video_capture = cv2.VideoCapture(0)
while True:
ret, frame = video_capture.read()
.
.

Related

How to get value at a point of line extended - TradingView Pine script

Im using the code below to draw a line:
//#version=4
simplesma = sma(close, 14)
var line3 = line.new(bar_index[0], high[0], bar_index, low, extend = extend.right)
line.set_xy1(line3, bar_index[5], simplesma[5])
line.set_xy2(line3, bar_index[3], simplesma[3])
That line has been drawn using 2 points in the history.
And then I use this code to draw a plot
price_point = line.get_price(line3,bar_index)
plot(price_point, title='Price', color=#ffcc00, transp=30)
Im trying to display the value on a label but the following code does not work:
var label3 = label.new(bar_index, high, text = "Value: "+ tostring(price_point, "#.########"), style = label.style_label_lower_left, color=#ffcc00, textcolor=#ff0000)
label.set_xy(label3,bar_index, price_point)
Can you please help me to show it on label ?
The variable price_point is the value at the current bar (bar_index). You don't need to use the function tostring().
Oh I found it.
var label3 = label.new(bar_index, high, text = "", style = label.style_label_lower_left, color=#ffcc00, textcolor=#ff0000)
label.set_xy(label3,bar_index, price_point)
label.set_text(label3, "Value: "+ tostring(price_point, "#.########"))

Weird behaviour with dialog boxes and variables in Lua script for Lightroom plugin

I'm writing a Lightroom plugin using the Lightroom SDK/API in the Lua language. I'm new to Lua. I've found a situation where my script only works if a Lightroom dialog box (LrDialogs.message("random message")) is present in one function. Without it the function falls over at a later point claiming a string variable (Image.dr in the last LrDialogs.message) is 'nil' as opposed to the normal value it has when the plugin is working properly. Anyone know what's going wrong? Here's the relevant code segment:
------ read output file for exif and write to LR metadata ------
function parseOutput(outputFilePath)
LrDialogs.message("random message")
local tblOutput = {} --to hold the output exif (1 column table, i.e. an array)
local tblImages = {} --to hold the images and their relevant metadata
for line in io.lines(outputFilePath) do
line = removeWhitespaces(line)
table.insert(tblOutput, line)
end
local str = table.remove(tblOutput) --remove last line in table/file (it's log info, not exif)
tblImages = extractExif(tblOutput) --pick out the exif key/value pairs and add to Image objects
end
function extractExif(tblOutput)
local Image = {} --pseudo object to hold metadata for each image
local tblImages = {}
local blnFlag = false
local intCount = 0
for k,v in pairs(tblOutput) do --iterate through each value in the table
if string.find(v, "^=.+") then
--test if new image other than the first one
if blnFlag == true then
--add Image to tblImages and then clear Image object
table.insert(tblImages, Image)
--Image = {} --don't technically need this
blnFlag = false
--LrDialogs.message("inside blnFlag test")
end
i, j = string.find(v, "/") -- **** MAC ONLY. Back slash for Windows *****
Image.filePath = string.sub(v, i) --returns the file path
Image.name = string.match(v, "([^/]+)$") --return the file name
blnFlag = true
elseif string.find(v, "ISO") ~= nil then
Image.iso = string.match(v, "%a+:(.+)") --get text (i.e value) to right of colon
elseif string.find(v, "Film") ~= nil then
Image.filmSim = string.match(v, "%a+:(.+)")
elseif string.find(v, "Setting") ~= nil then
Image.drMode = string.match(v, "%a+:(.+)")
elseif (string.find(v, "Auto") ~= nil) or (string.find(v, "Development") ~= nil) then
Image.dr = string.match(v, "%a+:(.+)")
else
end
end
LrDialogs.message(Image.name .. Image.iso .. Image.filmSim .. Image.drMode .. Image.dr)
return tblImages
end
function removeWhitespaces(str)
return string.gsub(str, "%s", "")
end

Label position not returning correctly

I am trying to determine a label's position so as to place other labels below.
When I try to output the data on a specific label I get 0.000 as a output on log.
Any idea why this is happening?
...
postTextLabel.text = postText;
postTextLabel.frame = CGRectMake(postTextLabel.frame.origin.x,
postThumbView.frame.origin.y + postThumbView.frame.size.height,
postTextLabel.frame.size.width,
postTextLabel.frame.size.height);
[postTextLabel resizeToFit];
postAuthorNameLabel.text = postAuthorName;
postTimestampLabel.text = postTimestamp;
NSLog(#"%f", postTimestampLabel.frame.origin.y);

Why size of frame is empty in navigationBar?

I try to get frame from navigationBar and get zero width and height of size. Code:
CGRect f = self.navigationController.navigationBar.frame;
In debug mode I get zero from f.height.
What is wrong?
use this
NSLog(#"frame:%#",NSStringFromCGRect(f));
This will show frame.
Most probably you are logging int as float or float as int. If you do
int ih = f.size.height;
or
float fh = f.size.height;
you will not see any warning as float will be converted to float, but trying to log
NSLog("%d", fh);
or
NSLog("%f", ih);
should give you a warning, just read it.
in your code : f.height should be f.size.height
By doing so : this code
CGRect f = self.navigationController.navigationBar.frame;
NSLog(#"f.size = (%.2f, %.2f)", f.size.width, f.size.height);
is giving me this output :
2012-01-14 15:54:32.909 naveCon[4071:207] f.size = (320.00, 44.00)

how to determine the transparent color index of ICO image with PIL?

Specifically, this is from an .ico file, so there is no "transparent" "info" attribute like you would get in a gif. The below example illustrates converting Yahoo!'s favicon to a png using the correct transparency index of "0", which I guessed. how to detect that the ico is in fact transparent and that the transparency index is 0 ?
import urllib2
import Image
import StringIO
resp = urllib2.urlopen("http://www.yahoo.com/favicon.ico")
image = Image.open(StringIO.StringIO(resp.read()))
f = file("test.png", "w")
# I guessed that the transparent index is 0. how to
# determine it correctly ?
image.save(f, "PNG", quality=95, transparency=0)
looks like someone recognized that PIL doesn't really read ICO correctly (I can see the same thing after reconciling its source code with some research on the ICO format - there is an AND bitmap which determines transparency)
and came up with this extension:
http://www.djangosnippets.org/snippets/1287/
since this is useful for non-django applications, I've reposted here with a few tweaks to its exception throws:
import operator
import struct
from PIL import BmpImagePlugin, PngImagePlugin, Image
def load_icon(file, index=None):
'''
Load Windows ICO image.
See http://en.wikipedia.org/w/index.php?oldid=264332061 for file format
description.
'''
if isinstance(file, basestring):
file = open(file, 'rb')
try:
header = struct.unpack('<3H', file.read(6))
except:
raise IOError('Not an ICO file')
# Check magic
if header[:2] != (0, 1):
raise IOError('Not an ICO file')
# Collect icon directories
directories = []
for i in xrange(header[2]):
directory = list(struct.unpack('<4B2H2I', file.read(16)))
for j in xrange(3):
if not directory[j]:
directory[j] = 256
directories.append(directory)
if index is None:
# Select best icon
directory = max(directories, key=operator.itemgetter(slice(0, 3)))
else:
directory = directories[index]
# Seek to the bitmap data
file.seek(directory[7])
prefix = file.read(16)
file.seek(-16, 1)
if PngImagePlugin._accept(prefix):
# Windows Vista icon with PNG inside
image = PngImagePlugin.PngImageFile(file)
else:
# Load XOR bitmap
image = BmpImagePlugin.DibImageFile(file)
if image.mode == 'RGBA':
# Windows XP 32-bit color depth icon without AND bitmap
pass
else:
# Patch up the bitmap height
image.size = image.size[0], image.size[1] >> 1
d, e, o, a = image.tile[0]
image.tile[0] = d, (0, 0) + image.size, o, a
# Calculate AND bitmap dimensions. See
# http://en.wikipedia.org/w/index.php?oldid=264236948#Pixel_storage
# for description
offset = o + a[1] * image.size[1]
stride = ((image.size[0] + 31) >> 5) << 2
size = stride * image.size[1]
# Load AND bitmap
file.seek(offset)
string = file.read(size)
mask = Image.fromstring('1', image.size, string, 'raw',
('1;I', stride, -1))
image = image.convert('RGBA')
image.putalpha(mask)
return image